Skip to content

Commit 811423e

Browse files
committed
Rustup for #[track_caller] trait object changes
Change test to assert that we get the correct location even through a trait object call.
1 parent 3cf6550 commit 811423e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c5e344f7747dbd7e7d4b209e3c480deb5979a56f
1+
3982eb35cabe3a99194d768d34a92347967c3fa2

tests/run-pass/track-caller-attribute.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,31 @@ fn test_fn_ptr() {
3838
fn test_trait_obj() {
3939
trait Tracked {
4040
#[track_caller]
41-
fn handle(&self) { // `fn` here is what the `location` should point at.
42-
let location = std::panic::Location::caller();
43-
assert_eq!(location.file(), file!());
44-
// we only call this via trait object, so the def site should *always* be returned
45-
assert_eq!(location.line(), line!() - 4);
46-
assert_eq!(location.column(), 9);
41+
fn handle(&self) -> &'static Location<'static> {
42+
std::panic::Location::caller()
4743
}
4844
}
4945

5046
impl Tracked for () {}
5147
impl Tracked for u8 {}
5248

49+
// Test that we get the correct location
50+
// even with a call through a trait object
51+
5352
let tracked: &dyn Tracked = &5u8;
54-
tracked.handle();
53+
let location = tracked.handle();
54+
let expected_line = line!() - 1;
55+
assert_eq!(location.file(), file!());
56+
assert_eq!(location.line(), expected_line);
57+
assert_eq!(location.column(), 28);
5558

5659
const TRACKED: &dyn Tracked = &();
57-
TRACKED.handle();
60+
let location = TRACKED.handle();
61+
let expected_line = line!() - 1;
62+
assert_eq!(location.file(), file!());
63+
assert_eq!(location.line(), expected_line);
64+
assert_eq!(location.column(), 28);
65+
5866
}
5967

6068
fn main() {

0 commit comments

Comments
 (0)