Skip to content

Commit bf39d86

Browse files
Erase late-bound regions before computing vtable debuginfo name.
1 parent cd8b56f commit bf39d86

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,11 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
480480
}
481481

482482
if let Some(trait_ref) = trait_ref {
483-
push_item_name(tcx, trait_ref.skip_binder().def_id, true, &mut vtable_name);
483+
let trait_ref =
484+
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
485+
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
484486
visited.clear();
485-
push_generic_params_internal(
486-
tcx,
487-
trait_ref.skip_binder().substs,
488-
&mut vtable_name,
489-
&mut visited,
490-
);
487+
push_generic_params_internal(tcx, trait_ref.substs, &mut vtable_name, &mut visited);
491488
} else {
492489
vtable_name.push_str("_");
493490
}

src/test/codegen/debug-vtable.rs

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, _>::vtable$"
1919
// CHECK: !DISubrange(count: 3
2020

21+
// NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::bar::{closure#0} as core::ops::function::FnOnce<(core::option::Option<&dyn core::ops::function::Fn<(), Output=()>>)>>::{vtable}"
22+
// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::bar::closure$0, core::ops::function::FnOnce<tuple$<enum$<core::option::Option<ref$<dyn$<core::ops::function::Fn<tuple$<>,assoc$<Output,tuple$<> > > > > >, {{.*}}, {{.*}}, Some> > > >::vtable$"
23+
2124
#![crate_type = "lib"]
2225

2326
pub struct Foo;
@@ -45,3 +48,10 @@ pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) {
4548
let z: &dyn SomeTraitWithGenerics<u64, i8> = x;
4649
(y.method1(), z.method1(), x as &dyn Send)
4750
}
51+
52+
// Constructing the debuginfo name for the FnOnce vtable below initially caused an ICE on MSVC
53+
// because the trait type contains a late bound region that needed to be erased before the type
54+
// layout for the niche enum `Option<&dyn Fn()>` could can be computed.
55+
pub fn bar() -> Box<dyn FnOnce(Option<&dyn Fn()>)> {
56+
Box::new(|_x: Option<&dyn Fn()>| {})
57+
}

0 commit comments

Comments
 (0)