@@ -1316,29 +1316,31 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
1316
1316
}
1317
1317
}
1318
1318
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 ,
1322
1322
ct : HirId ,
1323
1323
}
1324
1324
1325
- impl < ' v > Visitor < ' v > for AnonConstInParamListDetector {
1325
+ impl < ' v > Visitor < ' v > for AnonConstInParamTyDetector {
1326
1326
type Map = intravisit:: ErasedMap < ' v > ;
1327
1327
1328
1328
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
1329
1329
NestedVisitorMap :: None
1330
1330
}
1331
1331
1332
1332
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
+ }
1337
1339
}
1338
1340
1339
1341
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 ;
1342
1344
} else {
1343
1345
intravisit:: walk_anon_const ( self , c)
1344
1346
}
@@ -1366,27 +1368,24 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1366
1368
let parent_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
1367
1369
let parent_def_id = tcx. hir ( ) . local_def_id ( parent_id) ;
1368
1370
1369
- let mut in_param_list = false ;
1371
+ let mut in_param_ty = false ;
1370
1372
for ( _parent, node) in tcx. hir ( ) . parent_iter ( hir_id) {
1371
1373
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 ,
1375
1377
ct : hir_id,
1376
1378
} ;
1377
1379
1378
1380
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 ;
1380
1382
break ;
1381
1383
}
1382
1384
}
1383
1385
1384
- if in_param_list {
1386
+ if in_param_ty {
1385
1387
// 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.
1390
1389
None
1391
1390
} else if tcx. lazy_normalization ( ) {
1392
1391
// HACK(eddyb) this provides the correct generics when
0 commit comments