@@ -1617,9 +1617,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
1617
1617
// HACK: pick the first `did` as the `did` of the trait object. Someone
1618
1618
// might want to implement "native" support for marker-trait-only
1619
1619
// trait objects.
1620
- let mut dids = obj. principal_def_id ( ) . into_iter ( ) . chain ( obj. auto_traits ( ) ) ;
1621
- let did = dids
1622
- . next ( )
1620
+ let mut dids = obj. auto_traits ( ) ;
1621
+ let did = obj
1622
+ . principal_def_id ( )
1623
+ . or_else ( || dids. next ( ) )
1623
1624
. unwrap_or_else ( || panic ! ( "found trait object `{:?}` with no traits?" , this) ) ;
1624
1625
let substs = match obj. principal ( ) {
1625
1626
Some ( principal) => principal. skip_binder ( ) . substs ,
@@ -1630,19 +1631,18 @@ pub(crate) fn clean_middle_ty<'tcx>(
1630
1631
inline:: record_extern_fqn ( cx, did, ItemType :: Trait ) ;
1631
1632
1632
1633
let lifetime = clean_middle_region ( * reg) ;
1633
- let mut bounds = vec ! [ ] ;
1634
-
1635
- for did in dids {
1636
- let empty = cx. tcx . intern_substs ( & [ ] ) ;
1637
- let path = external_path ( cx, did, false , vec ! [ ] , empty) ;
1638
- inline:: record_extern_fqn ( cx, did, ItemType :: Trait ) ;
1639
- let bound = PolyTrait { trait_ : path, generic_params : Vec :: new ( ) } ;
1640
- bounds. push ( bound) ;
1641
- }
1634
+ let mut bounds = dids
1635
+ . map ( |did| {
1636
+ let empty = cx. tcx . intern_substs ( & [ ] ) ;
1637
+ let path = external_path ( cx, did, false , vec ! [ ] , empty) ;
1638
+ inline:: record_extern_fqn ( cx, did, ItemType :: Trait ) ;
1639
+ PolyTrait { trait_ : path, generic_params : Vec :: new ( ) }
1640
+ } )
1641
+ . collect :: < Vec < _ > > ( ) ;
1642
1642
1643
- let mut bindings = vec ! [ ] ;
1644
- for pb in obj . projection_bounds ( ) {
1645
- bindings . push ( TypeBinding {
1643
+ let bindings = obj
1644
+ . projection_bounds ( )
1645
+ . map ( |pb| TypeBinding {
1646
1646
assoc : projection_to_path_segment (
1647
1647
pb. skip_binder ( )
1648
1648
. lift_to_tcx ( cx. tcx )
@@ -1656,8 +1656,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
1656
1656
kind : TypeBindingKind :: Equality {
1657
1657
term : clean_middle_term ( pb. skip_binder ( ) . term , cx) ,
1658
1658
} ,
1659
- } ) ;
1660
- }
1659
+ } )
1660
+ . collect ( ) ;
1661
1661
1662
1662
let path = external_path ( cx, did, false , bindings, substs) ;
1663
1663
bounds. insert ( 0 , PolyTrait { trait_ : path, generic_params : Vec :: new ( ) } ) ;
0 commit comments