]> git.proxmox.com Git - rustc.git/blob - src/test/ui/rfc-2091-track-caller/track-caller-ffi.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / test / ui / rfc-2091-track-caller / track-caller-ffi.rs
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 }