Skip to content

Commit

Permalink
Auto merge of #1849 - Aaron1011:rustup-track-caller, r=RalfJung
Browse files Browse the repository at this point in the history
Rustup for `#[track_caller]` trait object changes

Change test to assert that we get the correct location
even through a trait object call.
  • Loading branch information
bors committed Jul 10, 2021
2 parents 3cf6550 + 811423e commit b061307
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c5e344f7747dbd7e7d4b209e3c480deb5979a56f
3982eb35cabe3a99194d768d34a92347967c3fa2
24 changes: 16 additions & 8 deletions tests/run-pass/track-caller-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,31 @@ fn test_fn_ptr() {
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() {
Expand Down

0 comments on commit b061307

Please sign in to comment.