@@ -1362,13 +1362,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1362
1362
let type_start = own_start - has_self as u32 + params. len ( ) as u32 ;
1363
1363
let mut i = 0 ;
1364
1364
1365
- // FIXME(const_generics): a few places in the compiler expect generic params
1366
- // to be in the order lifetimes, then type params, then const params.
1367
- //
1368
- // To prevent internal errors in case const parameters are supplied before
1369
- // type parameters we first add all type params, then all const params.
1370
- params. extend ( ast_generics. params . iter ( ) . filter_map ( |param| {
1371
- if let GenericParamKind :: Type { ref default, synthetic, .. } = param. kind {
1365
+ params. extend ( ast_generics. params . iter ( ) . filter_map ( |param| match param. kind {
1366
+ GenericParamKind :: Lifetime { .. } => None ,
1367
+ GenericParamKind :: Type { ref default, synthetic, .. } => {
1372
1368
if !allow_defaults && default. is_some ( ) {
1373
1369
if !tcx. features ( ) . default_type_parameter_fallback {
1374
1370
tcx. struct_span_lint_hir (
@@ -1378,7 +1374,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1378
1374
|lint| {
1379
1375
lint. build (
1380
1376
"defaults for type parameters are only allowed in \
1381
- `struct`, `enum`, `type`, or `trait` definitions.",
1377
+ `struct`, `enum`, `type`, or `trait` definitions.",
1382
1378
)
1383
1379
. emit ( ) ;
1384
1380
} ,
@@ -1403,13 +1399,8 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1403
1399
} ;
1404
1400
i += 1 ;
1405
1401
Some ( param_def)
1406
- } else {
1407
- None
1408
1402
}
1409
- } ) ) ;
1410
-
1411
- params. extend ( ast_generics. params . iter ( ) . filter_map ( |param| {
1412
- if let GenericParamKind :: Const { .. } = param. kind {
1403
+ GenericParamKind :: Const { .. } => {
1413
1404
let param_def = ty:: GenericParamDef {
1414
1405
index : type_start + i as u32 ,
1415
1406
name : param. name . ident ( ) . name ,
@@ -1419,8 +1410,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1419
1410
} ;
1420
1411
i += 1 ;
1421
1412
Some ( param_def)
1422
- } else {
1423
- None
1424
1413
}
1425
1414
} ) ) ;
1426
1415
@@ -1899,14 +1888,24 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
1899
1888
// Collect the predicates that were written inline by the user on each
1900
1889
// type parameter (e.g., `<T: Foo>`).
1901
1890
for param in ast_generics. params {
1902
- if let GenericParamKind :: Type { .. } = param. kind {
1903
- let name = param. name . ident ( ) . name ;
1904
- let param_ty = ty:: ParamTy :: new ( index, name) . to_ty ( tcx) ;
1905
- index += 1 ;
1906
-
1907
- let sized = SizedByDefault :: Yes ;
1908
- let bounds = AstConv :: compute_bounds ( & icx, param_ty, & param. bounds , sized, param. span ) ;
1909
- predicates. extend ( bounds. predicates ( tcx, param_ty) ) ;
1891
+ match param. kind {
1892
+ // We already dealt with early bound lifetimes above.
1893
+ GenericParamKind :: Lifetime { .. } => ( ) ,
1894
+ GenericParamKind :: Type { .. } => {
1895
+ let name = param. name . ident ( ) . name ;
1896
+ let param_ty = ty:: ParamTy :: new ( index, name) . to_ty ( tcx) ;
1897
+ index += 1 ;
1898
+
1899
+ let sized = SizedByDefault :: Yes ;
1900
+ let bounds =
1901
+ AstConv :: compute_bounds ( & icx, param_ty, & param. bounds , sized, param. span ) ;
1902
+ predicates. extend ( bounds. predicates ( tcx, param_ty) ) ;
1903
+ }
1904
+ GenericParamKind :: Const { .. } => {
1905
+ // Bounds on const parameters are currently not possible.
1906
+ debug_assert ! ( param. bounds. is_empty( ) ) ;
1907
+ index += 1 ;
1908
+ }
1910
1909
}
1911
1910
}
1912
1911
0 commit comments