2020-04-07 21:35:51 -05:00
|
|
|
// run-pass
|
|
|
|
|
|
|
|
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!());
|
2020-05-21 18:43:39 -05:00
|
|
|
assert_eq!(location.line(), 29);
|
2020-04-07 21:35:51 -05:00
|
|
|
assert_eq!(location.column(), 20);
|
|
|
|
|
|
|
|
let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
|
|
|
|
assert_eq!(tracked.file(), file!());
|
2020-05-21 18:43:39 -05:00
|
|
|
assert_eq!(tracked.line(), 34);
|
2020-04-07 21:35:51 -05:00
|
|
|
assert_eq!(tracked.column(), 28);
|
|
|
|
|
|
|
|
let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
|
|
|
|
assert_eq!(untracked.file(), file!());
|
2020-05-21 18:43:39 -05:00
|
|
|
assert_eq!(untracked.line(), 24);
|
2020-04-07 21:35:51 -05:00
|
|
|
assert_eq!(untracked.column(), 9);
|
|
|
|
|
|
|
|
let contained = rust_track_caller_ffi_test_nested_tracked();
|
|
|
|
assert_eq!(contained.file(), file!());
|
2020-05-21 18:43:39 -05:00
|
|
|
assert_eq!(contained.line(), 12);
|
2020-04-07 21:35:51 -05:00
|
|
|
assert_eq!(contained.column(), 14);
|
|
|
|
}
|