Auto merge of #1849 - Aaron1011:rustup-track-caller, r=RalfJung

Rustup for `#[track_caller]` trait object changes

Change test to assert that we get the correct location
even through a trait object call.
This commit is contained in:
bors 2021-07-10 17:15:31 +00:00
commit b06130762e
2 changed files with 17 additions and 9 deletions

View File

@ -1 +1 @@
c5e344f7747dbd7e7d4b209e3c480deb5979a56f
3982eb35cabe3a99194d768d34a92347967c3fa2

View File

@ -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() {