Skip to content

Commit bc15855

Browse files
committed
Merge branch 'resolve-cleanups3' into misc-cleanups
2 parents 5fd5f36 + 38169d6 commit bc15855

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+25-20
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;
@@ -1309,12 +1309,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13091309
let is_extern_crate_that_also_appears_in_prelude =
13101310
name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();
13111311

1312-
if !is_extern_crate_that_also_appears_in_prelude || alias_import {
1312+
if (!is_extern_crate_that_also_appears_in_prelude || alias_import)
13131313
// add the module to the lookup
1314-
if seen_modules.insert(module.def_id()) {
1315-
if via_import { &mut worklist_via_import } else { &mut worklist }
1316-
.push((module, path_segments, child_accessible, child_doc_visible));
1317-
}
1314+
&& seen_modules.insert(module.def_id())
1315+
{
1316+
if via_import { &mut worklist_via_import } else { &mut worklist }.push((
1317+
module,
1318+
path_segments,
1319+
child_accessible,
1320+
child_doc_visible,
1321+
));
13181322
}
13191323
}
13201324
})
@@ -3082,20 +3086,21 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
30823086
}
30833087

30843088
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
3089+
items
3090+
.iter()
3091+
.find(|item| {
3092+
matches!(item.kind, ItemKind::Use(..)) && is_span_suitable_for_use_injection(item.span)
3093+
})
3094+
.map(|item| {
3095+
let lo = item
3096+
.attrs
3097+
.iter()
3098+
.filter(|attr| attr.span.eq_ctxt(item.span))
3099+
.map(|attr| attr.span.lo())
3100+
.fold(item.span.lo(), cmp::min);
3101+
3102+
Span::new(lo, lo, item.span.ctxt(), item.span.parent())
3103+
})
30993104
}
31003105

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

0 commit comments

Comments
 (0)