Skip to content

Commit 16692f7

Browse files
author
Alexander Regueiro
committed
Addressed review points.
1 parent 72e5e8b commit 16692f7

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ fn vtable_methods<'a, 'tcx>(
10441044
)
10451045
}
10461046

1047-
impl<'tcx, O> Obligation<'tcx,O> {
1047+
impl<'tcx, O> Obligation<'tcx, O> {
10481048
pub fn new(cause: ObligationCause<'tcx>,
10491049
param_env: ty::ParamEnv<'tcx>,
10501050
predicate: O)

src/librustc/traits/util.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn elaborate_predicates<'cx, 'gcx, 'tcx>(
107107
{
108108
let mut visited = PredicateSet::new(tcx);
109109
predicates.retain(|pred| visited.insert(pred));
110-
Elaborator { stack: predicates, visited: visited }
110+
Elaborator { stack: predicates, visited }
111111
}
112112

113113
impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
@@ -286,47 +286,49 @@ pub fn expand_trait_refs<'cx, 'gcx, 'tcx>(
286286
let mut items: Vec<_> =
287287
trait_refs
288288
.into_iter()
289-
.map(|(tr, sp)| TraitRefExpansionInfo {
290-
top_level_trait_ref: tr.clone(),
291-
top_level_span: sp,
292-
trait_ref: tr,
293-
span: sp,
289+
.map(|(trait_ref, span)| TraitRefExpansionInfo {
290+
top_level_trait_ref: trait_ref.clone(),
291+
top_level_span: span,
292+
trait_ref,
293+
span,
294294
})
295295
.collect();
296296
items.retain(|item| visited.insert(&item.trait_ref.to_predicate()));
297-
TraitRefExpander { stack: items, visited: visited, }
297+
TraitRefExpander { stack: items, visited }
298298
}
299299

300300
impl<'cx, 'gcx, 'tcx> TraitRefExpander<'cx, 'gcx, 'tcx> {
301-
// Returns `true` if `item` refers to a trait.
301+
/// If `item` refers to a trait alias, adds the components of the trait alias to the stack,
302+
/// and returns `false`.
303+
/// If `item` refers to an ordinary trait, simply returns `true`.
302304
fn push(&mut self, item: &TraitRefExpansionInfo<'tcx>) -> bool {
303305
let tcx = self.visited.tcx;
304306

305307
if !tcx.is_trait_alias(item.trait_ref.def_id()) {
306308
return true;
307309
}
308310

309-
// Get predicates declared on the trait.
311+
// Get components of the trait alias.
310312
let predicates = tcx.super_predicates_of(item.trait_ref.def_id());
311313

312314
let mut items: Vec<_> = predicates.predicates
313315
.iter()
314316
.rev()
315-
.filter_map(|(pred, sp)| {
317+
.filter_map(|(pred, span)| {
316318
pred.subst_supertrait(tcx, &item.trait_ref)
317319
.to_opt_poly_trait_ref()
318320
.map(|trait_ref|
319321
TraitRefExpansionInfo {
320322
trait_ref,
321-
span: *sp,
323+
span: *span,
322324
..*item
323325
}
324326
)
325327
})
326328
.collect();
327329

328-
debug!("expand_trait_refs: trait_ref={:?} items={:?}",
329-
item.trait_ref, items);
330+
debug!("trait_ref_expander: trait_ref={:?} items={:?}",
331+
item.trait_ref, items);
330332

331333
// Only keep those items that we haven't already seen.
332334
items.retain(|i| self.visited.insert(&i.trait_ref.to_predicate()));
@@ -344,24 +346,17 @@ impl<'cx, 'gcx, 'tcx> Iterator for TraitRefExpander<'cx, 'gcx, 'tcx> {
344346
}
345347

346348
fn next(&mut self) -> Option<TraitRefExpansionInfo<'tcx>> {
347-
loop {
348-
let item = self.stack.pop();
349-
match item {
350-
Some(item) => {
351-
if self.push(&item) {
352-
return Some(item);
353-
}
354-
}
355-
None => {
356-
return None;
357-
}
349+
while let Some(item) = self.stack.pop() {
350+
if self.push(&item) {
351+
return Some(item);
358352
}
359353
}
354+
None
360355
}
361356
}
362357

363358
///////////////////////////////////////////////////////////////////////////
364-
// Iterator over def-ids of supertraits
359+
// Iterator over def-IDs of supertraits
365360
///////////////////////////////////////////////////////////////////////////
366361

367362
pub struct SupertraitDefIds<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
981981

982982
let mut projection_bounds = Vec::new();
983983
let dummy_self = self.tcx().types.trait_object_dummy_self;
984-
let mut bound_trait_refs = Vec::with_capacity(trait_bounds.len());
985984
let (principal, potential_assoc_types) = self.instantiate_poly_trait_ref(
986985
&trait_bounds[0],
987986
dummy_self,
988987
&mut projection_bounds,
989988
);
990989
debug!("principal: {:?}", principal);
991990

991+
let mut bound_trait_refs = Vec::with_capacity(trait_bounds.len());
992992
for trait_bound in trait_bounds[1..].iter().rev() {
993993
// Sanity check for non-principal trait bounds.
994994
let (tr, _) = self.instantiate_poly_trait_ref(
@@ -1009,7 +1009,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
10091009
"only auto traits can be used as additional traits in a trait object");
10101010
err.span_label(extra_trait.span, "non-auto additional trait");
10111011
if extra_trait.span != extra_trait.top_level_span {
1012-
err.span_label(extra_trait.top_level_span, "expanded from this alias");
1012+
err.span_label(extra_trait.top_level_span, "expanded from this trait alias");
10131013
}
10141014
err.emit();
10151015
}

0 commit comments

Comments
 (0)