@@ -775,11 +775,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
775775 /// The given trait-ref must actually be a trait.
776776 pub ( super ) fn instantiate_poly_trait_ref_inner ( & self ,
777777 trait_ref : & hir:: TraitRef ,
778+ span : Span ,
778779 self_ty : Ty < ' tcx > ,
779780 bounds : & mut Bounds < ' tcx > ,
780781 speculative : bool ,
781- ) -> ( ty:: PolyTraitRef < ' tcx > , Option < Vec < Span > > )
782- {
782+ ) -> Option < Vec < Span > > {
783783 let trait_def_id = trait_ref. trait_def_id ( ) ;
784784
785785 debug ! ( "instantiate_poly_trait_ref({:?}, def_id={:?})" , trait_ref, trait_def_id) ;
@@ -794,6 +794,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
794794 ) ;
795795 let poly_trait_ref = ty:: Binder :: bind ( ty:: TraitRef :: new ( trait_def_id, substs) ) ;
796796
797+ bounds. trait_bounds . push ( ( poly_trait_ref, span) ) ;
798+
797799 let mut dup_bindings = FxHashMap :: default ( ) ;
798800 for binding in & assoc_bindings {
799801 // Specify type to assert that error was already reported in `Err` case.
@@ -811,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
811813
812814 debug ! ( "instantiate_poly_trait_ref({:?}, bounds={:?}) -> {:?}" ,
813815 trait_ref, bounds, poly_trait_ref) ;
814- ( poly_trait_ref , potential_assoc_types)
816+ potential_assoc_types
815817 }
816818
817819 /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
@@ -836,10 +838,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
836838 pub fn instantiate_poly_trait_ref ( & self ,
837839 poly_trait_ref : & hir:: PolyTraitRef ,
838840 self_ty : Ty < ' tcx > ,
839- bounds : & mut Bounds < ' tcx >
840- ) -> ( ty:: PolyTraitRef < ' tcx > , Option < Vec < Span > > )
841- {
842- self . instantiate_poly_trait_ref_inner ( & poly_trait_ref. trait_ref , self_ty, bounds, false )
841+ bounds : & mut Bounds < ' tcx > ,
842+ ) -> Option < Vec < Span > > {
843+ self . instantiate_poly_trait_ref_inner (
844+ & poly_trait_ref. trait_ref ,
845+ poly_trait_ref. span ,
846+ self_ty,
847+ bounds,
848+ false ,
849+ )
843850 }
844851
845852 fn ast_path_to_mono_trait_ref ( & self ,
@@ -983,12 +990,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
983990 }
984991
985992 for bound in trait_bounds {
986- let ( poly_trait_ref , _ ) = self . instantiate_poly_trait_ref (
993+ let _ = self . instantiate_poly_trait_ref (
987994 bound,
988995 param_ty,
989996 bounds,
990997 ) ;
991- bounds. trait_bounds . push ( ( poly_trait_ref, bound. span ) )
992998 }
993999
9941000 bounds. region_bounds . extend ( region_bounds
@@ -1172,11 +1178,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11721178 // Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
11731179 // parameter to have a skipped binder.
11741180 let param_ty = tcx. mk_projection ( assoc_ty. def_id , candidate. skip_binder ( ) . substs ) ;
1175- self . add_bounds (
1176- param_ty,
1177- ast_bounds,
1178- bounds,
1179- ) ;
1181+ self . add_bounds ( param_ty, ast_bounds, bounds) ;
11801182 }
11811183 }
11821184 Ok ( ( ) )
@@ -1216,25 +1218,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12161218 let mut bounds = Bounds :: default ( ) ;
12171219 let mut potential_assoc_types = Vec :: new ( ) ;
12181220 let dummy_self = self . tcx ( ) . types . trait_object_dummy_self ;
1219- // FIXME: we want to avoid collecting into a `Vec` here, but simply cloning the iterator is
1220- // not straightforward due to the borrow checker.
1221- let bound_trait_refs: Vec < _ > = trait_bounds
1222- . iter ( )
1223- . rev ( )
1224- . map ( |trait_bound| {
1225- let ( trait_ref, cur_potential_assoc_types) = self . instantiate_poly_trait_ref (
1226- trait_bound,
1227- dummy_self,
1228- & mut bounds,
1229- ) ;
1230- potential_assoc_types. extend ( cur_potential_assoc_types. into_iter ( ) . flatten ( ) ) ;
1231- ( trait_ref, trait_bound. span )
1232- } )
1233- . collect ( ) ;
1221+ for trait_bound in trait_bounds. iter ( ) . rev ( ) {
1222+ let cur_potential_assoc_types = self . instantiate_poly_trait_ref (
1223+ trait_bound,
1224+ dummy_self,
1225+ & mut bounds,
1226+ ) ;
1227+ potential_assoc_types. extend ( cur_potential_assoc_types. into_iter ( ) . flatten ( ) ) ;
1228+ }
12341229
12351230 // Expand trait aliases recursively and check that only one regular (non-auto) trait
12361231 // is used and no 'maybe' bounds are used.
1237- let expanded_traits = traits:: expand_trait_aliases ( tcx, bound_trait_refs. iter ( ) . cloned ( ) ) ;
1232+ let expanded_traits =
1233+ traits:: expand_trait_aliases ( tcx, bounds. trait_bounds . iter ( ) . cloned ( ) ) ;
12381234 let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
12391235 expanded_traits. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
12401236 if regular_traits. len ( ) > 1 {
@@ -1276,7 +1272,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12761272 // Use a `BTreeSet` to keep output in a more consistent order.
12771273 let mut associated_types = BTreeSet :: default ( ) ;
12781274
1279- let regular_traits_refs = bound_trait_refs
1275+ let regular_traits_refs = bounds . trait_bounds
12801276 . into_iter ( )
12811277 . filter ( |( trait_ref, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) )
12821278 . map ( |( trait_ref, _) | trait_ref) ;
0 commit comments