@@ -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
}
@@ -1225,13 +1230,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1225
1230
} ;
1226
1231
}
1227
1232
}
1228
- bounds. projection_bounds . push ( (
1229
- projection_ty. map_bound ( |projection_ty| ty:: ProjectionPredicate {
1230
- projection_ty,
1231
- term : term,
1232
- } ) ,
1233
+ bounds. push_projection_bound (
1234
+ tcx,
1235
+ projection_ty
1236
+ . map_bound ( |projection_ty| ty:: ProjectionPredicate { projection_ty, term } ) ,
1233
1237
binding. span ,
1234
- ) ) ;
1238
+ ) ;
1235
1239
}
1236
1240
ConvertedBindingKind :: Constraint ( ast_bounds) => {
1237
1241
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
@@ -1260,7 +1264,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1260
1264
fn conv_object_ty_poly_trait_ref (
1261
1265
& self ,
1262
1266
span : Span ,
1263
- trait_bounds : & [ hir:: PolyTraitRef < ' _ > ] ,
1267
+ hir_trait_bounds : & [ hir:: PolyTraitRef < ' _ > ] ,
1264
1268
lifetime : & hir:: Lifetime ,
1265
1269
borrowed : bool ,
1266
1270
representation : DynKind ,
@@ -1270,7 +1274,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1270
1274
let mut bounds = Bounds :: default ( ) ;
1271
1275
let mut potential_assoc_types = Vec :: new ( ) ;
1272
1276
let dummy_self = self . tcx ( ) . types . trait_object_dummy_self ;
1273
- for trait_bound in trait_bounds . iter ( ) . rev ( ) {
1277
+ for trait_bound in hir_trait_bounds . iter ( ) . rev ( ) {
1274
1278
if let GenericArgCountResult {
1275
1279
correct :
1276
1280
Err ( GenericArgCountMismatch { invalid_args : cur_potential_assoc_types, .. } ) ,
@@ -1287,10 +1291,45 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1287
1291
}
1288
1292
}
1289
1293
1294
+ let mut trait_bounds = vec ! [ ] ;
1295
+ let mut projection_bounds = vec ! [ ] ;
1296
+ for ( pred, span) in bounds. predicates ( ) {
1297
+ let bound_pred = pred. kind ( ) ;
1298
+ match bound_pred. skip_binder ( ) {
1299
+ ty:: PredicateKind :: Clause ( clause) => match clause {
1300
+ ty:: Clause :: Trait ( trait_pred) => {
1301
+ assert_eq ! ( trait_pred. polarity, ty:: ImplPolarity :: Positive ) ;
1302
+ trait_bounds. push ( (
1303
+ bound_pred. rebind ( trait_pred. trait_ref ) ,
1304
+ span,
1305
+ trait_pred. constness ,
1306
+ ) ) ;
1307
+ }
1308
+ ty:: Clause :: Projection ( proj) => {
1309
+ projection_bounds. push ( ( bound_pred. rebind ( proj) , span) ) ;
1310
+ }
1311
+ ty:: Clause :: TypeOutlives ( _) => {
1312
+ // Do nothing, we deal with regions separately
1313
+ }
1314
+ ty:: Clause :: RegionOutlives ( _) => bug ! ( ) ,
1315
+ } ,
1316
+ ty:: PredicateKind :: WellFormed ( _)
1317
+ | ty:: PredicateKind :: ObjectSafe ( _)
1318
+ | ty:: PredicateKind :: ClosureKind ( _, _, _)
1319
+ | ty:: PredicateKind :: Subtype ( _)
1320
+ | ty:: PredicateKind :: Coerce ( _)
1321
+ | ty:: PredicateKind :: ConstEvaluatable ( _)
1322
+ | ty:: PredicateKind :: ConstEquate ( _, _)
1323
+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( _)
1324
+ | ty:: PredicateKind :: Ambiguous => bug ! ( ) ,
1325
+ }
1326
+ }
1327
+
1290
1328
// Expand trait aliases recursively and check that only one regular (non-auto) trait
1291
1329
// is used and no 'maybe' bounds are used.
1292
1330
let expanded_traits =
1293
- traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . map ( |& ( a, b, _) | ( a, b) ) ) ;
1331
+ traits:: expand_trait_aliases ( tcx, trait_bounds. iter ( ) . map ( |& ( a, b, _) | ( a, b) ) ) ;
1332
+
1294
1333
let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) = expanded_traits
1295
1334
. filter ( |i| i. trait_ref ( ) . self_ty ( ) . skip_binder ( ) == dummy_self)
1296
1335
. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
@@ -1327,8 +1366,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1327
1366
}
1328
1367
1329
1368
if regular_traits. is_empty ( ) && auto_traits. is_empty ( ) {
1330
- let trait_alias_span = bounds
1331
- . trait_bounds
1369
+ let trait_alias_span = trait_bounds
1332
1370
. iter ( )
1333
1371
. map ( |& ( trait_ref, _, _) | trait_ref. def_id ( ) )
1334
1372
. find ( |& trait_ref| tcx. is_trait_alias ( trait_ref) )
@@ -1359,8 +1397,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1359
1397
// Use a `BTreeSet` to keep output in a more consistent order.
1360
1398
let mut associated_types: FxHashMap < Span , BTreeSet < DefId > > = FxHashMap :: default ( ) ;
1361
1399
1362
- let regular_traits_refs_spans = bounds
1363
- . trait_bounds
1400
+ let regular_traits_refs_spans = trait_bounds
1364
1401
. into_iter ( )
1365
1402
. filter ( |( trait_ref, _, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) ) ;
1366
1403
@@ -1414,15 +1451,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1414
1451
// the discussion in #56288 for alternatives.
1415
1452
if !references_self {
1416
1453
// Include projections defined on supertraits.
1417
- bounds . projection_bounds . push ( ( pred, span) ) ;
1454
+ projection_bounds. push ( ( pred, span) ) ;
1418
1455
}
1419
1456
}
1420
1457
_ => ( ) ,
1421
1458
}
1422
1459
}
1423
1460
}
1424
1461
1425
- for ( projection_bound, _) in & bounds . projection_bounds {
1462
+ for ( projection_bound, _) in & projection_bounds {
1426
1463
for def_ids in associated_types. values_mut ( ) {
1427
1464
def_ids. remove ( & projection_bound. projection_def_id ( ) ) ;
1428
1465
}
@@ -1431,7 +1468,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1431
1468
self . complain_about_missing_associated_types (
1432
1469
associated_types,
1433
1470
potential_assoc_types,
1434
- trait_bounds ,
1471
+ hir_trait_bounds ,
1435
1472
) ;
1436
1473
1437
1474
// De-duplicate auto traits so that, e.g., `dyn Trait + Send + Send` is the same as
@@ -1473,7 +1510,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1473
1510
let substs = tcx. intern_substs ( & substs[ ..] ) ;
1474
1511
1475
1512
let span = i. bottom ( ) . 1 ;
1476
- let empty_generic_args = trait_bounds . iter ( ) . any ( |hir_bound| {
1513
+ let empty_generic_args = hir_trait_bounds . iter ( ) . any ( |hir_bound| {
1477
1514
hir_bound. trait_ref . path . res == Res :: Def ( DefKind :: Trait , trait_ref. def_id )
1478
1515
&& hir_bound. span . contains ( span)
1479
1516
} ) ;
@@ -1505,7 +1542,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1505
1542
} )
1506
1543
} ) ;
1507
1544
1508
- let existential_projections = bounds . projection_bounds . iter ( ) . map ( |( bound, _) | {
1545
+ let existential_projections = projection_bounds. iter ( ) . map ( |( bound, _) | {
1509
1546
bound. map_bound ( |mut b| {
1510
1547
assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
1511
1548
0 commit comments