2019-10-27 18:27:32 -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-27 18:27:32 -05:00
|
|
|
|
2019-11-10 15:11:25 -06:00
|
|
|
use std::panic::Location;
|
2019-10-27 18:27:32 -05:00
|
|
|
|
|
|
|
#[track_caller]
|
2019-11-10 15:11:25 -06:00
|
|
|
fn tracked() -> &'static Location<'static> {
|
|
|
|
Location::caller()
|
2019-10-27 18:27:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn nested_intrinsic() -> &'static Location<'static> {
|
2019-11-10 15:11:25 -06:00
|
|
|
Location::caller()
|
2019-10-27 18:27:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn nested_tracked() -> &'static Location<'static> {
|
|
|
|
tracked()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-11-10 15:11:25 -06:00
|
|
|
let location = Location::caller();
|
2019-10-27 18:27:32 -05:00
|
|
|
assert_eq!(location.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(location.line(), 21);
|
2019-10-27 18:27:32 -05:00
|
|
|
assert_eq!(location.column(), 20);
|
|
|
|
|
|
|
|
let tracked = tracked();
|
|
|
|
assert_eq!(tracked.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(tracked.line(), 26);
|
2019-10-27 18:27:32 -05:00
|
|
|
assert_eq!(tracked.column(), 19);
|
|
|
|
|
|
|
|
let nested = nested_intrinsic();
|
|
|
|
assert_eq!(nested.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(nested.line(), 13);
|
2019-10-27 18:27:32 -05:00
|
|
|
assert_eq!(nested.column(), 5);
|
|
|
|
|
|
|
|
let contained = nested_tracked();
|
|
|
|
assert_eq!(contained.file(), file!());
|
2020-02-08 15:46:57 -06:00
|
|
|
assert_eq!(contained.line(), 17);
|
2019-10-27 18:27:32 -05:00
|
|
|
assert_eq!(contained.column(), 5);
|
|
|
|
}
|