Skip to content

Commit e69dd7a

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 c5d167a commit e69dd7a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustc_middle/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<'tcx> Instance<'tcx> {
375375
debug!(" => associated item with unsizeable self: Self");
376376
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
377377
} else {
378-
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
378+
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
379379
}
380380
}
381381

Lines changed: 23 additions & 0 deletions
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)