]> git.proxmox.com Git - rustc.git/blame - src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / src / test / ui / rfc-2091-track-caller / caller-location-fnptr-rt-ctfe-equiv.rs
CommitLineData
74b04a01
XL
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
17df50a5 9#![feature(core_intrinsics, const_caller_location)]
74b04a01
XL
10
11type L = &'static std::panic::Location<'static>;
12
13#[track_caller]
14const fn attributed() -> L {
15 std::intrinsics::caller_location()
16}
17
18const 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;
f9f354fc 21 ptr()
74b04a01
XL
22}
23
24fn 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}