Skip to content

Commit 45589b5

Browse files
committed
track_caller: support on FFI imports
1 parent f6c729d commit 45589b5

File tree

6 files changed

+52
-41
lines changed

6 files changed

+52
-41
lines changed

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ E0734: include_str!("./error_codes/E0734.md"),
416416
E0735: include_str!("./error_codes/E0735.md"),
417417
E0736: include_str!("./error_codes/E0736.md"),
418418
E0737: include_str!("./error_codes/E0737.md"),
419-
E0738: include_str!("./error_codes/E0738.md"),
420419
E0739: include_str!("./error_codes/E0739.md"),
421420
E0740: include_str!("./error_codes/E0740.md"),
422421
E0741: include_str!("./error_codes/E0741.md"),
@@ -614,4 +613,5 @@ E0751: include_str!("./error_codes/E0751.md"),
614613
E0722, // Malformed `#[optimize]` attribute
615614
E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
616615
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
616+
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
617617
}

src/librustc_error_codes/error_codes/E0738.md

-11
This file was deleted.

src/librustc_passes/check_attr.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,7 @@ impl CheckAttrVisitor<'tcx> {
151151
.emit();
152152
false
153153
}
154-
Target::ForeignFn => {
155-
struct_span_err!(
156-
self.tcx.sess,
157-
*attr_span,
158-
E0738,
159-
"`#[track_caller]` is not supported on foreign functions",
160-
)
161-
.emit();
162-
false
163-
}
164-
Target::Fn | Target::Method(..) => true,
154+
Target::Fn | Target::Method(..) | Target::ForeignFn => true,
165155
_ => {
166156
struct_span_err!(
167157
self.tcx.sess,

src/test/ui/rfc-2091-track-caller/error-extern-fn.rs

-9
This file was deleted.

src/test/ui/rfc-2091-track-caller/error-extern-fn.stderr

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// run-pass
2+
3+
#![feature(track_caller)]
4+
5+
use std::panic::Location;
6+
7+
extern "Rust" {
8+
#[track_caller]
9+
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
10+
fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static>;
11+
}
12+
13+
fn rust_track_caller_ffi_test_nested_tracked() -> &'static Location<'static> {
14+
unsafe { rust_track_caller_ffi_test_tracked() }
15+
}
16+
17+
mod provides {
18+
use std::panic::Location;
19+
#[track_caller] // UB if we did not have this!
20+
#[no_mangle]
21+
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static> {
22+
Location::caller()
23+
}
24+
#[no_mangle]
25+
fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static> {
26+
Location::caller()
27+
}
28+
}
29+
30+
fn main() {
31+
let location = Location::caller();
32+
assert_eq!(location.file(), file!());
33+
assert_eq!(location.line(), 31);
34+
assert_eq!(location.column(), 20);
35+
36+
let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
37+
assert_eq!(tracked.file(), file!());
38+
assert_eq!(tracked.line(), 36);
39+
assert_eq!(tracked.column(), 28);
40+
41+
let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
42+
assert_eq!(untracked.file(), file!());
43+
assert_eq!(untracked.line(), 26);
44+
assert_eq!(untracked.column(), 9);
45+
46+
let contained = rust_track_caller_ffi_test_nested_tracked();
47+
assert_eq!(contained.file(), file!());
48+
assert_eq!(contained.line(), 14);
49+
assert_eq!(contained.column(), 14);
50+
}

0 commit comments

Comments
 (0)