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