Skip to content

Commit 4c710e7

Browse files
committedJul 26, 2020
Fix #[track_caller] shims for trait objects.
We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable. Closes #74764.
1 parent d7f9451 commit 4c710e7

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
@@ -411,7 +411,7 @@ impl<'tcx> Instance<'tcx> {
411411
debug!(" => associated item with unsizeable self: Self");
412412
Some(Instance { def: InstanceDef::VtableShim(def_id), substs })
413413
} else {
414-
Instance::resolve(tcx, param_env, def_id, substs).ok().flatten()
414+
Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs)
415415
}
416416
}
417417

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)