Skip to content

Commit 9db7781

Browse files
committed
add indirect call example to track-caller-ffi.rs
1 parent 7d99979 commit 9db7781

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/ui/rfcs/rfc-2091-track-caller/track-caller-ffi.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
use std::panic::Location;
44

5-
extern "Rust" {
5+
unsafe extern "Rust" {
66
#[track_caller]
7-
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
8-
fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static>;
7+
safe fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
8+
safe fn rust_track_caller_ffi_test_untracked() -> &'static Location<'static>;
99
}
1010

1111
fn rust_track_caller_ffi_test_nested_tracked() -> &'static Location<'static> {
12-
unsafe { rust_track_caller_ffi_test_tracked() }
12+
rust_track_caller_ffi_test_tracked()
1313
}
1414

1515
mod provides {
@@ -31,18 +31,23 @@ fn main() {
3131
assert_eq!(location.line(), 29);
3232
assert_eq!(location.column(), 20);
3333

34-
let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
34+
let tracked = rust_track_caller_ffi_test_tracked();
3535
assert_eq!(tracked.file(), file!());
3636
assert_eq!(tracked.line(), 34);
37-
assert_eq!(tracked.column(), 28);
37+
assert_eq!(tracked.column(), 19);
3838

39-
let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
39+
let untracked = rust_track_caller_ffi_test_untracked();
4040
assert_eq!(untracked.file(), file!());
4141
assert_eq!(untracked.line(), 24);
4242
assert_eq!(untracked.column(), 9);
4343

4444
let contained = rust_track_caller_ffi_test_nested_tracked();
4545
assert_eq!(contained.file(), file!());
4646
assert_eq!(contained.line(), 12);
47-
assert_eq!(contained.column(), 14);
47+
assert_eq!(contained.column(), 5);
48+
49+
let indirect = (rust_track_caller_ffi_test_tracked as fn() -> &'static Location<'static>)();
50+
assert_eq!(indirect.file(), file!());
51+
assert_eq!(indirect.line(), 7);
52+
assert_eq!(indirect.column(), 5);
4853
}

0 commit comments

Comments
 (0)