Skip to content

Commit a8e7baa

Browse files
author
Alexander Regueiro
committed
Fixed nits raised in review.
1 parent bed5ff4 commit a8e7baa

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

src/librustc/traits/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub use self::engine::{TraitEngine, TraitEngineExt};
6161
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
6262
pub use self::util::{supertraits, supertrait_def_ids, transitive_bounds,
6363
Supertraits, SupertraitDefIds};
64-
pub use self::util::{expand_trait_refs, TraitRefExpander, TraitRefExpansionInfoDignosticBuilder};
64+
pub use self::util::{expand_trait_aliases, TraitAliasExpander,
65+
TraitAliasExpansionInfoDignosticBuilder};
6566

6667
pub use self::chalk_fulfill::{
6768
CanonicalGoal as ChalkCanonicalGoal,

src/librustc/traits/util.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
258258
}
259259

260260
///////////////////////////////////////////////////////////////////////////
261-
// `TraitRefExpander` iterator
261+
// `TraitAliasExpander` iterator
262262
///////////////////////////////////////////////////////////////////////////
263263

264264
/// "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>,
267267
/// `trait Foo = Bar + Sync;`, and another trait alias
268268
/// `trait Bar = Read + Write`, then the bounds would expand to
269269
/// `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>>,
272272
visited: PredicateSet<'a, 'gcx, 'tcx>,
273273
}
274274

275275
#[derive(Debug, Clone)]
276-
pub struct TraitRefExpansionInfo<'tcx> {
276+
pub struct TraitAliasExpansionInfo<'tcx> {
277277
pub items: SmallVec<[(ty::PolyTraitRef<'tcx>, Span); 4]>,
278278
}
279279

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 {
283283
items: smallvec![(trait_ref, span)]
284284
}
285285
}
286286

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> {
288288
let mut items = self.items.clone();
289289
items.push((trait_ref, span));
290290

291-
TraitRefExpansionInfo {
291+
TraitAliasExpansionInfo {
292292
items
293293
}
294294
}
@@ -306,15 +306,15 @@ impl<'tcx> TraitRefExpansionInfo<'tcx> {
306306
}
307307
}
308308

309-
pub trait TraitRefExpansionInfoDignosticBuilder {
309+
pub trait TraitAliasExpansionInfoDignosticBuilder {
310310
fn label_with_exp_info<'tcx>(&mut self,
311-
info: &TraitRefExpansionInfo<'tcx>,
311+
info: &TraitAliasExpansionInfo<'tcx>,
312312
top_label: &str) -> &mut Self;
313313
}
314314

315-
impl<'a> TraitRefExpansionInfoDignosticBuilder for DiagnosticBuilder<'a> {
315+
impl<'a> TraitAliasExpansionInfoDignosticBuilder for DiagnosticBuilder<'a> {
316316
fn label_with_exp_info<'tcx>(&mut self,
317-
info: &TraitRefExpansionInfo<'tcx>,
317+
info: &TraitAliasExpansionInfo<'tcx>,
318318
top_label: &str) -> &mut Self {
319319
self.span_label(info.top().1, top_label);
320320
if info.items.len() > 1 {
@@ -326,31 +326,34 @@ impl<'a> TraitRefExpansionInfoDignosticBuilder for DiagnosticBuilder<'a> {
326326
}
327327
}
328328

329-
pub fn expand_trait_refs<'cx, 'gcx, 'tcx>(
329+
pub fn expand_trait_aliases<'cx, 'gcx, 'tcx>(
330330
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
331331
trait_refs: impl IntoIterator<Item = (ty::PolyTraitRef<'tcx>, Span)>
332-
) -> TraitRefExpander<'cx, 'gcx, 'tcx> {
332+
) -> TraitAliasExpander<'cx, 'gcx, 'tcx> {
333333
let mut visited = PredicateSet::new(tcx);
334334
let mut items: Vec<_> = trait_refs
335335
.into_iter()
336-
.map(|(tr, sp)| TraitRefExpansionInfo::new(tr, sp))
336+
.map(|(tr, sp)| TraitAliasExpansionInfo::new(tr, sp))
337337
.collect();
338338
// Note: we also retain auto traits here for the purpose of linting duplicate auto traits
339339
// in the `AstConv::conv_object_ty_poly_trait_ref` function.
340340
items.retain(|i| {
341341
let trait_ref = i.trait_ref();
342342
visited.insert(&trait_ref.to_predicate()) || tcx.trait_is_auto(trait_ref.def_id())
343343
});
344-
TraitRefExpander { stack: items, visited: visited, }
344+
TraitAliasExpander { stack: items, visited: visited, }
345345
}
346346

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 {
350353
let tcx = self.visited.tcx;
351354
let trait_ref = item.trait_ref();
352355

353-
debug!("expand_trait_refs: trait_ref={:?}", trait_ref);
356+
debug!("expand_trait_aliases: trait_ref={:?}", trait_ref);
354357

355358
if !tcx.is_trait_alias(trait_ref.def_id()) {
356359
return true;
@@ -369,7 +372,7 @@ impl<'cx, 'gcx, 'tcx> TraitRefExpander<'cx, 'gcx, 'tcx> {
369372
})
370373
.collect();
371374

372-
debug!("expand_trait_refs: items={:?}", items);
375+
debug!("expand_trait_aliases: items={:?}", items);
373376

374377
// Only keep those items that we haven't already seen.
375378
// 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> {
384387
}
385388
}
386389

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>;
389392

390393
fn size_hint(&self) -> (usize, Option<usize>) {
391394
(self.stack.len(), None)
392395
}
393396

394-
fn next(&mut self) -> Option<TraitRefExpansionInfo<'tcx>> {
397+
fn next(&mut self) -> Option<TraitAliasExpansionInfo<'tcx>> {
395398
loop {
396399
let item = self.stack.pop();
397400
match item {

src/librustc_typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use hir::HirVec;
1010
use lint;
1111
use middle::resolve_lifetime as rl;
1212
use namespace::Namespace;
13-
use rustc::traits::{self, TraitRefExpansionInfoDignosticBuilder};
13+
use rustc::traits::{self, TraitAliasExpansionInfoDignosticBuilder};
1414
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
1515
use rustc::ty::{GenericParamDef, GenericParamDefKind};
1616
use rustc::ty::subst::{Kind, Subst, Substs};
@@ -988,7 +988,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
988988
}
989989
bound_trait_refs.push((principal, trait_bounds[0].span));
990990

991-
let expanded_traits = traits::expand_trait_refs(tcx, bound_trait_refs);
991+
let expanded_traits = traits::expand_trait_aliases(tcx, bound_trait_refs);
992992
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) =
993993
expanded_traits.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id()));
994994
if regular_traits.len() > 1 {

0 commit comments

Comments
 (0)