@@ -5,7 +5,6 @@ use crate::ty::subst::{Kind, Subst, SubstsRef};
55
66use rustc_data_structures:: fx:: FxHashSet ;
77
8- use std:: iter;
98use std:: ops:: { Deref , DerefMut } ;
109
1110// `pretty` is a separate module only for organization.
@@ -64,14 +63,14 @@ pub trait Printer: Sized {
6463 type Path ;
6564 type Region ;
6665 type Type ;
66+ type DynExistential ;
6767
6868 fn print_def_path (
6969 self : PrintCx < ' _ , ' _ , ' tcx , Self > ,
7070 def_id : DefId ,
7171 substs : Option < SubstsRef < ' tcx > > ,
72- projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
7372 ) -> Result < Self :: Path , Self :: Error > {
74- self . default_print_def_path ( def_id, substs, projections )
73+ self . default_print_def_path ( def_id, substs)
7574 }
7675 fn print_impl_path (
7776 self : PrintCx < ' _ , ' _ , ' tcx , Self > ,
@@ -93,6 +92,11 @@ pub trait Printer: Sized {
9392 ty : Ty < ' tcx > ,
9493 ) -> Result < Self :: Type , Self :: Error > ;
9594
95+ fn print_dyn_existential (
96+ self : PrintCx < ' _ , ' _ , ' tcx , Self > ,
97+ predicates : & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > ,
98+ ) -> Result < Self :: DynExistential , Self :: Error > ;
99+
96100 fn path_crate (
97101 self : PrintCx < ' _ , ' _ , ' _ , Self > ,
98102 cnum : CrateNum ,
@@ -123,8 +127,7 @@ pub trait Printer: Sized {
123127 print_prefix : impl FnOnce (
124128 PrintCx < ' _ , ' gcx , ' tcx , Self > ,
125129 ) -> Result < Self :: Path , Self :: Error > ,
126- args : impl Iterator < Item = Kind < ' tcx > > + Clone ,
127- projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
130+ args : & [ Kind < ' tcx > ] ,
128131 ) -> Result < Self :: Path , Self :: Error > ;
129132}
130133
@@ -133,7 +136,6 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
133136 self ,
134137 def_id : DefId ,
135138 substs : Option < SubstsRef < ' tcx > > ,
136- projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
137139 ) -> Result < P :: Path , P :: Error > {
138140 debug ! ( "default_print_def_path: def_id={:?}, substs={:?}" , def_id, substs) ;
139141 let key = self . tcx . def_key ( def_id) ;
@@ -175,10 +177,10 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
175177 let trait_ref = ty:: TraitRef :: new ( parent_def_id, substs) ;
176178 cx. path_qualified ( trait_ref. self_ty ( ) , Some ( trait_ref) )
177179 } else {
178- cx. print_def_path ( parent_def_id, substs, iter :: empty ( ) )
180+ cx. print_def_path ( parent_def_id, substs)
179181 }
180182 } else {
181- cx. print_def_path ( parent_def_id, None , iter :: empty ( ) )
183+ cx. print_def_path ( parent_def_id, None )
182184 }
183185 } ;
184186 let print_path = |cx : PrintCx < ' _ , ' gcx , ' tcx , P > | {
@@ -197,7 +199,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
197199
198200 if let ( Some ( generics) , Some ( substs) ) = ( generics, substs) {
199201 let args = self . generic_args_to_print ( generics, substs) ;
200- self . path_generic_args ( print_path, args, projections )
202+ self . path_generic_args ( print_path, args)
201203 } else {
202204 print_path ( self )
203205 }
@@ -209,13 +211,16 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
209211 & self ,
210212 generics : & ' tcx ty:: Generics ,
211213 substs : SubstsRef < ' tcx > ,
212- ) -> impl Iterator < Item = Kind < ' tcx > > + Clone {
214+ ) -> & ' tcx [ Kind < ' tcx > ] {
215+ let mut own_params = generics. parent_count ..generics. count ( ) ;
216+
213217 // Don't print args for `Self` parameters (of traits).
214- let has_own_self = generics. has_self && generics. parent_count == 0 ;
215- let params = & generics. params [ has_own_self as usize ..] ;
218+ if generics. has_self && own_params. start == 0 {
219+ own_params. start = 1 ;
220+ }
216221
217222 // Don't print args that are the defaults of their respective parameters.
218- let num_supplied_defaults = params. iter ( ) . rev ( ) . take_while ( |param| {
223+ own_params . end -= generics . params . iter ( ) . rev ( ) . take_while ( |param| {
219224 match param. kind {
220225 ty:: GenericParamDefKind :: Lifetime => false ,
221226 ty:: GenericParamDefKind :: Type { has_default, .. } => {
@@ -226,9 +231,8 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
226231 ty:: GenericParamDefKind :: Const => false , // FIXME(const_generics:defaults)
227232 }
228233 } ) . count ( ) ;
229- params[ ..params. len ( ) - num_supplied_defaults] . iter ( ) . map ( move |param| {
230- substs[ param. index as usize ]
231- } )
234+
235+ & substs[ own_params]
232236 }
233237
234238 fn default_print_impl_path (
@@ -261,7 +265,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
261265 // trait-type, then fallback to a format that identifies
262266 // the module more clearly.
263267 self . path_append_impl (
264- |cx| cx. print_def_path ( parent_def_id, None , iter :: empty ( ) ) ,
268+ |cx| cx. print_def_path ( parent_def_id, None ) ,
265269 self_ty,
266270 impl_trait_ref,
267271 )
@@ -344,3 +348,11 @@ impl<P: Printer> Print<'tcx, P> for Ty<'tcx> {
344348 cx. print_type ( self )
345349 }
346350}
351+
352+ impl < P : Printer > Print < ' tcx , P > for & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > {
353+ type Output = P :: DynExistential ;
354+ type Error = P :: Error ;
355+ fn print ( & self , cx : PrintCx < ' _ , ' _ , ' tcx , P > ) -> Result < Self :: Output , Self :: Error > {
356+ cx. print_dyn_existential ( self )
357+ }
358+ }
0 commit comments