@@ -1148,21 +1148,18 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1148
1148
}
1149
1149
}
1150
1150
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 ) ;
1155
1153
let param_def_id = param_def_id. expect_local ( ) ;
1156
1154
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 ( ) ;
1158
1156
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 ( ) ;
1160
1158
1161
1159
// Scan the bounds and where-clauses on parameters to extract bounds
1162
1160
// of the form `T:'a` so as to determine the `ObjectLifetimeDefault`
1163
1161
// for each type parameter.
1164
1162
match param. kind {
1165
- GenericParamKind :: Lifetime { .. } => None ,
1166
1163
GenericParamKind :: Type { .. } => {
1167
1164
let mut set = Set1 :: Empty ;
1168
1165
@@ -1181,21 +1178,17 @@ fn object_lifetime_default<'tcx>(
1181
1178
}
1182
1179
}
1183
1180
1184
- Some ( match set {
1181
+ match set {
1185
1182
Set1 :: Empty => ObjectLifetimeDefault :: Empty ,
1186
1183
Set1 :: One ( hir:: LifetimeName :: Static ) => ObjectLifetimeDefault :: Static ,
1187
1184
Set1 :: One ( hir:: LifetimeName :: Param ( param_def_id, _) ) => {
1188
1185
ObjectLifetimeDefault :: Param ( param_def_id. to_def_id ( ) )
1189
1186
}
1190
1187
_ => ObjectLifetimeDefault :: Ambiguous ,
1191
- } )
1188
+ }
1192
1189
}
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" )
1199
1192
}
1200
1193
}
1201
1194
}
@@ -1512,7 +1505,20 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1512
1505
generics
1513
1506
. params
1514
1507
. 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
+ } )
1516
1522
. map ( set_to_region)
1517
1523
. collect ( )
1518
1524
} ) ;
0 commit comments