|
| 1 | +use std::cmp::Reverse; |
| 2 | + |
1 | 3 | use rustc_ast::expand::StrippedCfgItem; |
2 | 4 | use rustc_ast::ptr::P; |
3 | 5 | use rustc_ast::visit::{self, Visitor}; |
@@ -2357,22 +2359,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { |
2357 | 2359 | // 2) `std` suggestions before `core` suggestions. |
2358 | 2360 | let mut extern_crate_names = |
2359 | 2361 | self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>(); |
2360 | | - extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap()); |
2361 | | - |
2362 | | - for name in extern_crate_names.into_iter() { |
2363 | | - // Replace first ident with a crate name and check if that is valid. |
2364 | | - path[0].ident.name = name; |
2365 | | - let result = self.maybe_resolve_path(&path, None, parent_scope, None); |
2366 | | - debug!( |
2367 | | - "make_external_crate_suggestion: name={:?} path={:?} result={:?}", |
2368 | | - name, path, result |
2369 | | - ); |
2370 | | - if let PathResult::Module(..) = result { |
2371 | | - return Some((path, None)); |
2372 | | - } |
2373 | | - } |
2374 | | - |
2375 | | - None |
| 2362 | + extern_crate_names.sort_by_key(|&name| Reverse(name)); |
| 2363 | + |
| 2364 | + extern_crate_names |
| 2365 | + .into_iter() |
| 2366 | + .any(|name| { |
| 2367 | + // Replace first ident with a crate name and check if that is valid. |
| 2368 | + path[0].ident.name = name; |
| 2369 | + let result = self.maybe_resolve_path(&path, None, parent_scope, None); |
| 2370 | + debug!( |
| 2371 | + "make_external_crate_suggestion: name={:?} path={:?} result={:?}", |
| 2372 | + name, path, result |
| 2373 | + ); |
| 2374 | + matches!(result, PathResult::Module(..)) |
| 2375 | + }) |
| 2376 | + .then_some((path, None)) |
2376 | 2377 | } |
2377 | 2378 |
|
2378 | 2379 | /// Suggests importing a macro from the root of the crate rather than a module within |
|
0 commit comments