about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-28 04:53:06 +0100
committerGitHub <noreply@github.com>2019-10-28 04:53:06 +0100
commit4728d66206c82c98aa4e1fad751e8aae7489c242 (patch)
treea95e0d577f867d3fba9346478e13bcac3dc793a8 /src/test
parentc8eefdffe9480bbd84554eab3343f71f04af8f9a (diff)
parent86e55b1882ac492d6234e5c5f97c7f151a11f5d2 (diff)
downloadrust-4728d66206c82c98aa4e1fad751e8aae7489c242.tar.gz
rust-4728d66206c82c98aa4e1fad751e8aae7489c242.zip
Rollup merge of #65664 - anp:panic-location, r=eddyb
`std::panic::Location` is a lang_item, add `core::intrinsics::caller_location` (RFC 2091 3/N)

[Tracking issue](https://github.com/rust-lang/rust/issues/47809)
[RFC text](https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md)

@eddyb suggested doing this intrinsic implementation ahead of actually implementing the `#[track_caller]` attribute so that there's an easily tested intermediate step between adding the shim and wiring up the attribute.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const-eval/const_caller_location.rs23
-rw-r--r--src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs5
-rw-r--r--src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs9
3 files changed, 35 insertions, 2 deletions
diff --git a/src/test/ui/consts/const-eval/const_caller_location.rs b/src/test/ui/consts/const-eval/const_caller_location.rs
new file mode 100644
index 00000000000..c63822f052b
--- /dev/null
+++ b/src/test/ui/consts/const-eval/const_caller_location.rs
@@ -0,0 +1,23 @@
+// run-pass
+
+#![feature(const_fn, core_intrinsics)]
+
+use std::{intrinsics::caller_location, panic::Location};
+
+const LOCATION: &Location = caller_location();
+const NESTED: &Location = {
+    const fn nested_location() -> &'static Location<'static> {
+        caller_location()
+    };
+    nested_location()
+};
+
+fn main() {
+    assert_eq!(LOCATION.file(), file!());
+    assert_eq!(LOCATION.line(), 7);
+    assert_eq!(LOCATION.column(), 29);
+
+    assert_eq!(NESTED.file(), file!());
+    assert_eq!(NESTED.line(), 10);
+    assert_eq!(NESTED.column(), 9);
+}
diff --git a/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs b/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
index ff10d412a11..8727c9d1ca6 100644
--- a/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
+++ b/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
@@ -22,7 +22,7 @@
 //[thin]compile-flags: -C lto=thin
 //[fat]compile-flags: -C lto=fat
 
-#![feature(core_panic)]
+#![feature(core_panic, panic_internals)]
 
 // (For some reason, reproducing the LTO issue requires pulling in std
 // explicitly this way.)
@@ -51,7 +51,8 @@ fn main() {
 
         let _guard = Droppable;
         let s = "issue-64655-allow-unwind-when-calling-panic-directly.rs";
-        core::panicking::panic(&("???", s, 17, 4));
+        let location = core::panic::Location::internal_constructor(s, 17, 4);
+        core::panicking::panic("???", &location);
     });
 
     let wait = handle.join();
diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs b/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs
new file mode 100644
index 00000000000..ab6c59384c4
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+#![feature(core_intrinsics)]
+fn main() {
+    let loc = core::intrinsics::caller_location();
+    assert_eq!(loc.file(), file!());
+    assert_eq!(loc.line(), 5);
+    assert_eq!(loc.column(), 15);
+}