Skip to content

Commit 2718a9a

Browse files
committed
rustc_resolve: use Iterator::find instead of for loop
1 parent 6a64e3b commit 2718a9a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::cmp;
2+
13
use rustc_ast::expand::StrippedCfgItem;
24
use rustc_ast::ptr::P;
35
use rustc_ast::visit::{self, Visitor};
@@ -3074,20 +3076,21 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
30743076
}
30753077

30763078
fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
3077-
for item in items {
3078-
if let ItemKind::Use(..) = item.kind {
3079-
if is_span_suitable_for_use_injection(item.span) {
3080-
let mut lo = item.span.lo();
3081-
for attr in &item.attrs {
3082-
if attr.span.eq_ctxt(item.span) {
3083-
lo = std::cmp::min(lo, attr.span.lo());
3084-
}
3085-
}
3086-
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
3087-
}
3088-
}
3089-
}
3090-
None
3079+
items
3080+
.iter()
3081+
.find(|item| {
3082+
matches!(item.kind, ItemKind::Use(..)) && is_span_suitable_for_use_injection(item.span)
3083+
})
3084+
.map(|item| {
3085+
let lo = item
3086+
.attrs
3087+
.iter()
3088+
.filter(|attr| attr.span.eq_ctxt(item.span))
3089+
.map(|attr| attr.span.lo())
3090+
.fold(item.span.lo(), cmp::min);
3091+
3092+
Span::new(lo, lo, item.span.ctxt(), item.span.parent())
3093+
})
30913094
}
30923095

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

0 commit comments

Comments
 (0)