]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #1162 - RalfJung:track-fn-ptr, r=RalfJung
authorbors <bors@rust-lang.org>
Tue, 28 Jan 2020 21:57:00 +0000 (21:57 +0000)
committerbors <bors@rust-lang.org>
Tue, 28 Jan 2020 21:57:00 +0000 (21:57 +0000)
test track_caller with fn ptrs

Looks like we already use `ReifyShim` the right way, let's just make sure we test that!

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

index 68a0c95b44dbad9b8c0c41fb7d020f9aa6d5d923..f6797c24ebecf327ee3458b6cbfa7d2308d6aad3 100644 (file)
@@ -19,15 +19,33 @@ macro_rules! caller_location_from_macro {
     () => (core::panic::Location::caller());
 }
 
+fn test_fn_ptr() {
+    fn pass_to_ptr_call<T>(f: fn(T), x: T) {
+        f(x);
+    }
+
+    #[track_caller]
+    fn tracked_unit(_: ()) {
+        let expected_line = line!() - 1;
+        let location = std::panic::Location::caller();
+        assert_eq!(location.file(), file!());
+        assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
+    }
+
+    pass_to_ptr_call(tracked_unit, ());
+}
+
 fn main() {
     let location = Location::caller();
+    let expected_line = line!() - 1;
     assert_eq!(location.file(), file!());
-    assert_eq!(location.line(), 23);
+    assert_eq!(location.line(), expected_line);
     assert_eq!(location.column(), 20);
 
     let tracked = tracked();
+    let expected_line = line!() - 1;
     assert_eq!(tracked.file(), file!());
-    assert_eq!(tracked.line(), 28);
+    assert_eq!(tracked.line(), expected_line);
     assert_eq!(tracked.column(), 19);
 
     let nested = nested_intrinsic();
@@ -43,12 +61,16 @@ fn main() {
     // `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
     // i.e. point to where the macro was invoked, instead of the macro itself.
     let inmacro = caller_location_from_macro!();
+    let expected_line = line!() - 1;
     assert_eq!(inmacro.file(), file!());
-    assert_eq!(inmacro.line(), 45);
+    assert_eq!(inmacro.line(), expected_line);
     assert_eq!(inmacro.column(), 19);
 
     let intrinsic = core::intrinsics::caller_location();
+    let expected_line = line!() - 1;
     assert_eq!(intrinsic.file(), file!());
-    assert_eq!(intrinsic.line(), 50);
+    assert_eq!(intrinsic.line(), expected_line);
     assert_eq!(intrinsic.column(), 21);
+
+    test_fn_ptr();
 }