Skip to content

Commit b765963

Browse files
committed
Auto merge of #150843 - fmease:dyn-ace, r=BoxyUwU
mGCA: Make trait object types with type-level associated consts dyn compatible Under feature `min_generic_const_args` (mGCA) (#132980), render traits with non-parametrized type-level associated constants (i.e., `#[type_const]` ones) dyn compatible but force the user to specify all type-level associated consts in the trait object type via bindings (either directly, via supertrait bounds and/or behind trait aliases) just like associated types, their sibling. Fixes #130300 (feature request). Fixes #136063 (bug). Fixes #137260 (bug). Fixes #137514 (bug). While I'm accounting for most illegal `Self` references via const projections & params, I'm intentionally ignoring RUST-123140 (and duplicates) in this PR which is to be tackled some other time. Additional context: Crate `rustc-demangle` had to be updated to fix v0 demangling. I've patched it in PR rust-lang/rustc-demangle#87 which was was released in version 0.1.27 via PR rust-lang/rustc-demangle#88.
2 parents 004d710 + 558a592 commit b765963

File tree

108 files changed

+1437
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1437
-697
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,9 +3356,9 @@ dependencies = [
33563356

33573357
[[package]]
33583358
name = "rustc-demangle"
3359-
version = "0.1.26"
3359+
version = "0.1.27"
33603360
source = "registry+https://github.com/rust-lang/crates.io-index"
3361-
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
3361+
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
33623362

33633363
[[package]]
33643364
name = "rustc-hash"

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl DebugContext {
242242
let generics = tcx.generics_of(enclosing_fn_def_id);
243243
let args = instance.args.truncate_to(tcx, generics);
244244

245-
type_names::push_generic_params(
245+
type_names::push_generic_args(
246246
tcx,
247247
tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), args),
248248
&mut name,

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
456456
let generics = tcx.generics_of(enclosing_fn_def_id);
457457
let args = instance.args.truncate_to(tcx, generics);
458458

459-
type_names::push_generic_params(
459+
type_names::push_generic_args(
460460
tcx,
461461
tcx.normalize_erasing_regions(self.typing_env(), args),
462462
&mut name,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ fn push_debuginfo_type_name<'tcx>(
109109
ty_and_layout,
110110
&|output, visited| {
111111
push_item_name(tcx, def.did(), true, output);
112-
push_generic_params_internal(tcx, args, output, visited);
112+
push_generic_args_internal(tcx, args, output, visited);
113113
},
114114
output,
115115
visited,
116116
);
117117
} else {
118118
push_item_name(tcx, def.did(), qualified, output);
119-
push_generic_params_internal(tcx, args, output, visited);
119+
push_generic_args_internal(tcx, args, output, visited);
120120
}
121121
}
122122
ty::Tuple(component_types) => {
@@ -253,19 +253,18 @@ fn push_debuginfo_type_name<'tcx>(
253253
);
254254
push_item_name(tcx, principal.def_id, qualified, output);
255255
let principal_has_generic_params =
256-
push_generic_params_internal(tcx, principal.args, output, visited);
256+
push_generic_args_internal(tcx, principal.args, output, visited);
257257

258258
let projection_bounds: SmallVec<[_; 4]> = trait_data
259259
.projection_bounds()
260260
.map(|bound| {
261261
let ExistentialProjection { def_id: item_def_id, term, .. } =
262262
tcx.instantiate_bound_regions_with_erased(bound);
263-
// FIXME(mgca): allow for consts here
264-
(item_def_id, term.expect_type())
263+
(item_def_id, term)
265264
})
266265
.collect();
267266

268-
if projection_bounds.len() != 0 {
267+
if !projection_bounds.is_empty() {
269268
if principal_has_generic_params {
270269
// push_generic_params_internal() above added a `>` but we actually
271270
// want to add more items to that list, so remove that again...
@@ -279,17 +278,17 @@ fn push_debuginfo_type_name<'tcx>(
279278
output.push('<');
280279
}
281280

282-
for (item_def_id, ty) in projection_bounds {
281+
for (item_def_id, term) in projection_bounds {
283282
if cpp_like_debuginfo {
284283
output.push_str("assoc$<");
285284
push_item_name(tcx, item_def_id, false, output);
286285
push_arg_separator(cpp_like_debuginfo, output);
287-
push_debuginfo_type_name(tcx, ty, true, output, visited);
286+
push_debuginfo_term_name(tcx, term, true, output, visited);
288287
push_close_angle_bracket(cpp_like_debuginfo, output);
289288
} else {
290289
push_item_name(tcx, item_def_id, false, output);
291290
output.push('=');
292-
push_debuginfo_type_name(tcx, ty, true, output, visited);
291+
push_debuginfo_term_name(tcx, term, true, output, visited);
293292
}
294293
push_arg_separator(cpp_like_debuginfo, output);
295294
}
@@ -533,7 +532,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
533532
tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), trait_ref);
534533
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
535534
visited.clear();
536-
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
535+
push_generic_args_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
537536
} else {
538537
vtable_name.push('_');
539538
}
@@ -631,7 +630,13 @@ fn push_unqualified_item_name(
631630
};
632631
}
633632

634-
fn push_generic_params_internal<'tcx>(
633+
pub fn push_generic_args<'tcx>(tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>, output: &mut String) {
634+
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
635+
let mut visited = FxHashSet::default();
636+
push_generic_args_internal(tcx, args, output, &mut visited);
637+
}
638+
639+
fn push_generic_args_internal<'tcx>(
635640
tcx: TyCtxt<'tcx>,
636641
args: GenericArgsRef<'tcx>,
637642
output: &mut String,
@@ -646,14 +651,10 @@ fn push_generic_params_internal<'tcx>(
646651

