From 811423e76126c7c60651ced211241dd2cc796a05 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 10 Jul 2021 11:51:00 -0500 Subject: [PATCH] Rustup for `#[track_caller]` trait object changes Change test to assert that we get the correct location even through a trait object call. --- rust-version | 2 +- tests/run-pass/track-caller-attribute.rs | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/rust-version b/rust-version index 8856f7d0852..aee5d6ee3ba 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -c5e344f7747dbd7e7d4b209e3c480deb5979a56f +3982eb35cabe3a99194d768d34a92347967c3fa2 diff --git a/tests/run-pass/track-caller-attribute.rs b/tests/run-pass/track-caller-attribute.rs index a9cfd2e0ebd..d1115faa8f7 100644 --- a/tests/run-pass/track-caller-attribute.rs +++ b/tests/run-pass/track-caller-attribute.rs @@ -38,23 +38,31 @@ fn tracked_unit(_: ()) { fn test_trait_obj() { trait Tracked { #[track_caller] - fn handle(&self) { // `fn` here is what the `location` should point at. - let location = std::panic::Location::caller(); - assert_eq!(location.file(), file!()); - // we only call this via trait object, so the def site should *always* be returned - assert_eq!(location.line(), line!() - 4); - assert_eq!(location.column(), 9); + fn handle(&self) -> &'static Location<'static> { + std::panic::Location::caller() } } impl Tracked for () {} impl Tracked for u8 {} + // Test that we get the correct location + // even with a call through a trait object + let tracked: &dyn Tracked = &5u8; - tracked.handle(); + let location = tracked.handle(); + let expected_line = line!() - 1; + assert_eq!(location.file(), file!()); + assert_eq!(location.line(), expected_line); + assert_eq!(location.column(), 28); const TRACKED: &dyn Tracked = &(); - TRACKED.handle(); + let location = TRACKED.handle(); + let expected_line = line!() - 1; + assert_eq!(location.file(), file!()); + assert_eq!(location.line(), expected_line); + assert_eq!(location.column(), 28); + } fn main() {