Skip to content

Commit 8bf43d9

Browse files
committed
rustc_resolve: use Iterator::find instead of for loop
1 parent 5fd5f36 commit 8bf43d9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::cmp::Reverse;
1+
use std::cmp;
22

33
use rustc_ast::expand::StrippedCfgItem;
44
use rustc_ast::ptr::P;
@@ -3082,20 +3082,21 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
30823082
}
30833083

30843084
fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
3085-
for item in items {
3086-
if let ItemKind::Use(..) = item.kind
3087-
&& is_span_suitable_for_use_injection(item.span)
3088-
{
3089-
let mut lo = item.span.lo();
3090-
for attr in &item.attrs {
3091-
if attr.span.eq_ctxt(item.span) {
3092-
lo = std::cmp::min(lo, attr.span.lo());
3093-
}
3094-
}
3095-
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
3096-
}
3097-
}
3098-
None
3085+
items
3086+
.iter()
3087+
.find(|item| {
3088+
matches!(item.kind, ItemKind::Use(..)) && is_span_suitable_for_use_injection(item.span)
3089+
})
3090+
.map(|item| {
3091+
let lo = item
3092+
.attrs
3093+
.iter()
3094+
.filter(|attr| attr.span.eq_ctxt(item.span))
3095+
.map(|attr| attr.span.lo())
3096+
.fold(item.span.lo(), cmp::min);
3097+
3098+
Span::new(lo, lo, item.span.ctxt(), item.span.parent())
3099+
})
30993100
}
31003101

31013102
fn is_span_suitable_for_use_injection(s: Span) -> bool {

0 commit comments

Comments
 (0)