@@ -1362,13 +1362,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13621362 let type_start = own_start - has_self as u32 + params. len ( ) as u32 ;
13631363 let mut i = 0 ;
13641364
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, .. } => {
13721368 if !allow_defaults && default. is_some ( ) {
13731369 if !tcx. features ( ) . default_type_parameter_fallback {
13741370 tcx. struct_span_lint_hir (
@@ -1378,7 +1374,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13781374 |lint| {
13791375 lint. build (
13801376 "defaults for type parameters are only allowed in \
1381- `struct`, `enum`, `type`, or `trait` definitions.",
1377+ `struct`, `enum`, `type`, or `trait` definitions.",
13821378 )
13831379 . emit ( ) ;
13841380 } ,
@@ -1403,13 +1399,8 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
14031399 } ;
14041400 i += 1 ;
14051401 Some ( param_def)
1406- } else {
1407- None
14081402 }
1409- } ) ) ;
1410-
1411- params. extend ( ast_generics. params . iter ( ) . filter_map ( |param| {
1412- if let GenericParamKind :: Const { .. } = param. kind {
1403+ GenericParamKind :: Const { .. } => {
14131404 let param_def = ty:: GenericParamDef {
14141405 index : type_start + i as u32 ,
14151406 name : param. name . ident ( ) . name ,
@@ -1419,8 +1410,6 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
14191410 } ;
14201411 i += 1 ;
14211412 Some ( param_def)
1422- } else {
1423- None
14241413 }
14251414 } ) ) ;
14261415
@@ -1899,14 +1888,24 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
18991888 // Collect the predicates that were written inline by the user on each
19001889 // type parameter (e.g., `<T: Foo>`).
19011890 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+ }
19101909 }
19111910 }
19121911
0 commit comments