Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --(reduced) (original) This code is very similar to closed issue . The only difference is in line 17 which was in previous issue and now it's <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
label -needs-triage F-genericconstitems claim

Discussion:
if let Some(item) = tcx.opt_associated_item(def_id.into()) && let ty::AssocKind::Const = item.kind && let ty::ImplContainer = item.container <del> && let Some(trait_item) = item.trait_item_def_id </del> <ins> && let Some(trait_item_def_id) = item.trait_item_def_id </ins> { <del> let args = tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args; Some(tcx.type_of(trait_item).instantiate(tcx, args)) </del> <ins> let impl_def_id = item.container_id(tcx); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(); let args = ty::GenericArgs::identity_for_item(tcx, def_id).rebase_onto( tcx, impl_def_id, impl_trait_ref.args, ); tcx.check_args_compatible(trait_item_def_id, args) .then(|| tcx.type_of(trait_item_def_id).instantiate(tcx, args)) </ins> } else { Some(fcx.next_ty_var(span)) }

<del> //@ known-bug: rust-lang/rust#124833 #![feature(generic_const_items)] trait Trait { const C<'a>: &'a str; } impl Trait for () { const C<'a>:  = "C"; } </del>

<ins> // Ensure that we properly deal with missing/placeholder types inside GACs. // issue: rust-lang/rust#124833 #![feature(generic_const_items)] #![allow(incomplete_features)] trait Trait { const K<T>: T; const Q<'a>: &'a str; } impl Trait for () { const K<T> = (); //~^ ERROR missing type for `const` item //~| ERROR mismatched types //~| ERROR mismatched types const Q = ""; //~^ ERROR missing type for `const` item //~| ERROR lifetime parameters or bounds on const `Q` do not match the trait declaration } fn main() {} </ins>

<ins> error[E0308]: mismatched types --> $DIR/assoc-const-missing-type.rs:12:18 | LL |     const K<T> = (); |             -    ^^ expected type parameter `T`, found `()` |             | |             expected this type parameter | = note: expected type parameter `T` found unit type `()` error: missing type for `const` item --> $DIR/assoc-const-missing-type.rs:12:15 | LL |     const K<T> = (); |               ^ help: provide a type for the associated constant: `()` error[E0195]: lifetime parameters or bounds on const `Q` do not match the trait declaration --> $DIR/assoc-const-missing-type.rs:16:12 | LL |     const Q<'a>: &'a str; |            ---- lifetimes in impl do not match this const in trait ... LL |     const Q = ""; |            ^ lifetimes do not match const in trait error: missing type for `const` item --> $DIR/assoc-const-missing-type.rs:16:12 | LL |     const Q = ""; |            ^ help: provide a type for the associated constant: `: &str` error[E0308]: mismatched types --> $DIR/assoc-const-missing-type.rs:12:18 | LL |     const K<T> = (); |             -    ^^ expected type parameter `T`, found `()` |             | |             expected this type parameter | = note: expected type parameter `T` found unit type `()` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 5 previous errors Some errors have detailed explanations: E0195, E0308. For more information about an error, try `rustc --explain E0195`. </ins>