@@ -1148,21 +1148,18 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11481148 }
11491149}
11501150
1151- fn object_lifetime_default < ' tcx > (
1152- tcx : TyCtxt < ' tcx > ,
1153- param_def_id : DefId ,
1154- ) -> Option < ObjectLifetimeDefault > {
1151+ fn object_lifetime_default < ' tcx > ( tcx : TyCtxt < ' tcx > , param_def_id : DefId ) -> ObjectLifetimeDefault {
1152+ debug_assert_eq ! ( tcx. def_kind( param_def_id) , DefKind :: TyParam ) ;
11551153 let param_def_id = param_def_id. expect_local ( ) ;
11561154 let parent_def_id = tcx. local_parent ( param_def_id) ;
1157- let generics = tcx. hir ( ) . get_generics ( parent_def_id) ? ;
1155+ let generics = tcx. hir ( ) . get_generics ( parent_def_id) . unwrap ( ) ;
11581156 let param_hir_id = tcx. local_def_id_to_hir_id ( param_def_id) ;
1159- let param = generics. params . iter ( ) . find ( |p| p. hir_id == param_hir_id) ? ;
1157+ let param = generics. params . iter ( ) . find ( |p| p. hir_id == param_hir_id) . unwrap ( ) ;
11601158
11611159 // Scan the bounds and where-clauses on parameters to extract bounds
11621160 // of the form `T:'a` so as to determine the `ObjectLifetimeDefault`
11631161 // for each type parameter.
11641162 match param. kind {
1165- GenericParamKind :: Lifetime { .. } => None ,
11661163 GenericParamKind :: Type { .. } => {
11671164 let mut set = Set1 :: Empty ;
11681165
@@ -1181,21 +1178,17 @@ fn object_lifetime_default<'tcx>(
11811178 }
11821179 }
11831180
1184- Some ( match set {
1181+ match set {
11851182 Set1 :: Empty => ObjectLifetimeDefault :: Empty ,
11861183 Set1 :: One ( hir:: LifetimeName :: Static ) => ObjectLifetimeDefault :: Static ,
11871184 Set1 :: One ( hir:: LifetimeName :: Param ( param_def_id, _) ) => {
11881185 ObjectLifetimeDefault :: Param ( param_def_id. to_def_id ( ) )
11891186 }
11901187 _ => ObjectLifetimeDefault :: Ambiguous ,
1191- } )
1188+ }
11921189 }
1193- GenericParamKind :: Const { .. } => {
1194- // Generic consts don't impose any constraints.
1195- //
1196- // We still store a dummy value here to allow generic parameters
1197- // in an arbitrary order.
1198- Some ( ObjectLifetimeDefault :: Empty )
1190+ _ => {
1191+ bug ! ( "object_lifetime_default_raw must only be called on a type parameter" )
11991192 }
12001193 }
12011194}
@@ -1512,7 +1505,20 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15121505 generics
15131506 . params
15141507 . iter ( )
1515- . filter_map ( |param| self . tcx . object_lifetime_default ( param. def_id ) )
1508+ . filter_map ( |param| {
1509+ match self . tcx . def_kind ( param. def_id ) {
1510+ // Generic consts don't impose any constraints.
1511+ //
1512+ // We still store a dummy value here to allow generic parameters
1513+ // in an arbitrary order.
1514+ DefKind :: ConstParam => Some ( ObjectLifetimeDefault :: Empty ) ,
1515+ DefKind :: TyParam => Some ( self . tcx . object_lifetime_default ( param. def_id ) ) ,
1516+ // We may also get a `Trait` or `TraitAlias` because of how generics `Self` parameter
1517+ // works. Ignore it because it can't have a meaningful lifetime default.
1518+ DefKind :: LifetimeParam | DefKind :: Trait | DefKind :: TraitAlias => None ,
1519+ dk => bug ! ( "unexpected def_kind {:?}" , dk) ,
1520+ }
1521+ } )
15161522 . map ( set_to_region)
15171523 . collect ( )
15181524 } ) ;
0 commit comments