@@ -2281,8 +2281,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22812281 assert_eq ! ( opt_self_ty, None ) ;
22822282 self . prohibit_generics ( path. segments ) ;
22832283 // Try to evaluate any array length constants.
2284- let normalized_ty = self . normalize_ty ( span, tcx. at ( span) . type_of ( def_id) ) ;
2285- if forbid_generic && normalized_ty. needs_subst ( ) {
2284+ let ty = tcx. at ( span) . type_of ( def_id) ;
2285+ // HACK(min_const_generics): Forbid generic `Self` types
2286+ // here as we can't easily do that during nameres.
2287+ //
2288+ // We do this before normalization as we otherwise allow
2289+ // ```rust
2290+ // trait AlwaysApplicable { type Assoc; }
2291+ // impl<T: ?Sized> AlwaysApplicable for T { type Assoc = usize; }
2292+ //
2293+ // trait BindsParam<T> {
2294+ // type ArrayTy;
2295+ // }
2296+ // impl<T> BindsParam<T> for <T as AlwaysApplicable>::Assoc {
2297+ // type ArrayTy = [u8; Self::MAX];
2298+ // }
2299+ // ```
2300+ // Note that the normalization happens in the param env of
2301+ // the anon const, which is empty. This is why the
2302+ // `AlwaysApplicable` impl needs a `T: ?Sized` bound for
2303+ // this to compile if we were to normalize here.
2304+ if forbid_generic && ty. needs_subst ( ) {
22862305 let mut err = tcx. sess . struct_span_err (
22872306 path. span ,
22882307 "generic `Self` types are currently not permitted in anonymous constants" ,
@@ -2297,7 +2316,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22972316 err. emit ( ) ;
22982317 tcx. ty_error ( )
22992318 } else {
2300- normalized_ty
2319+ self . normalize_ty ( span , ty )
23012320 }
23022321 }
23032322 Res :: Def ( DefKind :: AssocTy , def_id) => {
0 commit comments