@@ -5,7 +5,6 @@ use ty::subst::{Kind, Subst, Substs};
5
5
6
6
use rustc_data_structures:: fx:: FxHashSet ;
7
7
8
- use std:: iter;
9
8
use std:: ops:: { Deref , DerefMut } ;
10
9
11
10
// `pretty` is a separate module only for organization.
@@ -64,14 +63,14 @@ pub trait Printer: Sized {
64
63
type Path ;
65
64
type Region ;
66
65
type Type ;
66
+ type DynExistential ;
67
67
68
68
fn print_def_path (
69
69
self : PrintCx < ' _ , ' _ , ' tcx , Self > ,
70
70
def_id : DefId ,
71
71
substs : Option < & ' tcx Substs < ' tcx > > ,
72
- projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
73
72
) -> Result < Self :: Path , Self :: Error > {
74
- self . default_print_def_path ( def_id, substs, projections )
73
+ self . default_print_def_path ( def_id, substs)
75
74
}
76
75
fn print_impl_path (
77
76
self : PrintCx < ' _ , ' _ , ' tcx , Self > ,
@@ -93,6 +92,11 @@ pub trait Printer: Sized {
93
92
ty : Ty < ' tcx > ,
94
93
) -> Result < Self :: Type , Self :: Error > ;
95
94
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
+
96
100
fn path_crate (
97
101
self : PrintCx < ' _ , ' _ , ' _ , Self > ,
98
102
cnum : CrateNum ,
@@ -123,8 +127,7 @@ pub trait Printer: Sized {
123
127
print_prefix : impl FnOnce (
124
128
PrintCx < ' _ , ' gcx , ' tcx , Self > ,
125
129
) -> 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 > ] ,
128
131
) -> Result < Self :: Path , Self :: Error > ;
129
132
}
130
133
@@ -133,7 +136,6 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
133
136
self ,
134
137
def_id : DefId ,
135
138
substs : Option < & ' tcx Substs < ' tcx > > ,
136
- projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
137
139
) -> Result < P :: Path , P :: Error > {
138
140
debug ! ( "default_print_def_path: def_id={:?}, substs={:?}" , def_id, substs) ;
139
141
let key = self . tcx . def_key ( def_id) ;
@@ -175,10 +177,10 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
175
177
let trait_ref = ty:: TraitRef :: new ( parent_def_id, substs) ;
176
178
cx. path_qualified ( trait_ref. self_ty ( ) , Some ( trait_ref) )
177
179
} else {
178
- cx. print_def_path ( parent_def_id, substs, iter :: empty ( ) )
180
+ cx. print_def_path ( parent_def_id, substs)
179
181
}
180
182
} else {
181
- cx. print_def_path ( parent_def_id, None , iter :: empty ( ) )
183
+ cx. print_def_path ( parent_def_id, None )
182
184
}
183
185
} ;
184
186
let print_path = |cx : PrintCx < ' _ , ' gcx , ' tcx , P > | {
@@ -197,7 +199,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
197
199
198
200
if let ( Some ( generics) , Some ( substs) ) = ( generics, substs) {
199
201
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)
201
203
} else {
202
204
print_path ( self )
203
205
}
@@ -209,13 +211,16 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
209
211
& self ,
210
212
generics : & ' tcx ty:: Generics ,
211
213
substs : & ' tcx Substs < ' tcx > ,
212
- ) -> impl Iterator < Item = Kind < ' tcx > > + Clone {
214
+ ) -> & ' tcx [ Kind < ' tcx > ] {
215
+ let mut own_params = generics. parent_count ..generics. count ( ) ;
216
+
213
217
// 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
+ }
216
221
217
222
// 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| {
219
224
match param. kind {
220
225
ty:: GenericParamDefKind :: Lifetime => false ,
221
226
ty:: GenericParamDefKind :: Type { has_default, .. } => {
@@ -225,9 +230,8 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
225
230
}
226
231
}
227
232
} ) . count ( ) ;
228
- params[ ..params. len ( ) - num_supplied_defaults] . iter ( ) . map ( move |param| {
229
- substs[ param. index as usize ]
230
- } )
233
+
234
+ & substs[ own_params]
231
235
}
232
236
233
237
fn default_print_impl_path (
@@ -260,7 +264,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
260
264
// trait-type, then fallback to a format that identifies
261
265
// the module more clearly.
262
266
self . path_append_impl (
263
- |cx| cx. print_def_path ( parent_def_id, None , iter :: empty ( ) ) ,
267
+ |cx| cx. print_def_path ( parent_def_id, None ) ,
264
268
self_ty,
265
269
impl_trait_ref,
266
270
)
@@ -343,3 +347,11 @@ impl<P: Printer> Print<'tcx, P> for Ty<'tcx> {
343
347
cx. print_type ( self )
344
348
}
345
349
}
350
+
351
+ impl < P : Printer > Print < ' tcx , P > for & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > {
352
+ type Output = P :: DynExistential ;
353
+ type Error = P :: Error ;
354
+ fn print ( & self , cx : PrintCx < ' _ , ' _ , ' tcx , P > ) -> Result < Self :: Output , Self :: Error > {
355
+ cx. print_dyn_existential ( self )
356
+ }
357
+ }
0 commit comments