647652
output.push('<');
648653

649-
for type_parameter in args {
650-
match type_parameter {
651-
GenericArgKind::Type(type_parameter) => {
652-
push_debuginfo_type_name(tcx, type_parameter, true, output, visited);
653-
}
654-
GenericArgKind::Const(ct) => {
655-
push_const_param(tcx, ct, output);
656-
}
654+
for arg in args {
655+
match arg {
656+
GenericArgKind::Type(ty) => push_debuginfo_type_name(tcx, ty, true, output, visited),
657+
GenericArgKind::Const(ct) => push_debuginfo_const_name(tcx, ct, output),
657658
other => bug!("Unexpected non-erasable generic: {:?}", other),
658659
}
659660

@@ -665,7 +666,20 @@ fn push_generic_params_internal<'tcx>(
665666
true
666667
}
667668

668-
fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
669+
fn push_debuginfo_term_name<'tcx>(
670+
tcx: TyCtxt<'tcx>,
671+
term: ty::Term<'tcx>,
672+
qualified: bool,
673+
output: &mut String,
674+
visited: &mut FxHashSet<Ty<'tcx>>,
675+
) {
676+
match term.kind() {
677+
ty::TermKind::Ty(ty) => push_debuginfo_type_name(tcx, ty, qualified, output, visited),
678+
ty::TermKind::Const(ct) => push_debuginfo_const_name(tcx, ct, output),
679+
}
680+
}
681+
682+
fn push_debuginfo_const_name<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
669683
match ct.kind() {
670684
ty::ConstKind::Param(param) => {
671685
write!(output, "{}", param.name)
@@ -715,16 +729,6 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
715729
.unwrap();
716730
}
717731

718-
pub fn push_generic_params<'tcx>(
719-
tcx: TyCtxt<'tcx>,
720-
args: GenericArgsRef<'tcx>,
721-
output: &mut String,
722-
) {
723-
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
724-
let mut visited = FxHashSet::default();
725-
push_generic_params_internal(tcx, args, output, &mut visited);
726-
}
727-
728732
fn push_closure_or_coroutine_name<'tcx>(
729733
tcx: TyCtxt<'tcx>,
730734
def_id: DefId,
@@ -767,7 +771,7 @@ fn push_closure_or_coroutine_name<'tcx>(
767771
// FIXME(async_closures): This is probably not going to be correct w.r.t.
768772
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
769773
let args = args.truncate_to(tcx, generics);
770-
push_generic_params_internal(tcx, args, output, visited);
774+
push_generic_args_internal(tcx, args, output, visited);
771775
}
772776

