@@ -775,11 +775,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
775
775
/// The given trait-ref must actually be a trait.
776
776
pub ( super ) fn instantiate_poly_trait_ref_inner ( & self ,
777
777
trait_ref : & hir:: TraitRef ,
778
+ span : Span ,
778
779
self_ty : Ty < ' tcx > ,
779
780
bounds : & mut Bounds < ' tcx > ,
780
781
speculative : bool ,
781
- ) -> ( ty:: PolyTraitRef < ' tcx > , Option < Vec < Span > > )
782
- {
782
+ ) -> Option < Vec < Span > > {
783
783
let trait_def_id = trait_ref. trait_def_id ( ) ;
784
784
785
785
debug ! ( "instantiate_poly_trait_ref({:?}, def_id={:?})" , trait_ref, trait_def_id) ;
@@ -794,6 +794,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
794
794
) ;
795
795
let poly_trait_ref = ty:: Binder :: bind ( ty:: TraitRef :: new ( trait_def_id, substs) ) ;
796
796
797
+ bounds. trait_bounds . push ( ( poly_trait_ref, span) ) ;
798
+
797
799
let mut dup_bindings = FxHashMap :: default ( ) ;
798
800
for binding in & assoc_bindings {
799
801
// Specify type to assert that error was already reported in `Err` case.
@@ -811,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
811
813
812
814
debug ! ( "instantiate_poly_trait_ref({:?}, bounds={:?}) -> {:?}" ,
813
815
trait_ref, bounds, poly_trait_ref) ;
814
- ( poly_trait_ref , potential_assoc_types)
816
+ potential_assoc_types
815
817
}
816
818
817
819
/// 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 {
836
838
pub fn instantiate_poly_trait_ref ( & self ,
837
839
poly_trait_ref : & hir:: PolyTraitRef ,
838
840
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
+ )
843
850
}
844
851
845
852
fn ast_path_to_mono_trait_ref ( & self ,
@@ -983,12 +990,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
983
990
}
984
991
985
992
for bound in trait_bounds {
986
- let ( poly_trait_ref , _ ) = self . instantiate_poly_trait_ref (
993
+ let _ = self . instantiate_poly_trait_ref (
987
994
bound,
988
995
param_ty,
989
996
bounds,
990
997
) ;
991
- bounds. trait_bounds . push ( ( poly_trait_ref, bound. span ) )
992
998
}
993
999
994
1000
bounds. region_bounds . extend ( region_bounds
@@ -1172,11 +1178,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1172
1178
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
1173
1179
// parameter to have a skipped binder.
1174
1180
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) ;
1180
1182
}
1181
1183
}
1182
1184
Ok ( ( ) )
@@ -1216,25 +1218,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1216
1218
let mut bounds = Bounds :: default ( ) ;
1217
1219
let mut potential_assoc_types = Vec :: new ( ) ;
1218
1220
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
+ }
1234
1229
1235
1230
// Expand trait aliases recursively and check that only one regular (non-auto) trait
1236
1231
// 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 ( ) ) ;
1238
1234
let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
1239
1235
expanded_traits. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
1240
1236
if regular_traits. len ( ) > 1 {
@@ -1276,7 +1272,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1276
1272
// Use a `BTreeSet` to keep output in a more consistent order.
1277
1273
let mut associated_types = BTreeSet :: default ( ) ;
1278
1274
1279
- let regular_traits_refs = bound_trait_refs
1275
+ let regular_traits_refs = bounds . trait_bounds
1280
1276
. into_iter ( )
1281
1277
. filter ( |( trait_ref, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) )
1282
1278
. map ( |( trait_ref, _) | trait_ref) ;
0 commit comments