rustc_resolve: use Iterator
combinators instead of for
loops where applicable
This commit is contained in:
parent
ae87d005bc
commit
6f22dfe4df
1 changed files with 12 additions and 26 deletions
|
@ -1728,13 +1728,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let normalized_ident = ident.normalize_to_macros_2_0();
|
let normalized_ident = ident.normalize_to_macros_2_0();
|
||||||
let mut outer_res = None;
|
let outer_res = lifetime_rib_iter
|
||||||
for rib in lifetime_rib_iter {
|
.find_map(|rib| rib.bindings.get_key_value(&normalized_ident).map(|(&outer, _)| outer));
|
||||||
if let Some((&outer, _)) = rib.bindings.get_key_value(&normalized_ident) {
|
|
||||||
outer_res = Some(outer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.emit_undeclared_lifetime_error(lifetime, outer_res);
|
self.emit_undeclared_lifetime_error(lifetime, outer_res);
|
||||||
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, LifetimeElisionCandidate::Named);
|
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, LifetimeElisionCandidate::Named);
|
||||||
|
@ -1801,23 +1796,21 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
LifetimeRibKind::AnonymousReportError => {
|
LifetimeRibKind::AnonymousReportError => {
|
||||||
if elided {
|
if elided {
|
||||||
let mut suggestion = None;
|
let suggestion = self.lifetime_ribs[i..].iter().rev().find_map(|rib| {
|
||||||
for rib in self.lifetime_ribs[i..].iter().rev() {
|
|
||||||
if let LifetimeRibKind::Generics {
|
if let LifetimeRibKind::Generics {
|
||||||
span,
|
span,
|
||||||
kind: LifetimeBinderKind::PolyTrait | LifetimeBinderKind::WhereBound,
|
kind: LifetimeBinderKind::PolyTrait | LifetimeBinderKind::WhereBound,
|
||||||
..
|
..
|
||||||
} = &rib.kind
|
} = rib.kind
|
||||||
{
|
{
|
||||||
suggestion =
|
Some(errors::ElidedAnonymousLivetimeReportErrorSuggestion {
|
||||||
Some(errors::ElidedAnonymousLivetimeReportErrorSuggestion {
|
lo: span.shrink_to_lo(),
|
||||||
lo: span.shrink_to_lo(),
|
hi: lifetime.ident.span.shrink_to_hi(),
|
||||||
hi: lifetime.ident.span.shrink_to_hi(),
|
})
|
||||||
});
|
} else {
|
||||||
break;
|
None
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// are we trying to use an anonymous lifetime
|
// are we trying to use an anonymous lifetime
|
||||||
// on a non GAT associated trait type?
|
// on a non GAT associated trait type?
|
||||||
if !self.in_func_body
|
if !self.in_func_body
|
||||||
|
@ -2486,14 +2479,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
/// Determine whether or not a label from the `rib_index`th label rib is reachable.
|
/// Determine whether or not a label from the `rib_index`th label rib is reachable.
|
||||||
fn is_label_valid_from_rib(&self, rib_index: usize) -> bool {
|
fn is_label_valid_from_rib(&self, rib_index: usize) -> bool {
|
||||||
let ribs = &self.label_ribs[rib_index + 1..];
|
let ribs = &self.label_ribs[rib_index + 1..];
|
||||||
|
ribs.iter().all(|rib| !rib.kind.is_label_barrier())
|
||||||
for rib in ribs {
|
|
||||||
if rib.kind.is_label_barrier() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
|
fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue