@@ -278,29 +278,6 @@ enum BinderScopeType {
278
278
/// you had `T: for<'a> Foo<Bar: for<'b> Baz<'a, 'b>>`, then the `for<'a>`
279
279
/// scope uses `PolyTraitRef`.
280
280
PolyTraitRef ,
281
- /// This is slightly complicated. Our representation for poly-trait-refs contains a single
282
- /// binder and thus we only allow a single level of quantification. However,
283
- /// the syntax of Rust permits quantification in two places in where clauses,
284
- /// e.g., `T: for <'a> Foo<'a>` and `for <'a, 'b> &'b T: Foo<'a>`. In order
285
- /// to get the De Bruijn indices correct when representing these constraints,
286
- /// we should only introduce one scope. However, we want to support both
287
- /// locations for the quantifier and during lifetime resolution we want
288
- /// precise information (so we can't desugar in an earlier phase). Moreso,
289
- /// an error here doesn't cause a bail from type checking, so we need to be
290
- /// extra careful that we don't lose any bound var information for *either*
291
- /// syntactic binder and that we track all lifetimes defined in both binders.
292
- ///
293
- /// This mechanism is similar to the concatenation done in nested poly trait
294
- /// refs, i.e. the inner syntactic binder extends upon the lifetimes on the
295
- /// outer syntactic binder. However, we require a separate variant here to
296
- /// distinguish `for<'a> T: for<'b> Foo<'a, 'b>` from
297
- /// `T: for<'a> Bar<Baz: for<'b> Foo<'a, 'b>>`. In this case, the innermost
298
- /// `: for<'b> Foo<'a, 'b>` both have a `for<'a>` scope above it. However,
299
- /// in the former case, we must emit an error because this is invalid syntax.
300
- /// Put another way: `PolyTraitRef` and `BoundedTy` behave identically except
301
- /// that `BoundedTy` is used to signal that an error should be emitted if
302
- /// another syntactic binder is found.
303
- BoundedTy ,
304
281
/// Within a syntactic trait ref, there may be multiple poly trait refs that
305
282
/// are nested (under the `associcated_type_bounds` feature). The binders of
306
283
/// the innner poly trait refs are extended from the outer poly trait refs
@@ -309,8 +286,7 @@ enum BinderScopeType {
309
286
/// would be `Concatenating`. This also used in trait refs in where clauses
310
287
/// where we have two binders `for<> T: for<> Foo` (I've intentionally left
311
288
/// out any lifetimes because they aren't needed to show the two scopes).
312
- /// See `BoundedTy` for a bit more details, but the inner `for<>` has a scope
313
- /// of `Concatenating`.
289
+ /// The inner `for<>` has a scope of `Concatenating`.
314
290
Concatenating ,
315
291
/// Any other binder scopes. These are "normal" in that they increase the binder
316
292
/// depth, are fully syntactic, don't concatenate, and don't have special syntactical
@@ -1311,7 +1287,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1311
1287
next_early_index,
1312
1288
track_lifetime_uses : true ,
1313
1289
opaque_type_parent : false ,
1314
- scope_type : BinderScopeType :: BoundedTy ,
1290
+ scope_type : BinderScopeType :: PolyTraitRef ,
1315
1291
} ;
1316
1292
this. with ( scope, |old_scope, this| {
1317
1293
this. check_lifetime_params ( old_scope, & bound_generic_params) ;
@@ -1344,30 +1320,24 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1344
1320
// FIXME(jackh726): This is pretty weird. `LangItemTrait` doesn't go
1345
1321
// through the regular poly trait ref code, so we don't get another
1346
1322
// chance to introduce a binder. For now, I'm keeping the existing logic
1347
- // of "if there isn't a `BoundedTy` scope above us, add one", but I
1323
+ // of "if there isn't a Binder scope above us, add one", but I
1348
1324
// imagine there's a better way to go about this.
1349
1325
let mut scope = self . scope ;
1350
1326
let trait_ref_hack = loop {
1351
1327
match scope {
1352
- Scope :: Body { .. } | Scope :: Root => {
1328
+ Scope :: TraitRefBoundary { .. } | Scope :: Body { .. } | Scope :: Root => {
1353
1329
break false ;
1354
1330
}
1355
1331
1332
+ Scope :: Binder { .. } => {
1333
+ break true ;
1334
+ }
1335
+
1356
1336
Scope :: Elision { s, .. }
1357
1337
| Scope :: ObjectLifetimeDefault { s, .. }
1358
1338
| Scope :: Supertrait { s, .. } => {
1359
1339
scope = s;
1360
1340
}
1361
-
1362
- Scope :: TraitRefBoundary { .. } => {
1363
- break false ;
1364
- }
1365
-
1366
- Scope :: Binder { scope_type, lifetimes, .. } => {
1367
- let trait_ref_hack =
1368
- matches ! ( scope_type, BinderScopeType :: BoundedTy ) && !lifetimes. is_empty ( ) ;
1369
- break trait_ref_hack;
1370
- }
1371
1341
}
1372
1342
} ;
1373
1343
match bound {
@@ -1402,10 +1372,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1402
1372
let next_early_index = self . next_early_index ( ) ;
1403
1373
let mut scope = self . scope ;
1404
1374
let mut supertrait_lifetimes = vec ! [ ] ;
1405
- let ( mut binders, trait_ref_hack , scope_type) = loop {
1375
+ let ( mut binders, scope_type) = loop {
1406
1376
match scope {
1407
1377
Scope :: Body { .. } | Scope :: Root => {
1408
- break ( vec ! [ ] , false , BinderScopeType :: PolyTraitRef ) ;
1378
+ break ( vec ! [ ] , BinderScopeType :: PolyTraitRef ) ;
1409
1379
}
1410
1380
1411
1381
Scope :: Elision { s, .. } | Scope :: ObjectLifetimeDefault { s, .. } => {
@@ -1420,10 +1390,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1420
1390
Scope :: TraitRefBoundary { .. } => {
1421
1391
// We should only see super trait lifetimes if there is a `Binder` above
1422
1392
assert ! ( supertrait_lifetimes. is_empty( ) ) ;
1423
- break ( vec ! [ ] , false , BinderScopeType :: PolyTraitRef ) ;
1393
+ break ( vec ! [ ] , BinderScopeType :: PolyTraitRef ) ;
1424
1394
}
1425
1395
1426
- Scope :: Binder { hir_id, scope_type, lifetimes , .. } => {
1396
+ Scope :: Binder { hir_id, scope_type, .. } => {
1427
1397
if let BinderScopeType :: Other = scope_type {
1428
1398
bug ! (
1429
1399
"Expected all syntacic poly trait refs to be surrounded by a `TraitRefBoundary`"
@@ -1434,30 +1404,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1434
1404
let mut full_binders =
1435
1405
self . map . late_bound_vars . entry ( * hir_id) . or_default ( ) . clone ( ) ;
1436
1406
full_binders. extend ( supertrait_lifetimes. into_iter ( ) ) ;
1437
- let trait_ref_hack =
1438
- matches ! ( scope_type, BinderScopeType :: BoundedTy ) && !lifetimes. is_empty ( ) ;
1439
- break ( full_binders, trait_ref_hack, BinderScopeType :: Concatenating ) ;
1407
+ break ( full_binders, BinderScopeType :: Concatenating ) ;
1440
1408
}
1441
1409
}
1442
1410
} ;
1443
1411
1444
- // See note on `BinderScopeType::BoundedTy`. If `for<..>`
1445
- // has been defined in both the outer and inner part of the
1446
- // trait ref, emit an error.
1447
- let has_lifetimes = trait_ref. bound_generic_params . iter ( ) . any ( |param| match param. kind {
1448
- GenericParamKind :: Lifetime { .. } => true ,
1449
- _ => false ,
1450
- } ) ;
1451
- if trait_ref_hack && has_lifetimes {
1452
- struct_span_err ! (
1453
- self . tcx. sess,
1454
- trait_ref. span,
1455
- E0316 ,
1456
- "nested quantification of lifetimes"
1457
- )
1458
- . emit ( ) ;
1459
- }
1460
-
1461
1412
let initial_bound_vars = binders. len ( ) as u32 ;
1462
1413
let mut lifetimes: FxHashMap < hir:: ParamName , Region > = FxHashMap :: default ( ) ;
1463
1414
let binders_iter = trait_ref
@@ -1486,7 +1437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
1486
1437
// Always introduce a scope here, even if this is in a where clause and
1487
1438
// we introduced the binders around the bounded Ty. In that case, we
1488
1439
// just reuse the concatenation functionality also present in nested trait
1489
- // refs. See `BinderScopeType::BoundedTy` for more details on that case.
1440
+ // refs.
1490
1441
let scope = Scope :: Binder {
1491
1442
hir_id : trait_ref. trait_ref . hir_ref_id ,
1492
1443
lifetimes,
@@ -2319,7 +2270,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2319
2270
}
2320
2271
match scope_type {
2321
2272
BinderScopeType :: Other => late_depth += 1 ,
2322
- BinderScopeType :: BoundedTy => late_depth += 1 ,
2323
2273
BinderScopeType :: PolyTraitRef => late_depth += 1 ,
2324
2274
BinderScopeType :: Concatenating => { }
2325
2275
}
@@ -3051,7 +3001,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
3051
3001
}
3052
3002
match scope_type {
3053
3003
BinderScopeType :: Other => late_depth += 1 ,
3054
- BinderScopeType :: BoundedTy => late_depth += 1 ,
3055
3004
BinderScopeType :: PolyTraitRef => late_depth += 1 ,
3056
3005
BinderScopeType :: Concatenating => { }
3057
3006
}
@@ -3216,7 +3165,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
3216
3165
Scope :: Binder { s, scope_type, .. } => {
3217
3166
match scope_type {
3218
3167
BinderScopeType :: Other => late_depth += 1 ,
3219
- BinderScopeType :: BoundedTy => late_depth += 1 ,
3220
3168
BinderScopeType :: PolyTraitRef => late_depth += 1 ,
3221
3169
BinderScopeType :: Concatenating => { }
3222
3170
}
0 commit comments