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