Auto merge of #74784 - anp:track-vtables, r=eddyb
Fix #[track_caller] shims for trait objects. We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable. Closes #74764.
This commit is contained in:
commit
f721fb5933
|
@ -389,7 +389,7 @@ impl<'tcx> Instance<'tcx> {
|
||||||
debug!(" => associated item with unsizeable self: Self");
|
debug!(" => associated item with unsizeable self: Self");
|
||||||
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
|
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
|
||||||
} else {
|
} else {
|
||||||
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
|
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
Loading…
Reference in New Issue