Skip to content

Commit e755f2c

Browse files
authored
Rollup merge of #94810 - michaelwoerister:fix-trait-pointer-debuginfo-names, r=wesleywiser
debuginfo: Fix bug in type name generation for dyn types with associated types but no other generic arguments. For types like `&dyn Future<Output=bool>` the compiler currently emits invalid types names in debuginfo. This PR fixes this. Before: ```txt // DWARF &dyn core::future::future::Future, Output=bool> // CodeView ref$<dyn$<core::future::future::Future,assoc$<Output,bool> > > > ``` After: ```txt // DWARF &dyn core::future::future::Future<Output=bool> // CodeView ref$<dyn$<core::future::future::Future<assoc$<Output,bool> > > > ``` These syntactically incorrect type names can cause downstream tools (e.g. debugger extensions) crash when trying to parse them. r? `@wesleywiser`
2 parents be52b4a + 5cd8a2a commit e755f2c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,18 @@ fn push_debuginfo_type_name<'tcx>(
226226
if projection_bounds.len() != 0 {
227227
if principal_has_generic_params {
228228
// push_generic_params_internal() above added a `>` but we actually
229-
// want to add more items to that list, so remove that again.
229+
// want to add more items to that list, so remove that again...
230230
pop_close_angle_bracket(output);
231+
// .. and add a comma to separate the regular generic args from the
232+
// associated types.
233+
push_arg_separator(cpp_like_debuginfo, output);
234+
} else {
235+
// push_generic_params_internal() did not add `<...>`, so we open
236+
// angle brackets here.
237+
output.push('<');
231238
}
232239

233240
for (item_def_id, ty) in projection_bounds {
234-
push_arg_separator(cpp_like_debuginfo, output);
235-
236241
if cpp_like_debuginfo {
237242
output.push_str("assoc$<");
238243
push_item_name(tcx, item_def_id, false, output);
@@ -244,8 +249,10 @@ fn push_debuginfo_type_name<'tcx>(
244249
output.push('=');
245250
push_debuginfo_type_name(tcx, ty, true, output, visited);
246251
}
252+
push_arg_separator(cpp_like_debuginfo, output);
247253
}
248254

255+
pop_arg_separator(output);
249256
push_close_angle_bracket(cpp_like_debuginfo, output);
250257
}
251258

Diff for: src/test/debuginfo/type-names.rs

+16
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
// gdb-command:whatis has_associated_type_trait
123123
// gdb-check:type = &(dyn type_names::Trait3<u32, AssocType=isize> + core::marker::Send)
124124

125+
// gdb-command:whatis has_associated_type_but_no_generics_trait
126+
// gdb-check:type = &dyn type_names::TraitNoGenericsButWithAssocType<Output=isize>
127+
125128
// BARE FUNCTIONS
126129
// gdb-command:whatis rust_fn
127130
// gdb-check:type = (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
@@ -228,6 +231,7 @@
228231
// cdb-check:struct ref_mut$<dyn$<type_names::Trait1> > mut_ref_trait = [...]
229232
// cdb-check:struct alloc::boxed::Box<dyn$<core::marker::Send,core::marker::Sync>,alloc::alloc::Global> no_principal_trait = [...]
230233
// cdb-check:struct ref$<dyn$<type_names::Trait3<u32,assoc$<AssocType,isize> >,core::marker::Send> > has_associated_type_trait = struct ref$<dyn$<type_names::Trait3<u32,assoc$<AssocType,isize> >,core::marker::Send> >
234+
// cdb-check:struct ref$<dyn$<type_names::TraitNoGenericsButWithAssocType<assoc$<Output,isize> > > > has_associated_type_but_no_generics_trait = struct ref$<dyn$<type_names::TraitNoGenericsButWithAssocType<assoc$<Output,isize> > > >
231235

232236
// BARE FUNCTIONS
233237
// cdb-command:dv /t *_fn*
@@ -317,12 +321,22 @@ trait Trait3<T> {
317321
panic!()
318322
}
319323
}
324+
trait TraitNoGenericsButWithAssocType {
325+
type Output;
326+
fn foo(&self) -> Self::Output;
327+
}
320328

321329
impl Trait1 for isize {}
322330
impl<T1, T2> Trait2<T1, T2> for isize {}
323331
impl<T> Trait3<T> for isize {
324332
type AssocType = isize;
325333
}
334+
impl TraitNoGenericsButWithAssocType for isize {
335+
type Output = isize;
336+
fn foo(&self) -> Self::Output {
337+
*self
338+
}
339+
}
326340

327341
fn rust_fn(_: Option<isize>, _: Option<&mod1::Struct2>) {}
328342
extern "C" fn extern_c_fn(_: isize) {}
@@ -413,6 +427,8 @@ fn main() {
413427
let mut_ref_trait = (&mut mut_int1) as &mut dyn Trait1;
414428
let no_principal_trait = Box::new(0_isize) as Box<(dyn Send + Sync)>;
415429
let has_associated_type_trait = &0_isize as &(dyn Trait3<u32, AssocType = isize> + Send);
430+
let has_associated_type_but_no_generics_trait =
431+
&0_isize as &dyn TraitNoGenericsButWithAssocType<Output = isize>;
416432

417433
let generic_box_trait = Box::new(0_isize) as Box<dyn Trait2<i32, mod1::Struct2>>;
418434
let generic_ref_trait = (&0_isize) as &dyn Trait2<Struct1, Struct1>;

0 commit comments

Comments
 (0)