|
1 |
| -use std::cmp::Reverse; |
| 1 | +use std::cmp; |
2 | 2 |
|
3 | 3 | use rustc_ast::expand::StrippedCfgItem;
|
4 | 4 | use rustc_ast::ptr::P;
|
@@ -1309,12 +1309,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
1309 | 1309 | let is_extern_crate_that_also_appears_in_prelude =
|
1310 | 1310 | name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();
|
1311 | 1311 |
|
1312 |
| - if !is_extern_crate_that_also_appears_in_prelude || alias_import { |
| 1312 | + if (!is_extern_crate_that_also_appears_in_prelude || alias_import) |
1313 | 1313 | // 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 | + )); |
1318 | 1322 | }
|
1319 | 1323 | }
|
1320 | 1324 | })
|
@@ -3082,20 +3086,21 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
|
3082 | 3086 | }
|
3083 | 3087 |
|
3084 | 3088 | 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 | + }) |
3099 | 3104 | }
|
3100 | 3105 |
|
3101 | 3106 | fn is_span_suitable_for_use_injection(s: Span) -> bool {
|
|
0 commit comments