From fd90e56120c9fec88808f9464e27283b0c6954ad Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Thu, 16 Jan 2020 18:58:32 -0800 Subject: Add failing #[track_caller] test with fn pointers. --- .../ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs | 16 ++++++++++++++++ src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs (limited to 'src/test') diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs new file mode 100644 index 00000000000..210a4f22f09 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(track_caller)] + +fn pass_to_ptr_call(f: fn(T), x: T) { + f(x); +} + +#[track_caller] +fn tracked_unit(_: ()) { + assert_eq!(std::panic::Location::caller().file(), file!()); +} + +fn main() { + pass_to_ptr_call(tracked_unit, ()); +} diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs new file mode 100644 index 00000000000..1ce8f678b60 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(track_caller)] + +fn ptr_call(f: fn()) { + f(); +} + +#[track_caller] +fn tracked() { + assert_eq!(std::panic::Location::caller().file(), file!()); +} + +fn main() { + ptr_call(tracked); +} -- cgit 1.4.1-3-g733a5 From 72dffac6cf170c6c16c043299e35848014aae8d4 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Sun, 19 Jan 2020 14:25:43 -0800 Subject: Test that ReifyShim + caller_location return the def site. --- src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs | 5 ++++- src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs index 210a4f22f09..0407eafbfd4 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs @@ -8,7 +8,10 @@ fn pass_to_ptr_call(f: fn(T), x: T) { #[track_caller] fn tracked_unit(_: ()) { - assert_eq!(std::panic::Location::caller().file(), file!()); + 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"); } fn main() { diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs index 1ce8f678b60..a4baaa26ced 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs @@ -8,7 +8,10 @@ fn ptr_call(f: fn()) { #[track_caller] fn tracked() { - assert_eq!(std::panic::Location::caller().file(), file!()); + 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"); } fn main() { -- cgit 1.4.1-3-g733a5