Skip to content

Commit 37a3346

Browse files
committed
use Reverse instead of manually doing reverse comparison
1 parent 8e59cf9 commit 37a3346

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::cmp::Reverse;
2+
13
use rustc_ast::expand::StrippedCfgItem;
24
use rustc_ast::ptr::P;
35
use rustc_ast::visit::{self, Visitor};
@@ -2357,22 +2359,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23572359
// 2) `std` suggestions before `core` suggestions.
23582360
let mut extern_crate_names =
23592361
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))
23762377
}
23772378

23782379
/// Suggests importing a macro from the root of the crate rather than a module within

0 commit comments

Comments
 (0)