Skip to content

Commit f17f97d

Browse files
authored
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
2 parents 1028978 + f0eec88 commit f17f97d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Ensure that a `#[track_caller]` function, returning `caller_location()`,
2+
// which coerced (to a function pointer) and called, inside a `const fn`,
3+
// in turn called, results in the same output irrespective of whether
4+
// we're in a const or runtime context.
5+
6+
// run-pass
7+
// compile-flags: -Z unleash-the-miri-inside-of-you
8+
9+
#![feature(core_intrinsics, const_caller_location, track_caller, const_fn)]
10+
11+
type L = &'static std::panic::Location<'static>;
12+
13+
#[track_caller]
14+
const fn attributed() -> L {
15+
std::intrinsics::caller_location()
16+
}
17+
18+
const fn calling_attributed() -> L {
19+
// We need `-Z unleash-the-miri-inside-of-you` for this as we don't have `const fn` pointers.
20+
let ptr: fn() -> L = attributed;
21+
ptr() //~ WARN skipping const checks
22+
}
23+
24+
fn main() {
25+
const CONSTANT: L = calling_attributed();
26+
let runtime = calling_attributed();
27+
28+
assert_eq!(
29+
(runtime.file(), runtime.line(), runtime.column()),
30+
(CONSTANT.file(), CONSTANT.line(), CONSTANT.column()),
31+
);
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: skipping const checks
2+
--> $DIR/caller-location-fnptr-rt-ctfe-equiv.rs:21:5
3+
|
4+
LL | ptr()
5+
| ^^^^^
6+

0 commit comments

Comments
 (0)