Skip to content

Commit f721fb5

Browse files
committed
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.
2 parents fa36f96 + 4c710e7 commit f721fb5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustc_middle/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'tcx> Instance<'tcx> {
389389
debug!(" => associated item with unsizeable self: Self");
390390
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
391391
} else {
392-
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
392+
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
393393
}
394394
}
395395

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
trait Tracked {
4+
#[track_caller]
5+
fn handle(&self) {
6+
let location = std::panic::Location::caller();
7+
assert_eq!(location.file(), file!());
8+
// we only call this via trait object, so the def site should *always* be returned
9+
assert_eq!(location.line(), line!() - 4);
10+
assert_eq!(location.column(), 5);
11+
}
12+
}
13+
14+
impl Tracked for () {}
15+
impl Tracked for u8 {}
16+
17+
fn main() {
18+
let tracked: &dyn Tracked = &5u8;
19+
tracked.handle();
20+
21+
const TRACKED: &dyn Tracked = &();
22+
TRACKED.handle();
23+
}

0 commit comments

Comments
 (0)