]> git.proxmox.com Git - rustc.git/blame - src/test/ui/rfc-2091-track-caller/call-chain.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / rfc-2091-track-caller / call-chain.rs
CommitLineData
f035d41b
XL
1// run-pass
2
3use std::panic::Location;
4
5struct Foo;
6
7impl 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
18fn 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}