Skip to content

Commit fcd1712

Browse files
anpMark-Simulacrum
authored andcommitted
Fix #[track_caller] shims for trait objects.
We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable. Closes #74764.
1 parent c774981 commit fcd1712

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: src/librustc_middle/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'tcx> Instance<'tcx> {
345345
debug!(" => associated item with unsizeable self: Self");
346346
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
347347
} else {
348-
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
348+
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
349349
}
350350
}
351351

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

0 commit comments

Comments
 (0)