Skip to content

Commit

Permalink
track_caller: support on FFI imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Apr 9, 2020
1 parent f6c729d commit 45589b5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ E0734: include_str!("./error_codes/E0734.md"),
E0735: include_str!("./error_codes/E0735.md"),
E0736: include_str!("./error_codes/E0736.md"),
E0737: include_str!("./error_codes/E0737.md"),
E0738: include_str!("./error_codes/E0738.md"),
E0739: include_str!("./error_codes/E0739.md"),
E0740: include_str!("./error_codes/E0740.md"),
E0741: include_str!("./error_codes/E0741.md"),
Expand Down Expand Up @@ -614,4 +613,5 @@ E0751: include_str!("./error_codes/E0751.md"),
E0722, // Malformed `#[optimize]` attribute
E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
}
11 changes: 0 additions & 11 deletions src/librustc_error_codes/error_codes/E0738.md

This file was deleted.

12 changes: 1 addition & 11 deletions src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,7 @@ impl CheckAttrVisitor<'tcx> {
.emit();
false
}
Target::ForeignFn => {
struct_span_err!(
self.tcx.sess,
*attr_span,
E0738,
"`#[track_caller]` is not supported on foreign functions",
)
.emit();
false
}
Target::Fn | Target::Method(..) => true,
Target::Fn | Target::Method(..) | Target::ForeignFn => true,
_ => {
struct_span_err!(
self.tcx.sess,
Expand Down
9 changes: 0 additions & 9 deletions src/test/ui/rfc-2091-track-caller/error-extern-fn.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/rfc-2091-track-caller/error-extern-fn.stderr

This file was deleted.

50 changes: 50 additions & 0 deletions src/test/ui/rfc-2091-track-caller/track-caller-ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// run-pass

#![feature(track_caller)]

use std::panic::Location;

extern "Rust" {
#[track_caller]
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static>;
}

fn rust_track_caller_ffi_test_nested_tracked() -> &'static Location<'static> {
unsafe { rust_track_caller_ffi_test_tracked() }
}

mod provides {
use std::panic::Location;
#[track_caller] // UB if we did not have this!
#[no_mangle]
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static> {
Location::caller()
}
#[no_mangle]
fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static> {
Location::caller()
}
}

fn main() {
let location = Location::caller();
assert_eq!(location.file(), file!());
assert_eq!(location.line(), 31);
assert_eq!(location.column(), 20);

let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
assert_eq!(tracked.file(), file!());
assert_eq!(tracked.line(), 36);
assert_eq!(tracked.column(), 28);

let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
assert_eq!(untracked.file(), file!());
assert_eq!(untracked.line(), 26);
assert_eq!(untracked.column(), 9);

let contained = rust_track_caller_ffi_test_nested_tracked();
assert_eq!(contained.file(), file!());
assert_eq!(contained.line(), 14);
assert_eq!(contained.column(), 14);
}

0 comments on commit 45589b5

Please sign in to comment.