@@ -2281,8 +2281,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2281
2281
assert_eq ! ( opt_self_ty, None ) ;
2282
2282
self . prohibit_generics ( path. segments ) ;
2283
2283
// 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 ( ) {
2286
2305
let mut err = tcx. sess . struct_span_err (
2287
2306
path. span ,
2288
2307
"generic `Self` types are currently not permitted in anonymous constants" ,
@@ -2297,7 +2316,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2297
2316
err. emit ( ) ;
2298
2317
tcx. ty_error ( )
2299
2318
} else {
2300
- normalized_ty
2319
+ self . normalize_ty ( span , ty )
2301
2320
}
2302
2321
}
2303
2322
Res :: Def ( DefKind :: AssocTy , def_id) => {
0 commit comments