Skip to content

Commit 9d99f9c

Browse files
authored
Rollup merge of #135677 - yotamofek:resolve-cleanups2, r=compiler-errors
Small `rustc_resolve` cleanups 1. Don't open-code `Reverse` 2. Use slice patterns where possible
2 parents 7c3e804 + a909520 commit 9d99f9c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+6-4
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};
@@ -2243,13 +2245,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22432245
) -> Option<(Vec<Segment>, Option<String>)> {
22442246
debug!("make_path_suggestion: span={:?} path={:?}", span, path);
22452247

2246-
match (path.get(0), path.get(1)) {
2248+
match path[..] {
22472249
// `{{root}}::ident::...` on both editions.
22482250
// On 2015 `{{root}}` is usually added implicitly.
2249-
(Some(fst), Some(snd))
2251+
[fst, snd, ..]
22502252
if fst.ident.name == kw::PathRoot && !snd.ident.is_path_segment_keyword() => {}
22512253
// `ident::...` on 2018.
2252-
(Some(fst), _)
2254+
[fst, ..]
22532255
if fst.ident.span.at_least_rust_2018() && !fst.ident.is_path_segment_keyword() =>
22542256
{
22552257
// Insert a placeholder that's later replaced by `self`/`super`/etc.
@@ -2357,7 +2359,7 @@ 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());
2362+
extern_crate_names.sort_by_key(|&name| Reverse(name));
23612363

23622364
for name in extern_crate_names.into_iter() {
23632365
// Replace first ident with a crate name and check if that is valid.

0 commit comments

Comments
 (0)