2019-10-09 10:25:41 -05:00
|
|
|
// run-pass
|
|
|
|
|
2019-11-10 15:11:25 -06:00
|
|
|
#![feature(track_caller)]
|
2019-10-30 11:54:40 -05:00
|
|
|
|
2019-12-06 19:10:47 -06:00
|
|
|
#[inline(never)]
|
|
|
|
#[track_caller]
|
|
|
|
fn defeat_const_prop() -> &'static core::panic::Location<'static> {
|
|
|
|
core::panic::Location::caller()
|
|
|
|
}
|
|
|
|
|
2019-10-30 11:54:40 -05:00
|
|
|
macro_rules! caller_location_from_macro {
|
2019-12-06 19:10:47 -06:00
|
|
|
() => (defeat_const_prop());
|
2019-10-30 11:54:40 -05:00
|
|
|
}
|
|
|
|
|
2019-10-09 10:25:41 -05:00
|
|
|
fn main() {
|
2019-12-06 19:10:47 -06:00
|
|
|
let loc = defeat_const_prop();
|
2019-10-09 10:25:41 -05:00
|
|
|
assert_eq!(loc.file(), file!());
|
2019-12-06 19:10:47 -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!());
|
2019-12-06 19:10:47 -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
|
|
|
}
|