From 353d6373ff77853f3399dde04e35ef4e86b8ca00 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 25 Sep 2021 00:22:59 +0900 Subject: [PATCH 1/2] change the order of path suggestions --- compiler/rustc_resolve/src/diagnostics.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 0b1687d1bd8c3..7e79de102ae2d 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1707,6 +1707,12 @@ crate fn show_candidates( candidates.iter().map(|c| path_names_to_string(&c.path)).collect(); path_strings.sort(); + let core_path_strings = + path_strings.iter().filter(|p| p.starts_with("core::")).cloned().collect::>(); + if !core_path_strings.is_empty() { + path_strings.retain(|p| !p.starts_with("core::")); + } + path_strings.extend(core_path_strings); path_strings.dedup(); let (determiner, kind) = if candidates.len() == 1 { From 4c239055151ca2717c1d76fc84e0825487cd807c Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 25 Sep 2021 11:33:53 +0900 Subject: [PATCH 2/2] use `drain_filter` instead of `filter` and `retain` --- compiler/rustc_resolve/src/diagnostics.rs | 5 +---- compiler/rustc_resolve/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 7e79de102ae2d..937319df18a4f 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1708,10 +1708,7 @@ crate fn show_candidates( path_strings.sort(); let core_path_strings = - path_strings.iter().filter(|p| p.starts_with("core::")).cloned().collect::>(); - if !core_path_strings.is_empty() { - path_strings.retain(|p| !p.starts_with("core::")); - } + path_strings.drain_filter(|p| p.starts_with("core::")).collect::>(); path_strings.extend(core_path_strings); path_strings.dedup(); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index d76ba80e42eab..a9609f188bcc9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -10,6 +10,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(box_patterns)] +#![feature(drain_filter)] #![feature(bool_to_option)] #![feature(crate_visibility_modifier)] #![feature(format_args_capture)]