773777
fn push_close_angle_bracket(cpp_like_debuginfo: bool, output: &mut String) {

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported
165165
hir_analysis_duplicate_precise_capture = cannot capture parameter `{$name}` twice
166166
.label = parameter captured again here
167167
168+
hir_analysis_dyn_trait_assoc_item_binding_mentions_self =
169+
{$kind} binding in trait object type mentions `Self`
170+
.label = contains a mention of `Self`
171+
.binding_label = this binding mentions `Self`
172+
168173
hir_analysis_eii_with_generics =
169174
`{$impl_name}` cannot have generic parameters other than lifetimes
170175
.label = required by this attribute
@@ -330,37 +335,18 @@ hir_analysis_manual_implementation =
330335
hir_analysis_method_should_return_future = method should be `async` or return a future, but it is synchronous
331336
.note = this method is `async` so it expects a future to be returned
332337
333-
hir_analysis_missing_one_of_trait_item = not all trait items implemented, missing one of: `{$missing_items_msg}`
334-
.label = missing one of `{$missing_items_msg}` in implementation
335-
.note = required because of this annotation
336-
337-
hir_analysis_missing_trait_item = not all trait items implemented, missing: `{$missing_items_msg}`
338-
.label = missing `{$missing_items_msg}` in implementation
339-
340-
hir_analysis_missing_trait_item_label = `{$item}` from trait
341-
342-
hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snippet}`
343-
344-
hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
345-
.note = default implementation of `{$missing_item_name}` is unstable
346-
.some_note = use of unstable library feature `{$feature}`: {$reason}
347-
.none_note = use of unstable library feature `{$feature}`
348-
349-
hir_analysis_missing_type_params =
350-
the type {$parameterCount ->
338+
hir_analysis_missing_generic_params =
339+
the {$descr} {$parameterCount ->
351340
[one] parameter
352341
*[other] parameters
353342
} {$parameters} must be explicitly specified
354-
.label = type {$parameterCount ->
343+
.label = {$descr} {$parameterCount ->
355344
[one] parameter
356345
*[other] parameters
357346
} {$parameters} must be specified for this
358-
.suggestion = set the type {$parameterCount ->
347+
.suggestion = explicitly specify the {$descr} {$parameterCount ->
359348
[one] parameter
360349
*[other] parameters
361-
} to the desired {$parameterCount ->
362-
[one] type
363-
*[other] types
364350
}
365351
.no_suggestion_label = missing {$parameterCount ->
366352
[one] reference
@@ -372,7 +358,23 @@ hir_analysis_missing_type_params =
372358
} `Self`, the {$parameterCount ->
373359
[one] parameter
374360
*[other] parameters
375-
} must be specified on the object type
361+
} must be specified on the trait object type
362+
363+
hir_analysis_missing_one_of_trait_item = not all trait items implemented, missing one of: `{$missing_items_msg}`
364+
.label = missing one of `{$missing_items_msg}` in implementation
365+
.note = required because of this annotation
366+
367+
hir_analysis_missing_trait_item = not all trait items implemented, missing: `{$missing_items_msg}`
368+
.label = missing `{$missing_items_msg}` in implementation
369+
370+
hir_analysis_missing_trait_item_label = `{$item}` from trait
371+
372+
hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snippet}`
373+
374+
hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
375+
.note = default implementation of `{$missing_item_name}` is unstable
376+
.some_note = use of unstable library feature `{$feature}`: {$reason}
377+
.none_note = use of unstable library feature `{$feature}`
376378
377379
hir_analysis_no_variant_named = no variant named `{$ident}` found for enum `{$ty}`
378380
@@ -481,9 +483,6 @@ hir_analysis_self_in_impl_self =
481483
`Self` is not valid in the self type of an impl block
482484
.note = replace `Self` with a different type
483485
484-
hir_analysis_self_in_type_alias = `Self` is not allowed in type aliases
485-
.label = `Self` is only available in impls, traits, and concrete type definitions
486-
487486
hir_analysis_self_ty_not_captured = `impl Trait` must mention the `Self` type of the trait in `use<...>`
488487
.label = `Self` type parameter is implicitly captured by this `impl Trait`
489488
.note = currently, all type parameters are required to be mentioned in the precise captures list

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ fn compare_generic_param_kinds<'tcx>(
19601960
trait_item: ty::AssocItem,
19611961
delay: bool,
19621962
) -> Result<(), ErrorGuaranteed> {
1963-
assert_eq!(impl_item.as_tag(), trait_item.as_tag());
1963+
assert_eq!(impl_item.tag(), trait_item.tag());
19641964

19651965
let ty_const_params_of = |def_id| {
19661966
tcx.generics_of(def_id).own_params.iter().filter(|param| {

0 commit comments

Comments
 (0)