Skip to content

Commit 5cd8a2a

Browse files
debuginfo: Fix bug in type name generation for dyn types with associated types but no other generic arguments.
1 parent 282778a commit 5cd8a2a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,18 @@ fn push_debuginfo_type_name<'tcx>(
212212
if projection_bounds.len() != 0 {
213213
if principal_has_generic_params {
214214
// push_generic_params_internal() above added a `>` but we actually
215-
// want to add more items to that list, so remove that again.
215+
// want to add more items to that list, so remove that again...
216216
pop_close_angle_bracket(output);
217+
// .. and add a comma to separate the regular generic args from the
218+
// associated types.
219+
push_arg_separator(cpp_like_debuginfo, output);
220+
} else {
221+
// push_generic_params_internal() did not add `<...>`, so we open
222+
// angle brackets here.
223+
output.push('<');
217224
}
218225

219226
for (item_def_id, ty) in projection_bounds {
220-
push_arg_separator(cpp_like_debuginfo, output);
221-
222227
if cpp_like_debuginfo {
223228
output.push_str("assoc$<");
224229
push_item_name(tcx, item_def_id, false, output);
@@ -230,8 +235,10 @@ fn push_debuginfo_type_name<'tcx>(
230235
output.push('=');
231236
push_debuginfo_type_name(tcx, ty, true, output, visited);
232237
}
238+
push_arg_separator(cpp_like_debuginfo, output);
233239
}
234240

241+
pop_arg_separator(output);
235242
push_close_angle_bracket(cpp_like_debuginfo, output);
236243
}
237244

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*
@@ -318,12 +322,22 @@ trait Trait3<T> {
318322
panic!()
319323
}
320324
}
325+
trait TraitNoGenericsButWithAssocType {
326+
type Output;
327+
fn foo(&self) -> Self::Output;
328+
}
321329

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

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

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

0 commit comments

Comments
 (0)