rust/tests/ui/rfcs/rfc-2091-track-caller/const-caller-location.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.0 KiB
Rust
Raw Normal View History

// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=4
2021-05-07 11:56:16 -05:00
#![feature(const_caller_location)]
use std::panic::Location;
const LOCATION: &Location = Location::caller();
2019-11-11 10:45:52 -06:00
const TRACKED: &Location = tracked();
#[track_caller]
const fn tracked() -> &'static Location <'static> {
Location::caller()
2019-11-11 10:45:52 -06:00
}
const NESTED: &Location = nested_location();
const fn nested_location() -> &'static Location<'static> {
Location::caller()
2019-11-11 10:45:52 -06:00
}
const CONTAINED: &Location = contained();
const fn contained() -> &'static Location<'static> {
tracked()
}
fn main() {
assert_eq!(LOCATION.file(), file!());
assert_eq!(LOCATION.line(), 9);
assert_eq!(LOCATION.column(), 29);
2019-11-11 10:45:52 -06:00
assert_eq!(TRACKED.file(), file!());
assert_eq!(TRACKED.line(), 11);
2019-11-11 10:45:52 -06:00
assert_eq!(TRACKED.column(), 28);
assert_eq!(NESTED.file(), file!());
assert_eq!(NESTED.line(), 19);
2019-11-11 10:45:52 -06:00
assert_eq!(NESTED.column(), 5);
assert_eq!(CONTAINED.file(), file!());
assert_eq!(CONTAINED.line(), 24);
2019-11-11 10:45:52 -06:00
assert_eq!(CONTAINED.column(), 5);
}