@@ -1247,8 +1247,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1247
1247
// Expand trait aliases recursively and check that only one regular (non-auto) trait
1248
1248
// is used and no 'maybe' bounds are used.
1249
1249
let expanded_traits =
1250
- traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . cloned ( ) ) ;
1251
- let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
1250
+ traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . cloned ( ) )
1251
+ // Ensure that trait ref is to self type and not some type param.
1252
+ . filter ( |info| info. trait_ref ( ) . self_ty ( ) == dummy_self) ;
1253
+ let ( auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
1252
1254
expanded_traits. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
1253
1255
if regular_traits. len ( ) > 1 {
1254
1256
let first_trait = & regular_traits[ 0 ] ;
@@ -1289,7 +1291,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1289
1291
let mut associated_types = BTreeSet :: default ( ) ;
1290
1292
1291
1293
let regular_traits_refs = bounds. trait_bounds
1292
- . into_iter ( )
1294
+ . iter ( )
1295
+ . cloned ( )
1293
1296
. filter ( |( trait_ref, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) )
1294
1297
. map ( |( trait_ref, _) | trait_ref) ;
1295
1298
for trait_ref in traits:: elaborate_trait_refs ( tcx, regular_traits_refs) {
@@ -1398,10 +1401,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1398
1401
err. emit ( ) ;
1399
1402
}
1400
1403
1404
+ let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
1405
+ bounds. trait_bounds
1406
+ . into_iter ( )
1407
+ . map ( |( trait_ref, _) | trait_ref)
1408
+ . partition ( |i| tcx. trait_is_auto ( i. def_id ( ) ) ) ;
1409
+
1401
1410
// De-duplicate auto traits so that, e.g., `dyn Trait + Send + Send` is the same as
1402
1411
// `dyn Trait + Send`.
1403
- auto_traits. sort_by_key ( |i| i. trait_ref ( ) . def_id ( ) ) ;
1404
- auto_traits. dedup_by_key ( |i| i. trait_ref ( ) . def_id ( ) ) ;
1412
+ auto_traits. sort_by_key ( |i| i. def_id ( ) ) ;
1413
+ auto_traits. dedup_by_key ( |i| i. def_id ( ) ) ;
1405
1414
debug ! ( "regular_traits: {:?}" , regular_traits) ;
1406
1415
debug ! ( "auto_traits: {:?}" , auto_traits) ;
1407
1416
@@ -1415,25 +1424,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1415
1424
} ;
1416
1425
1417
1426
// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
1418
- let existential_trait_refs = regular_traits. iter ( ) . map ( |i| {
1419
- i. trait_ref ( ) . map_bound ( |trait_ref| trait_ref_to_existential ( trait_ref) )
1420
- } ) ;
1421
- let existential_projections = bounds. projection_bounds . iter ( ) . map ( |( bound, _) | {
1422
- bound. map_bound ( |b| {
1423
- let trait_ref = trait_ref_to_existential ( b. projection_ty . trait_ref ( tcx) ) ;
1424
- ty:: ExistentialProjection {
1425
- ty : b. ty ,
1426
- item_def_id : b. projection_ty . item_def_id ,
1427
- substs : trait_ref. substs ,
1428
- }
1429
- } )
1430
- } ) ;
1427
+ let existential_trait_refs = regular_traits
1428
+ . iter ( )
1429
+ . map ( |i| i. map_bound ( |trait_ref| trait_ref_to_existential ( trait_ref) ) ) ;
1430
+ let existential_projections = bounds. projection_bounds
1431
+ . iter ( )
1432
+ . map ( |( bound, _) | {
1433
+ bound. map_bound ( |b| {
1434
+ let trait_ref = trait_ref_to_existential ( b. projection_ty . trait_ref ( tcx) ) ;
1435
+ ty:: ExistentialProjection {
1436
+ ty : b. ty ,
1437
+ item_def_id : b. projection_ty . item_def_id ,
1438
+ substs : trait_ref. substs ,
1439
+ }
1440
+ } )
1441
+ } ) ;
1431
1442
1432
1443
// Calling `skip_binder` is okay because the predicates are re-bound.
1433
- let regular_trait_predicates = existential_trait_refs. map (
1434
- |trait_ref| ty:: ExistentialPredicate :: Trait ( * trait_ref. skip_binder ( ) ) ) ;
1435
- let auto_trait_predicates = auto_traits. into_iter ( ) . map (
1436
- |trait_ref| ty:: ExistentialPredicate :: AutoTrait ( trait_ref. trait_ref ( ) . def_id ( ) ) ) ;
1444
+ let regular_trait_predicates = existential_trait_refs
1445
+ . map ( |trait_ref| ty:: ExistentialPredicate :: Trait ( * trait_ref. skip_binder ( ) ) ) ;
1446
+ let auto_trait_predicates = auto_traits
1447
+ . into_iter ( )
1448
+ . map ( |trait_ref| ty:: ExistentialPredicate :: AutoTrait ( trait_ref. def_id ( ) ) ) ;
1437
1449
let mut v =
1438
1450
regular_trait_predicates
1439
1451
. chain ( auto_trait_predicates)
0 commit comments