@@ -638,6 +638,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
638
638
}
639
639
640
640
Scope :: Binder { binder_depth, from_poly_trait_ref, .. } => {
641
+ if concanetate && !passed_boundary && !from_poly_trait_ref {
642
+ bug ! ( "{:?}" , self . scope) ;
643
+ }
641
644
break if concanetate {
642
645
if passed_boundary || !from_poly_trait_ref {
643
646
binder_depth + 1
@@ -850,7 +853,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
850
853
} ;
851
854
self . with ( scope, |old_scope, this| {
852
855
this. check_lifetime_params ( old_scope, & generics. params ) ;
853
- intravisit:: walk_item ( this, item) ;
856
+ let scope = Scope :: TraitRefBoundary { s : this. scope } ;
857
+ this. with ( scope, |_, this| {
858
+ intravisit:: walk_item ( this, item) ;
859
+ } ) ;
854
860
} ) ;
855
861
self . missing_named_lifetime_spots . pop ( ) ;
856
862
}
@@ -985,9 +991,12 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
985
991
986
992
// Elided lifetimes are not allowed in non-return
987
993
// position impl Trait
988
- let scope = Scope :: Elision { elide : Elide :: Forbid , s : self . scope } ;
994
+ let scope = Scope :: TraitRefBoundary { s : self . scope } ;
989
995
self . with ( scope, |_, this| {
990
- intravisit:: walk_item ( this, opaque_ty) ;
996
+ let scope = Scope :: Elision { elide : Elide :: Forbid , s : this. scope } ;
997
+ this. with ( scope, |_, this| {
998
+ intravisit:: walk_item ( this, opaque_ty) ;
999
+ } )
991
1000
} ) ;
992
1001
993
1002
return ;
@@ -1320,93 +1329,93 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1320
1329
if !self . trait_definition_only {
1321
1330
check_mixed_explicit_and_in_band_defs ( self . tcx , & generics. params ) ;
1322
1331
}
1323
- for param in generics. params {
1324
- match param. kind {
1325
- GenericParamKind :: Lifetime { .. } => { }
1326
- GenericParamKind :: Type { ref default, .. } => {
1327
- walk_list ! ( self , visit_param_bound, param. bounds) ;
1328
- if let Some ( ref ty) = default {
1329
- self . visit_ty ( & ty) ;
1332
+ let scope = Scope :: TraitRefBoundary { s : self . scope } ;
1333
+ self . with ( scope, |_, this| {
1334
+ for param in generics. params {
1335
+ match param. kind {
1336
+ GenericParamKind :: Lifetime { .. } => { }
1337
+ GenericParamKind :: Type { ref default, .. } => {
1338
+ walk_list ! ( this, visit_param_bound, param. bounds) ;
1339
+ if let Some ( ref ty) = default {
1340
+ this. visit_ty ( & ty) ;
1341
+ }
1342
+ }
1343
+ GenericParamKind :: Const { ref ty, .. } => {
1344
+ let was_in_const_generic = this. is_in_const_generic ;
1345
+ this. is_in_const_generic = true ;
1346
+ walk_list ! ( this, visit_param_bound, param. bounds) ;
1347
+ this. visit_ty ( & ty) ;
1348
+ this. is_in_const_generic = was_in_const_generic;
1330
1349
}
1331
1350
}
1332
- GenericParamKind :: Const { ref ty, .. } => {
1333
- let was_in_const_generic = self . is_in_const_generic ;
1334
- self . is_in_const_generic = true ;
1335
- walk_list ! ( self , visit_param_bound, param. bounds) ;
1336
- self . visit_ty ( & ty) ;
1337
- self . is_in_const_generic = was_in_const_generic;
1338
- }
1339
- }
1340
- }
1341
- for predicate in generics. where_clause . predicates {
1342
- match predicate {
1343
- & hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1344
- ref bounded_ty,
1345
- bounds,
1346
- ref bound_generic_params,
1347
- ..
1348
- } ) => {
1349
- let ( lifetimes, binders) : ( FxHashMap < hir:: ParamName , Region > , Vec < _ > ) =
1350
- bound_generic_params
1351
- . iter ( )
1352
- . filter_map ( |param| match param. kind {
1353
- GenericParamKind :: Lifetime { .. } => Some ( param) ,
1354
- _ => None ,
1355
- } )
1356
- . enumerate ( )
1357
- . map ( |( late_bound_idx, param) | {
1358
- let pair =
1359
- Region :: late ( late_bound_idx as u32 , & self . tcx . hir ( ) , param) ;
1360
- let r = late_region_as_bound_region ( self . tcx , & pair. 1 ) ;
1361
- ( pair, r)
1362
- } )
1363
- . unzip ( ) ;
1364
- self . map . late_bound_vars . insert ( bounded_ty. hir_id , binders. clone ( ) ) ;
1365
- let scope = Scope :: TraitRefBoundary { s : self . scope } ;
1366
- self . with ( scope, |_, this| {
1367
- if !lifetimes. is_empty ( ) {
1368
- let next_early_index = this. next_early_index ( ) ;
1369
- let scope = Scope :: Binder {
1370
- hir_id : bounded_ty. hir_id ,
1371
- lifetimes,
1372
- s : this. scope ,
1373
- next_early_index,
1374
- track_lifetime_uses : true ,
1375
- opaque_type_parent : false ,
1376
- from_poly_trait_ref : true ,
1377
- binder_depth : this. depth ( false ) ,
1378
- } ;
1379
- this. with ( scope, |old_scope, this| {
1380
- this. check_lifetime_params ( old_scope, & bound_generic_params) ;
1351
+ }
1352
+ for predicate in generics. where_clause . predicates {
1353
+ match predicate {
1354
+ & hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1355
+ ref bounded_ty,
1356
+ bounds,
1357
+ ref bound_generic_params,
1358
+ ..
1359
+ } ) => {
1360
+ let ( lifetimes, binders) : ( FxHashMap < hir:: ParamName , Region > , Vec < _ > ) =
1361
+ bound_generic_params
1362
+ . iter ( )
1363
+ . filter_map ( |param| match param. kind {
1364
+ GenericParamKind :: Lifetime { .. } => Some ( param) ,
1365
+ _ => None ,
1366
+ } )
1367
+ . enumerate ( )
1368
+ . map ( |( late_bound_idx, param) | {
1369
+ let pair =
1370
+ Region :: late ( late_bound_idx as u32 , & this. tcx . hir ( ) , param) ;
1371
+ let r = late_region_as_bound_region ( this. tcx , & pair. 1 ) ;
1372
+ ( pair, r)
1373
+ } )
1374
+ . unzip ( ) ;
1375
+ this. map . late_bound_vars . insert ( bounded_ty. hir_id , binders. clone ( ) ) ;
1376
+ if !lifetimes. is_empty ( ) {
1377
+ let next_early_index = this. next_early_index ( ) ;
1378
+ let scope = Scope :: Binder {
1379
+ hir_id : bounded_ty. hir_id ,
1380
+ lifetimes,
1381
+ s : this. scope ,
1382
+ next_early_index,
1383
+ track_lifetime_uses : true ,
1384
+ opaque_type_parent : false ,
1385
+ from_poly_trait_ref : true ,
1386
+ binder_depth : this. depth ( false ) ,
1387
+ } ;
1388
+ this. with ( scope, |old_scope, this| {
1389
+ this. check_lifetime_params ( old_scope, & bound_generic_params) ;
1390
+ this. visit_ty ( & bounded_ty) ;
1391
+ this. trait_ref_hack = Some ( bounded_ty. hir_id ) ;
1392
+ walk_list ! ( this, visit_param_bound, bounds) ;
1393
+ this. trait_ref_hack = None ;
1394
+ } )
1395
+ } else {
1381
1396
this. visit_ty ( & bounded_ty) ;
1382
- this. trait_ref_hack = Some ( bounded_ty. hir_id ) ;
1383
1397
walk_list ! ( this, visit_param_bound, bounds) ;
1384
- this. trait_ref_hack = None ;
1385
- } )
1386
- } else {
1387
- this. visit_ty ( & bounded_ty) ;
1388
- walk_list ! ( this, visit_param_bound, bounds) ;
1389
- }
1390
- } )
1391
- }
1392
- & hir:: WherePredicate :: RegionPredicate ( hir:: WhereRegionPredicate {
1393
- ref lifetime,
1394
- bounds,
1395
- ..
1396
- } ) => {
1397
- self . visit_lifetime ( lifetime) ;
1398
- walk_list ! ( self , visit_param_bound, bounds) ;
1399
- }
1400
- & hir:: WherePredicate :: EqPredicate ( hir:: WhereEqPredicate {
1401
- ref lhs_ty,
1402
- ref rhs_ty,
1403
- ..
1404
- } ) => {
1405
- self . visit_ty ( lhs_ty) ;
1406
- self . visit_ty ( rhs_ty) ;
1398
+ }
1399
+ }
1400
+ & hir:: WherePredicate :: RegionPredicate ( hir:: WhereRegionPredicate {
1401
+ ref lifetime,
1402
+ bounds,
1403
+ ..
1404
+ } ) => {
1405
+ this. visit_lifetime ( lifetime) ;
1406
+ walk_list ! ( this, visit_param_bound, bounds) ;
1407
+ }
1408
+ & hir:: WherePredicate :: EqPredicate ( hir:: WhereEqPredicate {
1409
+ ref lhs_ty,
1410
+ ref rhs_ty,
1411
+ ..
1412
+ } ) => {
1413
+ this. visit_ty ( lhs_ty) ;
1414
+ this. visit_ty ( rhs_ty) ;
1415
+ }
1407
1416
}
1408
1417
}
1409
- }
1418
+ } )
1410
1419
}
1411
1420
1412
1421
fn visit_param_bound ( & mut self , bound : & ' tcx hir:: GenericBound < ' tcx > ) {
0 commit comments