Skip to content

Commit

Permalink
use Reverse instead of manually doing reverse comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamofek committed Jan 18, 2025
1 parent 8e59cf9 commit 37a3346
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp::Reverse;

use rustc_ast::expand::StrippedCfgItem;
use rustc_ast::ptr::P;
use rustc_ast::visit::{self, Visitor};
Expand Down Expand Up @@ -2357,22 +2359,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// 2) `std` suggestions before `core` suggestions.
let mut extern_crate_names =
self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>();
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());

for name in extern_crate_names.into_iter() {
// Replace first ident with a crate name and check if that is valid.
path[0].ident.name = name;
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!(
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
name, path, result
);
if let PathResult::Module(..) = result {
return Some((path, None));
}
}

None
extern_crate_names.sort_by_key(|&name| Reverse(name));

extern_crate_names
.into_iter()
.any(|name| {
// Replace first ident with a crate name and check if that is valid.
path[0].ident.name = name;
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!(
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
name, path, result
);
matches!(result, PathResult::Module(..))
})
.then_some((path, None))
}

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

0 comments on commit 37a3346

Please sign in to comment.