]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2091-track-caller/track-caller-ffi.rs
Rollup merge of #90498 - joshtriplett:target-tier-policy-draft-updates, r=Mark-Simulacrum
[rust.git] / src / test / ui / rfc-2091-track-caller / track-caller-ffi.rs
1 // run-pass
2
3 use std::panic::Location;
4
5 extern "Rust" {
6     #[track_caller]
7     fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
8     fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static>;
9 }
10
11 fn rust_track_caller_ffi_test_nested_tracked() -> &'static Location<'static> {
12     unsafe { rust_track_caller_ffi_test_tracked() }
13 }
14
15 mod provides {
16     use std::panic::Location;
17     #[track_caller] // UB if we did not have this!
18     #[no_mangle]
19     fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static> {
20         Location::caller()
21     }
22     #[no_mangle]
23     fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static> {
24         Location::caller()
25     }
26 }
27
28 fn main() {
29     let location = Location::caller();
30     assert_eq!(location.file(), file!());
31     assert_eq!(location.line(), 29);
32     assert_eq!(location.column(), 20);
33
34     let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
35     assert_eq!(tracked.file(), file!());
36     assert_eq!(tracked.line(), 34);
37     assert_eq!(tracked.column(), 28);
38
39     let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
40     assert_eq!(untracked.file(), file!());
41     assert_eq!(untracked.line(), 24);
42     assert_eq!(untracked.column(), 9);
43
44     let contained = rust_track_caller_ffi_test_nested_tracked();
45     assert_eq!(contained.file(), file!());
46     assert_eq!(contained.line(), 12);
47     assert_eq!(contained.column(), 14);
48 }