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