Skip to content

Commit 61dbfe0

Browse files
Rollup merge of #157967 - kevin-valerio:fix-track-caller-vtable-shim, r=folkertdev
Preserve track_caller for by-value dyn vtable shims Fixes #157964
2 parents abbab2d + b77dcf4 commit 61dbfe0

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ impl<'tcx> InstanceKind<'tcx> {
310310

311311
pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
312312
match *self {
313-
InstanceKind::Item(def_id) | InstanceKind::Virtual(def_id, _) => {
313+
InstanceKind::Item(def_id)
314+
| InstanceKind::Virtual(def_id, _)
315+
| InstanceKind::VTableShim(def_id) => {
314316
tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
315317
}
316318
InstanceKind::ClosureOnceShim { call_once: _, closure: _, track_caller } => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ run-pass
2+
3+
#![feature(unsized_fn_params)]
4+
#![allow(internal_features)]
5+
6+
trait TrackedByValue {
7+
#[track_caller]
8+
fn consume(self, expected_line: u32);
9+
}
10+
11+
impl TrackedByValue for u8 {
12+
fn consume(self, expected_line: u32) {
13+
assert_eq!(self, 7);
14+
assert_eq!(std::panic::Location::caller().line(), expected_line);
15+
}
16+
}
17+
18+
fn main() {
19+
let obj = Box::new(7_u8) as Box<dyn TrackedByValue>;
20+
obj.consume(line!());
21+
}

0 commit comments

Comments
 (0)