@@ -682,7 +682,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
682
682
ty:: Binder :: bind_with_vars ( tcx. mk_trait_ref ( trait_def_id, substs) , bound_vars) ;
683
683
684
684
debug ! ( ?poly_trait_ref, ?assoc_bindings) ;
685
- bounds. trait_bounds . push ( ( poly_trait_ref, span, constness) ) ;
685
+ bounds. push_trait_bound ( tcx , poly_trait_ref, span, constness) ;
686
686
687
687
let mut dup_bindings = FxHashMap :: default ( ) ;
688
688
for binding in & assoc_bindings {
@@ -853,18 +853,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
853
853
}
854
854
855
855
/// Sets `implicitly_sized` to true on `Bounds` if necessary
856
- pub ( crate ) fn add_implicitly_sized < ' hir > (
856
+ pub ( crate ) fn add_implicitly_sized (
857
857
& self ,
858
- bounds : & mut Bounds < ' hir > ,
859
- ast_bounds : & ' hir [ hir:: GenericBound < ' hir > ] ,
860
- self_ty_where_predicates : Option < ( LocalDefId , & ' hir [ hir:: WherePredicate < ' hir > ] ) > ,
858
+ bounds : & mut Bounds < ' tcx > ,
859
+ self_ty : Ty < ' tcx > ,
860
+ ast_bounds : & ' tcx [ hir:: GenericBound < ' tcx > ] ,
861
+ self_ty_where_predicates : Option < ( LocalDefId , & ' tcx [ hir:: WherePredicate < ' tcx > ] ) > ,
861
862
span : Span ,
862
863
) {
863
864
let tcx = self . tcx ( ) ;
864
865
865
866
// Try to find an unbound in bounds.
866
867
let mut unbound = None ;
867
- let mut search_bounds = |ast_bounds : & ' hir [ hir:: GenericBound < ' hir > ] | {
868
+ let mut search_bounds = |ast_bounds : & ' tcx [ hir:: GenericBound < ' tcx > ] | {
868
869
for ab in ast_bounds {
869
870
if let hir:: GenericBound :: Trait ( ptr, hir:: TraitBoundModifier :: Maybe ) = ab {
870
871
if unbound. is_none ( ) {
@@ -912,7 +913,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
912
913
// No lang item for `Sized`, so we can't add it as a bound.
913
914
return ;
914
915
}
915
- bounds. implicitly_sized = Some ( span) ;
916
+ bounds. push_sized ( tcx , self_ty , span) ;
916
917
}
917
918
918
919
/// This helper takes a *converted* parameter type (`param_ty`)
@@ -963,10 +964,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
963
964
}
964
965
hir:: GenericBound :: Outlives ( lifetime) => {
965
966
let region = self . ast_region_to_region ( lifetime, None ) ;
966
- bounds. region_bounds . push ( (
967
- ty:: Binder :: bind_with_vars ( region, bound_vars) ,
967
+ bounds. push_region_bound (
968
+ self . tcx ( ) ,
969
+ ty:: Binder :: bind_with_vars (
970
+ ty:: OutlivesPredicate ( param_ty, region) ,
971
+ bound_vars,
972
+ ) ,
968
973
lifetime. ident . span ,
969
- ) ) ;
974
+ ) ;
970
975
}
971
976
}
972
977
}
@@ -1234,13 +1239,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1234
1239
} ;
1235
1240
}
1236
1241
}
1237
- bounds. projection_bounds . push ( (
1238
- projection_ty. map_bound ( |projection_ty| ty:: ProjectionPredicate {
1239
- projection_ty,
1240
- term : term,
1241
- } ) ,
1242
+ bounds. push_projection_bound (
1243
+ tcx,
1244
+ projection_ty
1245
+ . map_bound ( |projection_ty| ty:: ProjectionPredicate { projection_ty, term } ) ,
1242
1246
binding. span ,
1243
- ) ) ;
1247
+ ) ;
1244
1248
}
1245
1249
ConvertedBindingKind :: Constraint ( ast_bounds) => {
1246
1250
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
@@ -1269,7 +1273,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1269
1273
fn conv_object_ty_poly_trait_ref (
1270
1274
& self ,
1271
1275
span : Span ,
1272
- trait_bounds : & [ hir:: PolyTraitRef < ' _ > ] ,
1276
+ hir_trait_bounds : & [ hir:: PolyTraitRef < ' _ > ] ,
1273
1277
lifetime : & hir:: Lifetime ,
1274
1278
borrowed : bool ,
1275
1279
representation : DynKind ,
@@ -1279,7 +1283,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1279
1283
let mut bounds = Bounds :: default ( ) ;
1280
1284
let mut potential_assoc_types = Vec :: new ( ) ;
1281
1285
let dummy_self = self . tcx ( ) . types . trait_object_dummy_self ;
1282
- for trait_bound in trait_bounds . iter ( ) . rev ( ) {
1286
+ for trait_bound in hir_trait_bounds . iter ( ) . rev ( ) {
1283
1287
if let GenericArgCountResult {
1284
1288
correct :
1285
1289
Err ( GenericArgCountMismatch { invalid_args : cur_potential_assoc_types, .. } ) ,
@@ -1296,10 +1300,45 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1296
1300
}
1297
1301
}
1298
1302
1303
+ let mut trait_bounds = vec ! [ ] ;
1304
+ let mut projection_bounds = vec ! [ ] ;
1305
+ for ( pred, span) in bounds. predicates ( ) {
1306
+ let bound_pred = pred. kind ( ) ;
1307
+ match bound_pred. skip_binder ( ) {
1308
+ ty:: PredicateKind :: Clause ( clause) => match clause {
1309
+ ty:: Clause :: Trait ( trait_pred) => {
1310
+ assert_eq ! ( trait_pred. polarity, ty:: ImplPolarity :: Positive ) ;
1311
+ trait_bounds. push ( (
1312
+ bound_pred. rebind ( trait_pred. trait_ref ) ,
1313
+ span,
1314
+ trait_pred. constness ,
1315
+ ) ) ;
1316
+ }
1317
+ ty:: Clause :: Projection ( proj) => {
1318
+ projection_bounds. push ( ( bound_pred. rebind ( proj) , span) ) ;
1319
+ }
1320
+ ty:: Clause :: TypeOutlives ( _) => {
1321
+ // Do nothing, we deal with regions separately
1322
+ }
1323
+ ty:: Clause :: RegionOutlives ( _) => bug ! ( ) ,
1324
+ } ,
1325
+ ty:: PredicateKind :: WellFormed ( _)
1326
+ | ty:: PredicateKind :: ObjectSafe ( _)
1327
+ | ty:: PredicateKind :: ClosureKind ( _, _, _)
1328
+ | ty:: PredicateKind :: Subtype ( _)
1329
+ | ty:: PredicateKind :: Coerce ( _)
1330
+ | ty:: PredicateKind :: ConstEvaluatable ( _)
1331
+ | ty:: PredicateKind :: ConstEquate ( _, _)
1332
+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( _)
1333
+ | ty:: PredicateKind :: Ambiguous => bug ! ( ) ,
1334
+ }
1335
+ }
1336
+
1299
1337
// Expand trait aliases recursively and check that only one regular (non-auto) trait
1300
1338
// is used and no 'maybe' bounds are used.
1301
1339
let expanded_traits =
1302
- traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . map ( |& ( a, b, _) | ( a, b) ) ) ;
1340
+ traits:: expand_trait_aliases ( tcx, trait_bounds. iter ( ) . map ( |& ( a, b, _) | ( a, b) ) ) ;
1341
+
1303
1342
let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) = expanded_traits
1304
1343
. filter ( |i| i. trait_ref ( ) . self_ty ( ) . skip_binder ( ) == dummy_self)
1305
1344
. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
@@ -1336,8 +1375,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1336
1375
}
1337
1376
1338
1377
if regular_traits. is_empty ( ) && auto_traits. is_empty ( ) {
1339
- let trait_alias_span = bounds
1340
- . trait_bounds
1378
+ let trait_alias_span = trait_bounds
1341
1379
. iter ( )
1342
1380
. map ( |& ( trait_ref, _, _) | trait_ref. def_id ( ) )
1343
1381
. find ( |& trait_ref| tcx. is_trait_alias ( trait_ref) )
@@ -1368,8 +1406,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1368
1406
// Use a `BTreeSet` to keep output in a more consistent order.
1369
1407
let mut associated_types: FxHashMap < Span , BTreeSet < DefId > > = FxHashMap :: default ( ) ;
1370
1408
1371
- let regular_traits_refs_spans = bounds
1372
- . trait_bounds
1409
+ let regular_traits_refs_spans = trait_bounds
1373
1410
. into_iter ( )
1374
1411
. filter ( |( trait_ref, _, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) ) ;
1375
1412
@@ -1423,15 +1460,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1423
1460
// the discussion in #56288 for alternatives.
1424
1461
if !references_self {
1425
1462
// Include projections defined on supertraits.
1426
- bounds . projection_bounds . push ( ( pred, span) ) ;
1463
+ projection_bounds. push ( ( pred, span) ) ;
1427
1464
}
1428
1465
}
1429
1466
_ => ( ) ,
1430
1467
}
1431
1468
}
1432
1469
}
1433
1470
1434
- for ( projection_bound, _) in & bounds . projection_bounds {
1471
+ for ( projection_bound, _) in & projection_bounds {
1435
1472
for def_ids in associated_types. values_mut ( ) {
1436
1473
def_ids. remove ( & projection_bound. projection_def_id ( ) ) ;
1437
1474
}
@@ -1440,7 +1477,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1440
1477
self . complain_about_missing_associated_types (
1441
1478
associated_types,
1442
1479
potential_assoc_types,
1443
- trait_bounds ,
1480
+ hir_trait_bounds ,
1444
1481
) ;
1445
1482
1446
1483
// De-duplicate auto traits so that, e.g., `dyn Trait + Send + Send` is the same as
@@ -1482,7 +1519,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1482
1519
let substs = tcx. intern_substs ( & substs[ ..] ) ;
1483
1520
1484
1521
let span = i. bottom ( ) . 1 ;
1485
- let empty_generic_args = trait_bounds . iter ( ) . any ( |hir_bound| {
1522
+ let empty_generic_args = hir_trait_bounds . iter ( ) . any ( |hir_bound| {
1486
1523
hir_bound. trait_ref . path . res == Res :: Def ( DefKind :: Trait , trait_ref. def_id )
1487
1524
&& hir_bound. span . contains ( span)
1488
1525
} ) ;
@@ -1514,7 +1551,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1514
1551
} )
1515
1552
} ) ;
1516
1553
1517
- let existential_projections = bounds . projection_bounds . iter ( ) . map ( |( bound, _) | {
1554
+ let existential_projections = projection_bounds. iter ( ) . map ( |( bound, _) | {
1518
1555
bound. map_bound ( |mut b| {
1519
1556
assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
1520
1557
0 commit comments