Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #[track_caller] shims for trait objects. #74784

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<'tcx> Instance<'tcx> {
debug!(" => associated item with unsizeable self: Self");
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
} else {
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// run-pass

trait Tracked {
#[track_caller]
fn handle(&self) {
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(), 5);
}
}

impl Tracked for () {}
impl Tracked for u8 {}

fn main() {
let tracked: &dyn Tracked = &5u8;
tracked.handle();

const TRACKED: &dyn Tracked = &();
TRACKED.handle();
}