@@ -1164,13 +1164,33 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
11641164 let parent_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
11651165 Some ( tcx. hir ( ) . local_def_id ( parent_id) . to_def_id ( ) )
11661166 }
1167-
1167+ // FIXME(#43408) always enable this once we use `lazy_normalization` is
1168+ // stable enough and does not need a feature gate anymore.
11681169 Node :: AnonConst ( _) => {
1169- if tcx. features ( ) . lazy_normalization_consts {
1170- let parent_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
1171- Some ( tcx. hir ( ) . local_def_id ( parent_id) . to_def_id ( ) )
1170+ let parent_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
1171+ let parent_def_id = tcx. hir ( ) . local_def_id ( parent_id) ;
1172+
1173+ // HACK(eddyb) this provides the correct generics when
1174+ // `feature(const_generics)` is enabled, so that const expressions
1175+ // used with const generics, e.g. `Foo<{N+1}>`, can work at all.
1176+ if tcx. features ( ) . const_generics || tcx. features ( ) . lazy_normalization_consts {
1177+ Some ( parent_def_id. to_def_id ( ) )
11721178 } else {
1173- None
1179+ let parent_node = tcx. hir ( ) . get ( tcx. hir ( ) . get_parent_node ( hir_id) ) ;
1180+ match parent_node {
1181+ // HACK(eddyb) this provides the correct generics for repeat
1182+ // expressions' count (i.e. `N` in `[x; N]`), and explicit
1183+ // `enum` discriminants (i.e. `D` in `enum Foo { Bar = D }`),
1184+ // as they shouldn't be able to cause query cycle errors.
1185+ Node :: Expr ( & Expr { kind : ExprKind :: Repeat ( _, ref constant) , .. } )
1186+ | Node :: Variant ( Variant { disr_expr : Some ( ref constant) , .. } )
1187+ if constant. hir_id == hir_id =>
1188+ {
1189+ Some ( parent_def_id. to_def_id ( ) )
1190+ }
1191+
1192+ _ => None ,
1193+ }
11741194 }
11751195 }
11761196
0 commit comments