2019-10-09 10:25:41 -05:00
|
|
|
// run-pass
|
2020-02-08 15:46:57 -06:00
|
|
|
// revisions: default mir-opt
|
2021-03-04 07:21:13 -06:00
|
|
|
//[mir-opt] compile-flags: -Zmir-opt-level=4
|
2019-10-09 10:25:41 -05:00
|
|
|
|
2019-12-06 19:10:47 -06:00
|
|
|
#[inline(never)]
|
|
|
|
#[track_caller]
|
2019-12-08 06:51:55 -06:00
|
|
|
fn codegen_caller_loc() -> &'static core::panic::Location<'static> {
|
2019-12-06 19:10:47 -06:00
|
|
|
core::panic::Location::caller()
|
|
|
|
}
|
|
|
|
|
2019-10-30 11:54:40 -05:00
|
|
|
macro_rules! caller_location_from_macro {
|
2019-12-08 06:51:55 -06:00
|
|
|
() => (codegen_caller_loc());
|
2019-10-30 11:54:40 -05:00
|
|
|
}
|
|
|
|
|
2019-10-09 10:25:41 -05:00
|
|
|
fn main() {
|
2019-12-08 06:51:55 -06:00
|
|
|
let loc = codegen_caller_loc();
|
2019-10-09 10:25:41 -05:00
|
|
|
assert_eq!(loc.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(loc.line(), 16);
|
2019-10-09 10:25:41 -05:00
|
|
|
assert_eq!(loc.column(), 15);
|
2019-10-30 11:54:40 -05:00
|
|
|
|
2019-11-10 15:11:25 -06:00
|
|
|
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
|
2019-10-30 11:54:40 -05:00
|
|
|
// i.e. point to where the macro was invoked, instead of the macro itself.
|
|
|
|
let loc2 = caller_location_from_macro!();
|
|
|
|
assert_eq!(loc2.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(loc2.line(), 23);
|
2019-10-30 11:54:40 -05:00
|
|
|
assert_eq!(loc2.column(), 16);
|
2019-10-09 10:25:41 -05:00
|
|
|
}
|