summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfc-2091-track-caller/track-caller-ffi.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/rfc-2091-track-caller/track-caller-ffi.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/rfc-2091-track-caller/track-caller-ffi.rs')
-rw-r--r--tests/ui/rfc-2091-track-caller/track-caller-ffi.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/rfc-2091-track-caller/track-caller-ffi.rs b/tests/ui/rfc-2091-track-caller/track-caller-ffi.rs
new file mode 100644
index 000000000..5115f687c
--- /dev/null
+++ b/tests/ui/rfc-2091-track-caller/track-caller-ffi.rs
@@ -0,0 +1,48 @@
+// 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!());
+ assert_eq!(location.line(), 29);
+ assert_eq!(location.column(), 20);
+
+ let tracked = unsafe { rust_track_caller_ffi_test_tracked() };
+ assert_eq!(tracked.file(), file!());
+ assert_eq!(tracked.line(), 34);
+ assert_eq!(tracked.column(), 28);
+
+ let untracked = unsafe { rust_track_caller_ffi_test_untracked() };
+ assert_eq!(untracked.file(), file!());
+ assert_eq!(untracked.line(), 24);
+ assert_eq!(untracked.column(), 9);
+
+ let contained = rust_track_caller_ffi_test_nested_tracked();
+ assert_eq!(contained.file(), file!());
+ assert_eq!(contained.line(), 12);
+ assert_eq!(contained.column(), 14);
+}