@@ -1316,29 +1316,31 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
13161316 }
13171317}
13181318
1319- struct AnonConstInParamListDetector {
1320- in_param_list : bool ,
1321- found_anon_const_in_list : bool ,
1319+ struct AnonConstInParamTyDetector {
1320+ in_param_ty : bool ,
1321+ found_anon_const_in_param_ty : bool ,
13221322 ct : HirId ,
13231323}
13241324
1325- impl < ' v > Visitor < ' v > for AnonConstInParamListDetector {
1325+ impl < ' v > Visitor < ' v > for AnonConstInParamTyDetector {
13261326 type Map = intravisit:: ErasedMap < ' v > ;
13271327
13281328 fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
13291329 NestedVisitorMap :: None
13301330 }
13311331
13321332 fn visit_generic_param ( & mut self , p : & ' v hir:: GenericParam < ' v > ) {
1333- let prev = self . in_param_list ;
1334- self . in_param_list = true ;
1335- intravisit:: walk_generic_param ( self , p) ;
1336- self . in_param_list = prev;
1333+ if let GenericParamKind :: Const { ref ty, default : _ } = p. kind {
1334+ let prev = self . in_param_ty ;
1335+ self . in_param_ty = true ;
1336+ self . visit_ty ( ty) ;
1337+ self . in_param_ty = prev;
1338+ }
13371339 }
13381340
13391341 fn visit_anon_const ( & mut self , c : & ' v hir:: AnonConst ) {
1340- if self . in_param_list && self . ct == c. hir_id {
1341- self . found_anon_const_in_list = true ;
1342+ if self . in_param_ty && self . ct == c. hir_id {
1343+ self . found_anon_const_in_param_ty = true ;
13421344 } else {
13431345 intravisit:: walk_anon_const ( self , c)
13441346 }
@@ -1366,27 +1368,24 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13661368 let parent_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
13671369 let parent_def_id = tcx. hir ( ) . local_def_id ( parent_id) ;
13681370
1369- let mut in_param_list = false ;
1371+ let mut in_param_ty = false ;
13701372 for ( _parent, node) in tcx. hir ( ) . parent_iter ( hir_id) {
13711373 if let Some ( generics) = node. generics ( ) {
1372- let mut visitor = AnonConstInParamListDetector {
1373- in_param_list : false ,
1374- found_anon_const_in_list : false ,
1374+ let mut visitor = AnonConstInParamTyDetector {
1375+ in_param_ty : false ,
1376+ found_anon_const_in_param_ty : false ,
13751377 ct : hir_id,
13761378 } ;
13771379
13781380 visitor. visit_generics ( generics) ;
1379- in_param_list = visitor. found_anon_const_in_list ;
1381+ in_param_ty = visitor. found_anon_const_in_param_ty ;
13801382 break ;
13811383 }
13821384 }
13831385
1384- if in_param_list {
1386+ if in_param_ty {
13851387 // We do not allow generic parameters in anon consts if we are inside
1386- // of a param list.
1387- //
1388- // This affects both default type bindings, e.g. `struct<T, U = [u8; std::mem::size_of::<T>()]>(T, U)`,
1389- // and the types of const parameters, e.g. `struct V<const N: usize, const M: [u8; N]>();`.
1388+ // of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
13901389 None
13911390 } else if tcx. lazy_normalization ( ) {
13921391 // HACK(eddyb) this provides the correct generics when
0 commit comments