]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | // run-pass |
2 | ||
3 | use std::panic::Location; | |
4 | ||
5 | struct Foo; | |
6 | ||
7 | impl Foo { | |
8 | #[track_caller] | |
9 | fn check_loc(&self, line: u32, col: u32) -> &Self { | |
10 | let loc = Location::caller(); | |
11 | assert_eq!(loc.file(), file!(), "file mismatch"); | |
12 | assert_eq!(loc.line(), line, "line mismatch"); | |
13 | assert_eq!(loc.column(), col, "column mismatch"); | |
14 | self | |
15 | } | |
16 | } | |
17 | ||
18 | fn main() { | |
19 | // Tests that when `Location::caller` is used in a method chain, | |
20 | // it points to the start of the correct call (the first character after the dot) | |
21 | // instead of to the very first expression in the chain | |
22 | let foo = Foo; | |
23 | foo. | |
24 | check_loc(line!(), 9).check_loc(line!(), 31) | |
25 | .check_loc(line!(), 10); | |
26 | } |