Skip to content

Commit eb679c9

Browse files
committed
Add test for Location::caller in a macro.
1 parent bc6e66e commit eb679c9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
#![feature(track_caller)]
4+
5+
macro_rules! caller_location_from_macro {
6+
() => (core::panic::Location::caller());
7+
}
8+
9+
fn main() {
10+
let loc = core::panic::Location::caller();
11+
assert_eq!(loc.file(), file!());
12+
assert_eq!(loc.line(), 10);
13+
assert_eq!(loc.column(), 15);
14+
15+
// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
16+
// i.e. point to where the macro was invoked, instead of the macro itself.
17+
let loc2 = caller_location_from_macro!();
18+
assert_eq!(loc2.file(), file!());
19+
assert_eq!(loc2.line(), 17);
20+
assert_eq!(loc2.column(), 16);
21+
}

0 commit comments

Comments
 (0)