]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs
Rollup merge of #99064 - lyming2007:issue-97687-fix, r=estebank
[rust.git] / src / test / ui / rfc-2091-track-caller / caller-location-fnptr-rt-ctfe-equiv.rs
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)]
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()
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 }