about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-03 18:58:36 +0100
committerGitHub <noreply@github.com>2020-02-03 18:58:36 +0100
commitf17f97d36a41a1ca4c9f9bc3ecec9b30b5555583 (patch)
tree1626ccfc1d8ca79211fc90321edee1d0d5e8c18d /src
parent1028978e8f8c51aeab76667ba7f5a5e46524c1ba (diff)
parentf0eec8858173868d2d266c5d7fe4ef83a2d9412c (diff)
Rollup merge of #68798 - Centril:caller-loc-ctfe-rt-equiv, r=RalfJung
Test that `#[track_caller]` as `fn()` respects RT / CTFE equivalence

r? @RalfJung cc @anp @eddyb
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs32
-rw-r--r--src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr6
2 files changed, 38 insertions, 0 deletions
diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs
new file mode 100644
index 00000000000..fe2b92eafdb
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs
@@ -0,0 +1,32 @@
+// Ensure that a `#[track_caller]` function, returning `caller_location()`,
+// which coerced (to a function pointer) and called, inside a `const fn`,
+// in turn called, results in the same output irrespective of whether
+// we're in a const or runtime context.
+
+// run-pass
+// compile-flags: -Z unleash-the-miri-inside-of-you
+
+#![feature(core_intrinsics, const_caller_location, track_caller, const_fn)]
+
+type L = &'static std::panic::Location<'static>;
+
+#[track_caller]
+const fn attributed() -> L {
+    std::intrinsics::caller_location()
+}
+
+const fn calling_attributed() -> L {
+    // We need `-Z unleash-the-miri-inside-of-you` for this as we don't have `const fn` pointers.
+    let ptr: fn() -> L = attributed;
+    ptr() //~ WARN skipping const checks
+}
+
+fn main() {
+    const CONSTANT: L = calling_attributed();
+    let runtime = calling_attributed();
+
+    assert_eq!(
+        (runtime.file(), runtime.line(), runtime.column()),
+        (CONSTANT.file(), CONSTANT.line(), CONSTANT.column()),
+    );
+}
diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr
new file mode 100644
index 00000000000..fcf0945ed4c
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr
@@ -0,0 +1,6 @@
+warning: skipping const checks
+  --> $DIR/caller-location-fnptr-rt-ctfe-equiv.rs:21:5
+   |
+LL |     ptr()
+   |     ^^^^^
+