@@ -258,7 +258,7 @@ pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
258
258
}
259
259
260
260
///////////////////////////////////////////////////////////////////////////
261
- // `TraitRefExpander ` iterator
261
+ // `TraitAliasExpander ` iterator
262
262
///////////////////////////////////////////////////////////////////////////
263
263
264
264
/// "Trait reference expansion" is the process of expanding a sequence of trait
@@ -267,28 +267,28 @@ pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
267
267
/// `trait Foo = Bar + Sync;`, and another trait alias
268
268
/// `trait Bar = Read + Write`, then the bounds would expand to
269
269
/// `Read + Write + Sync + Send`.
270
- pub struct TraitRefExpander < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
271
- stack : Vec < TraitRefExpansionInfo < ' tcx > > ,
270
+ pub struct TraitAliasExpander < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
271
+ stack : Vec < TraitAliasExpansionInfo < ' tcx > > ,
272
272
visited : PredicateSet < ' a , ' gcx , ' tcx > ,
273
273
}
274
274
275
275
#[ derive( Debug , Clone ) ]
276
- pub struct TraitRefExpansionInfo < ' tcx > {
276
+ pub struct TraitAliasExpansionInfo < ' tcx > {
277
277
pub items : SmallVec < [ ( ty:: PolyTraitRef < ' tcx > , Span ) ; 4 ] > ,
278
278
}
279
279
280
- impl < ' tcx > TraitRefExpansionInfo < ' tcx > {
281
- fn new ( trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> TraitRefExpansionInfo < ' tcx > {
282
- TraitRefExpansionInfo {
280
+ impl < ' tcx > TraitAliasExpansionInfo < ' tcx > {
281
+ fn new ( trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> TraitAliasExpansionInfo < ' tcx > {
282
+ TraitAliasExpansionInfo {
283
283
items : smallvec ! [ ( trait_ref, span) ]
284
284
}
285
285
}
286
286
287
- fn push ( & self , trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> TraitRefExpansionInfo < ' tcx > {
287
+ fn push ( & self , trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> TraitAliasExpansionInfo < ' tcx > {
288
288
let mut items = self . items . clone ( ) ;
289
289
items. push ( ( trait_ref, span) ) ;
290
290
291
- TraitRefExpansionInfo {
291
+ TraitAliasExpansionInfo {
292
292
items
293
293
}
294
294
}
@@ -306,15 +306,15 @@ impl<'tcx> TraitRefExpansionInfo<'tcx> {
306
306
}
307
307
}
308
308
309
- pub trait TraitRefExpansionInfoDignosticBuilder {
309
+ pub trait TraitAliasExpansionInfoDignosticBuilder {
310
310
fn label_with_exp_info < ' tcx > ( & mut self ,
311
- info : & TraitRefExpansionInfo < ' tcx > ,
311
+ info : & TraitAliasExpansionInfo < ' tcx > ,
312
312
top_label : & str ) -> & mut Self ;
313
313
}
314
314
315
- impl < ' a > TraitRefExpansionInfoDignosticBuilder for DiagnosticBuilder < ' a > {
315
+ impl < ' a > TraitAliasExpansionInfoDignosticBuilder for DiagnosticBuilder < ' a > {
316
316
fn label_with_exp_info < ' tcx > ( & mut self ,
317
- info : & TraitRefExpansionInfo < ' tcx > ,
317
+ info : & TraitAliasExpansionInfo < ' tcx > ,
318
318
top_label : & str ) -> & mut Self {
319
319
self . span_label ( info. top ( ) . 1 , top_label) ;
320
320
if info. items . len ( ) > 1 {
@@ -326,31 +326,34 @@ impl<'a> TraitRefExpansionInfoDignosticBuilder for DiagnosticBuilder<'a> {
326
326
}
327
327
}
328
328
329
- pub fn expand_trait_refs < ' cx , ' gcx , ' tcx > (
329
+ pub fn expand_trait_aliases < ' cx , ' gcx , ' tcx > (
330
330
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
331
331
trait_refs : impl IntoIterator < Item = ( ty:: PolyTraitRef < ' tcx > , Span ) >
332
- ) -> TraitRefExpander < ' cx , ' gcx , ' tcx > {
332
+ ) -> TraitAliasExpander < ' cx , ' gcx , ' tcx > {
333
333
let mut visited = PredicateSet :: new ( tcx) ;
334
334
let mut items: Vec < _ > = trait_refs
335
335
. into_iter ( )
336
- . map ( |( tr, sp) | TraitRefExpansionInfo :: new ( tr, sp) )
336
+ . map ( |( tr, sp) | TraitAliasExpansionInfo :: new ( tr, sp) )
337
337
. collect ( ) ;
338
338
// Note: we also retain auto traits here for the purpose of linting duplicate auto traits
339
339
// in the `AstConv::conv_object_ty_poly_trait_ref` function.
340
340
items. retain ( |i| {
341
341
let trait_ref = i. trait_ref ( ) ;
342
342
visited. insert ( & trait_ref. to_predicate ( ) ) || tcx. trait_is_auto ( trait_ref. def_id ( ) )
343
343
} ) ;
344
- TraitRefExpander { stack : items, visited : visited, }
344
+ TraitAliasExpander { stack : items, visited : visited, }
345
345
}
346
346
347
- impl < ' cx , ' gcx , ' tcx > TraitRefExpander < ' cx , ' gcx , ' tcx > {
348
- // Returns `true` if `item` refers to a trait.
349
- fn push ( & mut self , item : & TraitRefExpansionInfo < ' tcx > ) -> bool {
347
+ impl < ' cx , ' gcx , ' tcx > TraitAliasExpander < ' cx , ' gcx , ' tcx > {
348
+ /// If item is a trait alias, then expands item to the definition and pushes the resulting
349
+ /// expansion onto `self.stack`, and returns `false` (indicating that item should not be
350
+ /// returned to the user). Otherwise, just returns `true` (indicating that no expansion took
351
+ /// place, and item should be returned to the user).
352
+ fn push ( & mut self , item : & TraitAliasExpansionInfo < ' tcx > ) -> bool {
350
353
let tcx = self . visited . tcx ;
351
354
let trait_ref = item. trait_ref ( ) ;
352
355
353
- debug ! ( "expand_trait_refs : trait_ref={:?}" , trait_ref) ;
356
+ debug ! ( "expand_trait_aliases : trait_ref={:?}" , trait_ref) ;
354
357
355
358
if !tcx. is_trait_alias ( trait_ref. def_id ( ) ) {
356
359
return true ;
@@ -369,7 +372,7 @@ impl<'cx, 'gcx, 'tcx> TraitRefExpander<'cx, 'gcx, 'tcx> {
369
372
} )
370
373
. collect ( ) ;
371
374
372
- debug ! ( "expand_trait_refs : items={:?}" , items) ;
375
+ debug ! ( "expand_trait_aliases : items={:?}" , items) ;
373
376
374
377
// Only keep those items that we haven't already seen.
375
378
// Note: we also retain auto traits here for the purpose of linting duplicate auto traits
@@ -384,14 +387,14 @@ impl<'cx, 'gcx, 'tcx> TraitRefExpander<'cx, 'gcx, 'tcx> {
384
387
}
385
388
}
386
389
387
- impl < ' cx , ' gcx , ' tcx > Iterator for TraitRefExpander < ' cx , ' gcx , ' tcx > {
388
- type Item = TraitRefExpansionInfo < ' tcx > ;
390
+ impl < ' cx , ' gcx , ' tcx > Iterator for TraitAliasExpander < ' cx , ' gcx , ' tcx > {
391
+ type Item = TraitAliasExpansionInfo < ' tcx > ;
389
392
390
393
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
391
394
( self . stack . len ( ) , None )
392
395
}
393
396
394
- fn next ( & mut self ) -> Option < TraitRefExpansionInfo < ' tcx > > {
397
+ fn next ( & mut self ) -> Option < TraitAliasExpansionInfo < ' tcx > > {
395
398
loop {
396
399
let item = self . stack . pop ( ) ;
397
400
match item {
0 commit comments