]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs
test: ensure #[track_caller] tests also test MIR inlining.
[rust.git] / src / test / ui / rfc-2091-track-caller / caller-location-intrinsic.rs
1 // run-pass
2 // revisions: default mir-opt
3 //[mir-opt] compile-flags: -Zmir-opt-level=3
4
5 #[inline(never)]
6 #[track_caller]
7 fn codegen_caller_loc() -> &'static core::panic::Location<'static> {
8     core::panic::Location::caller()
9 }
10
11 macro_rules! caller_location_from_macro {
12     () => (codegen_caller_loc());
13 }
14
15 fn main() {
16     let loc = codegen_caller_loc();
17     assert_eq!(loc.file(), file!());
18     assert_eq!(loc.line(), 16);
19     assert_eq!(loc.column(), 15);
20
21     // `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
22     // i.e. point to where the macro was invoked, instead of the macro itself.
23     let loc2 = caller_location_from_macro!();
24     assert_eq!(loc2.file(), file!());
25     assert_eq!(loc2.line(), 23);
26     assert_eq!(loc2.column(), 16);
27 }