]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #1493 - RalfJung:track-test, r=RalfJung
authorbors <bors@rust-lang.org>
Fri, 31 Jul 2020 17:25:34 +0000 (17:25 +0000)
committerbors <bors@rust-lang.org>
Fri, 31 Jul 2020 17:25:34 +0000 (17:25 +0000)
test track_caller on trait objects

Adds a Miri-side test for https://github.com/rust-lang/rust/issues/74764.

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

index be655703daa061834603cabbcf099117183e3978..a9cfd2e0ebdedac99e1da29e1013c2f9eace0af7 100644 (file)
@@ -35,6 +35,28 @@ fn tracked_unit(_: ()) {
     pass_to_ptr_call(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);
+        }
+    }
+
+    impl Tracked for () {}
+    impl Tracked for u8 {}
+
+    let tracked: &dyn Tracked = &5u8;
+    tracked.handle();
+
+    const TRACKED: &dyn Tracked = &();
+    TRACKED.handle();
+}
+
 fn main() {
     let location = Location::caller();
     let expected_line = line!() - 1;
@@ -73,4 +95,5 @@ fn main() {
     assert_eq!(intrinsic.column(), 21);
 
     test_fn_ptr();
+    test_trait_obj();
 }