about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-06-12 23:51:31 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-06-13 20:22:21 +0000
commit5de8e6edfcc747930891a0adc8e90608776dbe54 (patch)
tree770cb18a4f3c28cd3702507d09e2915585f44cc0
parentf1586001ace26df7cafeb6534eaf76fb2c5513e5 (diff)
downloadrust-5de8e6edfcc747930891a0adc8e90608776dbe54.tar.gz
rust-5de8e6edfcc747930891a0adc8e90608776dbe54.zip
Tweak output of import suggestions
When both `std::` and `core::` items are available, only suggest the
`std::` ones. We ensure that in `no_std` crates we suggest `core::`
items.

Ensure that the list of items suggested to be imported are always in the
order of local crate items, `std`/`core` items and finally foreign crate
items.

Tweak wording of import suggestion: if there are multiple items but they
are all of the same kind, we use the kind name and not the generic "items".

Fix #83564.
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs46
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6252.stderr4
-rw-r--r--tests/ui/const-generics/issues/issue-82956.stderr2
-rw-r--r--tests/ui/consts/const_refs_to_static-ice-121413.rs4
-rw-r--r--tests/ui/consts/const_refs_to_static-ice-121413.stderr8
-rw-r--r--tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr2
-rw-r--r--tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr7
-rw-r--r--tests/ui/imports/cycle-import-in-std-1.stderr3
-rw-r--r--tests/ui/imports/cycle-import-in-std-2.stderr3
-rw-r--r--tests/ui/imports/import-alias-issue-121168.edition2018.stderr2
-rw-r--r--tests/ui/imports/import-alias-issue-121168.edition2021.stderr2
-rw-r--r--tests/ui/imports/issue-56125.stderr10
-rw-r--r--tests/ui/lint/use_suggestion_json.stderr4
-rw-r--r--tests/ui/namespace/namespace-mix.stderr8
-rw-r--r--tests/ui/resolve/issue-16058.stderr2
-rw-r--r--tests/ui/resolve/issue-21221-1.stderr12
-rw-r--r--tests/ui/resolve/issue-21221-2.stderr2
-rw-r--r--tests/ui/resolve/issue-50599.stderr2
-rw-r--r--tests/ui/resolve/issue-73427.stderr2
-rw-r--r--tests/ui/resolve/privacy-enum-ctor.stderr4
-rw-r--r--tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr4
-rw-r--r--tests/ui/rust-2018/issue-52202-use-suggestions.stderr2
-rw-r--r--tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed22
-rw-r--r--tests/ui/suggestions/core-std-import-order-issue-83564.no_std.stderr (renamed from tests/ui/suggestions/core-std-import-order-issue-83564.stderr)6
-rw-r--r--tests/ui/suggestions/core-std-import-order-issue-83564.rs12
-rw-r--r--tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed22
-rw-r--r--tests/ui/suggestions/core-std-import-order-issue-83564.std.stderr14
-rw-r--r--tests/ui/suggestions/crate-or-module-typo.stderr4
-rw-r--r--tests/ui/suggestions/suggest-tryinto-edition-change.rs5
-rw-r--r--tests/ui/suggestions/suggest-tryinto-edition-change.stderr19
30 files changed, 159 insertions, 80 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index d1541527cf5..8d470c6c61e 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -2783,33 +2783,65 @@ fn show_candidates(
     // by iterating through a hash map, so make sure they are ordered:
     for path_strings in [&mut accessible_path_strings, &mut inaccessible_path_strings] {
         path_strings.sort_by(|a, b| a.0.cmp(&b.0));
+        path_strings.dedup_by(|a, b| a.0 == b.0);
         let core_path_strings =
             path_strings.extract_if(|p| p.0.starts_with("core::")).collect::<Vec<_>>();
-        path_strings.extend(core_path_strings);
-        path_strings.dedup_by(|a, b| a.0 == b.0);
+        let std_path_strings =
+            path_strings.extract_if(|p| p.0.starts_with("std::")).collect::<Vec<_>>();
+        let foreign_crate_path_strings =
+            path_strings.extract_if(|p| !p.0.starts_with("crate::")).collect::<Vec<_>>();
+
+        // We list the `crate` local paths first.
+        // Then we list the `std`/`core` paths.
+        if std_path_strings.len() == core_path_strings.len() {
+            // Do not list `core::` paths if we are already listing the `std::` ones.
+            path_strings.extend(std_path_strings);
+        } else {
+            path_strings.extend(std_path_strings);
+            path_strings.extend(core_path_strings);
+        }
+        // List all paths from foreign crates last.
+        path_strings.extend(foreign_crate_path_strings);
     }
-    accessible_path_strings.sort();
 
     if !accessible_path_strings.is_empty() {
-        let (determiner, kind, name, through) =
+        let (determiner, kind, s, name, through) =
             if let [(name, descr, _, _, via_import)] = &accessible_path_strings[..] {
                 (
                     "this",
                     *descr,
+                    "",
                     format!(" `{name}`"),
                     if *via_import { " through its public re-export" } else { "" },
                 )
             } else {
-                ("one of these", "items", String::new(), "")
+                // Get the unique item kinds and if there's only one, we use the right kind name
+                // instead of the more generic "items".
+                let mut kinds = accessible_path_strings
+                    .iter()
+                    .map(|(_, descr, _, _, _)| *descr)
+                    .collect::<FxHashSet<&str>>()
+                    .into_iter();
+                let kind = if let Some(kind) = kinds.next()
+                    && let None = kinds.next()
+                {
+                    kind
+                } else {
+                    "item"
+                };
+                let s = if kind.ends_with('s') { "es" } else { "s" };
+
+                ("one of these", kind, s, String::new(), "")
             };
 
         let instead = if let Instead::Yes = instead { " instead" } else { "" };
         let mut msg = if let DiagMode::Pattern = mode {
             format!(
-                "if you meant to match on {kind}{instead}{name}, use the full path in the pattern",
+                "if you meant to match on {kind}{s}{instead}{name}, use the full path in the \
+                 pattern",
             )
         } else {
-            format!("consider importing {determiner} {kind}{through}{instead}")
+            format!("consider importing {determiner} {kind}{s}{through}{instead}")
         };
 
         for note in accessible_path_strings.iter().flat_map(|cand| cand.3.as_ref()) {
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
index ce3b9495eb1..cd2031af1c6 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
@@ -4,9 +4,7 @@ error[E0412]: cannot find type `PhantomData` in this scope
 LL |     _n: PhantomData,
    |         ^^^^^^^^^^^ not found in this scope
    |
-help: consider importing one of these items
-   |
-LL + use core::marker::PhantomData;
+help: consider importing this struct
    |
 LL + use std::marker::PhantomData;
    |
diff --git a/tests/ui/const-generics/issues/issue-82956.stderr b/tests/ui/const-generics/issues/issue-82956.stderr
index d0fc7112426..a956fc741f4 100644
--- a/tests/ui/const-generics/issues/issue-82956.stderr
+++ b/tests/ui/const-generics/issues/issue-82956.stderr
@@ -4,7 +4,7 @@ error[E0433]: failed to resolve: use of undeclared type `IntoIter`
 LL |         let mut iter = IntoIter::new(self);
    |                        ^^^^^^^^ use of undeclared type `IntoIter`
    |
-help: consider importing one of these items
+help: consider importing one of these structs
    |
 LL + use std::array::IntoIter;
    |
diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.rs b/tests/ui/consts/const_refs_to_static-ice-121413.rs
index 8a24fb799b6..8fc3912efd0 100644
--- a/tests/ui/consts/const_refs_to_static-ice-121413.rs
+++ b/tests/ui/consts/const_refs_to_static-ice-121413.rs
@@ -5,12 +5,16 @@
 // ignore-tidy-linelength
 #![feature(const_refs_to_static)]
 const REF_INTERIOR_MUT: &usize = {
+    //~^ HELP consider importing this struct
     static FOO: Sync = AtomicUsize::new(0);
     //~^ ERROR failed to resolve: use of undeclared type `AtomicUsize`
     //~| WARN trait objects without an explicit `dyn` are deprecated
     //~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
     //~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
     //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+    //~| HELP if this is an object-safe trait, use `dyn`
+    //~| HELP the trait `Sized` is not implemented for `(dyn Sync + 'static)`
+    //~| HELP the trait `Sized` is not implemented for `(dyn Sync + 'static)`
     unsafe { &*(&FOO as *const _ as *const usize) }
 };
 pub fn main() {}
diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.stderr b/tests/ui/consts/const_refs_to_static-ice-121413.stderr
index c977c698a92..fbe32a70293 100644
--- a/tests/ui/consts/const_refs_to_static-ice-121413.stderr
+++ b/tests/ui/consts/const_refs_to_static-ice-121413.stderr
@@ -1,5 +1,5 @@
 error[E0433]: failed to resolve: use of undeclared type `AtomicUsize`
-  --> $DIR/const_refs_to_static-ice-121413.rs:8:24
+  --> $DIR/const_refs_to_static-ice-121413.rs:9:24
    |
 LL |     static FOO: Sync = AtomicUsize::new(0);
    |                        ^^^^^^^^^^^ use of undeclared type `AtomicUsize`
@@ -10,7 +10,7 @@ LL + use std::sync::atomic::AtomicUsize;
    |
 
 warning: trait objects without an explicit `dyn` are deprecated
-  --> $DIR/const_refs_to_static-ice-121413.rs:8:17
+  --> $DIR/const_refs_to_static-ice-121413.rs:9:17
    |
 LL |     static FOO: Sync = AtomicUsize::new(0);
    |                 ^^^^
@@ -24,7 +24,7 @@ LL |     static FOO: dyn Sync = AtomicUsize::new(0);
    |                 +++
 
 error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
-  --> $DIR/const_refs_to_static-ice-121413.rs:8:17
+  --> $DIR/const_refs_to_static-ice-121413.rs:9:17
    |
 LL |     static FOO: Sync = AtomicUsize::new(0);
    |                 ^^^^ doesn't have a size known at compile-time
@@ -32,7 +32,7 @@ LL |     static FOO: Sync = AtomicUsize::new(0);
    = help: the trait `Sized` is not implemented for `(dyn Sync + 'static)`
 
 error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
-  --> $DIR/const_refs_to_static-ice-121413.rs:8:24
+  --> $DIR/const_refs_to_static-ice-121413.rs:9:24
    |
 LL |     static FOO: Sync = AtomicUsize::new(0);
    |                        ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
diff --git a/tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr b/tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr
index 5c610f36322..b1a15b8594a 100644
--- a/tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr
+++ b/tests/ui/did_you_mean/issue-56028-there-is-an-enum-variant.stderr
@@ -22,7 +22,7 @@ error[E0425]: cannot find value `Set` in this scope
 LL | fn setup() -> Set { Set }
    |                     ^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these unit variants
    |
 LL + use AffixHeart::Set;
    |
diff --git a/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr b/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr
index 78e6376bca2..cc229764ad3 100644
--- a/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr
+++ b/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr
@@ -24,8 +24,7 @@ LL |         fn f() { my_core::mem::drop(0); }
 LL | a!();
    | ---- in this macro invocation
    |
-   = help: consider importing one of these items:
-           core::mem
+   = help: consider importing this module:
            std::mem
    = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)
 
@@ -35,9 +34,7 @@ error[E0433]: failed to resolve: use of undeclared crate or module `my_core`
 LL |     fn f() { my_core::mem::drop(0); }
    |              ^^^^^^^ use of undeclared crate or module `my_core`
    |
-help: consider importing one of these items
-   |
-LL +     use core::mem;
+help: consider importing this module
    |
 LL +     use std::mem;
    |
diff --git a/tests/ui/imports/cycle-import-in-std-1.stderr b/tests/ui/imports/cycle-import-in-std-1.stderr
index d4e6f32cc10..a7dfc6231ba 100644
--- a/tests/ui/imports/cycle-import-in-std-1.stderr
+++ b/tests/ui/imports/cycle-import-in-std-1.stderr
@@ -4,8 +4,7 @@ error[E0432]: unresolved import `ops`
 LL | use ops::{self as std};
    |           ^^^^^^^^^^^ no external crate `ops`
    |
-   = help: consider importing one of these items instead:
-           core::ops
+   = help: consider importing this module instead:
            std::ops
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/imports/cycle-import-in-std-2.stderr b/tests/ui/imports/cycle-import-in-std-2.stderr
index dc0270dffe4..8d94693cd51 100644
--- a/tests/ui/imports/cycle-import-in-std-2.stderr
+++ b/tests/ui/imports/cycle-import-in-std-2.stderr
@@ -4,8 +4,7 @@ error[E0432]: unresolved import `ops`
 LL | use ops::{self as std};
    |           ^^^^^^^^^^^ no external crate `ops`
    |
-   = help: consider importing one of these items instead:
-           core::ops
+   = help: consider importing this module instead:
            std::ops
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/imports/import-alias-issue-121168.edition2018.stderr b/tests/ui/imports/import-alias-issue-121168.edition2018.stderr
index b61a0e3edd5..e14e700c33d 100644
--- a/tests/ui/imports/import-alias-issue-121168.edition2018.stderr
+++ b/tests/ui/imports/import-alias-issue-121168.edition2018.stderr
@@ -4,7 +4,7 @@ error[E0412]: cannot find type `Foo` in this scope
 LL |     let _: Foo<i32> = todo!();
    |            ^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these structs
    |
 LL + use crate::nice_crate_name::Foo;
    |
diff --git a/tests/ui/imports/import-alias-issue-121168.edition2021.stderr b/tests/ui/imports/import-alias-issue-121168.edition2021.stderr
index b61a0e3edd5..e14e700c33d 100644
--- a/tests/ui/imports/import-alias-issue-121168.edition2021.stderr
+++ b/tests/ui/imports/import-alias-issue-121168.edition2021.stderr
@@ -4,7 +4,7 @@ error[E0412]: cannot find type `Foo` in this scope
 LL |     let _: Foo<i32> = todo!();
    |            ^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these structs
    |
 LL + use crate::nice_crate_name::Foo;
    |
diff --git a/tests/ui/imports/issue-56125.stderr b/tests/ui/imports/issue-56125.stderr
index d2a0f436c42..0c4a569c7ea 100644
--- a/tests/ui/imports/issue-56125.stderr
+++ b/tests/ui/imports/issue-56125.stderr
@@ -4,16 +4,16 @@ error[E0432]: unresolved import `empty::issue_56125`
 LL |     use empty::issue_56125;
    |         ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
    |
-help: consider importing one of these items instead
+help: consider importing one of these modules instead
    |
+LL |     use crate::m3::last_segment::issue_56125;
+   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LL |     use crate::m3::non_last_segment::non_last_segment::issue_56125;
+   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 LL |     use ::issue_56125::issue_56125;
    |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
 LL |     use ::issue_56125::last_segment::issue_56125;
    |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-LL |     use ::issue_56125::non_last_segment::non_last_segment::issue_56125;
-   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-LL |     use crate::m3::last_segment::issue_56125;
-   |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      and 1 other candidate
 
 error[E0659]: `issue_56125` is ambiguous
diff --git a/tests/ui/lint/use_suggestion_json.stderr b/tests/ui/lint/use_suggestion_json.stderr
index acc36550642..4683e5dd8f3 100644
--- a/tests/ui/lint/use_suggestion_json.stderr
+++ b/tests/ui/lint/use_suggestion_json.stderr
@@ -95,7 +95,7 @@ mod foo {
   ],
   "children": [
     {
-      "message": "consider importing one of these items",
+      "message": "consider importing one of these structs",
       "code": null,
       "level": "help",
       "spans": [
@@ -386,7 +386,7 @@ mod foo {
 \u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m    let x: Iter;\u001b[0m
 \u001b[0m   \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m            \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9mnot found in this scope\u001b[0m
 \u001b[0m   \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
-\u001b[0m\u001b[1m\u001b[38;5;14mhelp\u001b[0m\u001b[0m: consider importing one of these items\u001b[0m
+\u001b[0m\u001b[1m\u001b[38;5;14mhelp\u001b[0m\u001b[0m: consider importing one of these structs\u001b[0m
 \u001b[0m   \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
 \u001b[0m\u001b[1m\u001b[38;5;12mLL\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[38;5;10m+ use std::collections::binary_heap::Iter;\u001b[0m
 \u001b[0m   \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m
diff --git a/tests/ui/namespace/namespace-mix.stderr b/tests/ui/namespace/namespace-mix.stderr
index 4eff08ead42..b80363fe8f8 100644
--- a/tests/ui/namespace/namespace-mix.stderr
+++ b/tests/ui/namespace/namespace-mix.stderr
@@ -12,7 +12,7 @@ help: a tuple struct with a similar name exists
    |
 LL |     check(m1::TS);
    |               ~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use m2::S;
    |
@@ -40,7 +40,7 @@ help: a tuple struct with a similar name exists
    |
 LL |     check(xm1::TS);
    |                ~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use m2::S;
    |
@@ -66,7 +66,7 @@ help: a tuple variant with a similar name exists
    |
 LL |     check(m7::TV);
    |               ~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use m8::V;
    |
@@ -94,7 +94,7 @@ help: a tuple variant with a similar name exists
    |
 LL |     check(xm7::TV);
    |                ~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use m8::V;
    |
diff --git a/tests/ui/resolve/issue-16058.stderr b/tests/ui/resolve/issue-16058.stderr
index 914990c35ff..12b1ac8a5fb 100644
--- a/tests/ui/resolve/issue-16058.stderr
+++ b/tests/ui/resolve/issue-16058.stderr
@@ -4,7 +4,7 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
 LL |         Result {
    |         ^^^^^^ not a struct, variant or union type
    |
-help: consider importing one of these items instead
+help: consider importing one of these type aliases instead
    |
 LL + use std::fmt::Result;
    |
diff --git a/tests/ui/resolve/issue-21221-1.stderr b/tests/ui/resolve/issue-21221-1.stderr
index a38116cd728..ccf03afaa19 100644
--- a/tests/ui/resolve/issue-21221-1.stderr
+++ b/tests/ui/resolve/issue-21221-1.stderr
@@ -4,14 +4,14 @@ error[E0405]: cannot find trait `Mul` in this scope
 LL | impl Mul for Foo {
    |      ^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these traits
+   |
+LL + use std::ops::Mul;
    |
 LL + use mul1::Mul;
    |
 LL + use mul2::Mul;
    |
-LL + use std::ops::Mul;
-   |
 
 error[E0412]: cannot find type `Mul` in this scope
   --> $DIR/issue-21221-1.rs:58:16
@@ -19,14 +19,14 @@ error[E0412]: cannot find type `Mul` in this scope
 LL | fn getMul() -> Mul {
    |                ^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these traits
+   |
+LL + use std::ops::Mul;
    |
 LL + use mul1::Mul;
    |
 LL + use mul2::Mul;
    |
-LL + use std::ops::Mul;
-   |
 
 error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
   --> $DIR/issue-21221-1.rs:63:6
diff --git a/tests/ui/resolve/issue-21221-2.stderr b/tests/ui/resolve/issue-21221-2.stderr
index 3bd4c1a5d13..5db327955eb 100644
--- a/tests/ui/resolve/issue-21221-2.stderr
+++ b/tests/ui/resolve/issue-21221-2.stderr
@@ -4,7 +4,7 @@ error[E0405]: cannot find trait `T` in this scope
 LL | impl T for Foo { }
    |      ^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these traits
    |
 LL + use baz::T;
    |
diff --git a/tests/ui/resolve/issue-50599.stderr b/tests/ui/resolve/issue-50599.stderr
index e5eacd741fb..24fb3d580b8 100644
--- a/tests/ui/resolve/issue-50599.stderr
+++ b/tests/ui/resolve/issue-50599.stderr
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `LOG10_2` in module `std::f64`
 LL |     const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize;
    |                                                ^^^^^^^ not found in `std::f64`
    |
-help: consider importing one of these items
+help: consider importing one of these constants
    |
 LL + use std::f128::consts::LOG10_2;
    |
diff --git a/tests/ui/resolve/issue-73427.stderr b/tests/ui/resolve/issue-73427.stderr
index c5e245d884b..0a9a504f79c 100644
--- a/tests/ui/resolve/issue-73427.stderr
+++ b/tests/ui/resolve/issue-73427.stderr
@@ -105,7 +105,7 @@ help: the following enum variant is available
    |
 LL |     (E::TupleWithFields(/* fields */)).foo();
    |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use std::f128::consts::E;
    |
diff --git a/tests/ui/resolve/privacy-enum-ctor.stderr b/tests/ui/resolve/privacy-enum-ctor.stderr
index 01c8a38d2a4..ee3aecddcc3 100644
--- a/tests/ui/resolve/privacy-enum-ctor.stderr
+++ b/tests/ui/resolve/privacy-enum-ctor.stderr
@@ -82,7 +82,7 @@ help: a function with a similar name exists
    |
 LL |     let _: E = m::f;
    |                   ~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use std::f128::consts::E;
    |
@@ -123,7 +123,7 @@ help: alternatively, the following enum variant is available
    |
 LL |     let _: E = (E::Fn(/* fields */));
    |                ~~~~~~~~~~~~~~~~~~~~~
-help: consider importing one of these items instead
+help: consider importing one of these constants instead
    |
 LL + use std::f128::consts::E;
    |
diff --git a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr
index 7f989c15f1c..d0c084f7bd5 100644
--- a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr
+++ b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr
@@ -4,10 +4,8 @@ error[E0432]: unresolved import `alloc`
 LL | use alloc;
    |     ^^^^^ no external crate `alloc`
    |
-help: consider importing one of these items instead
+help: consider importing this module instead
    |
-LL | use core::alloc;
-   |     ~~~~~~~~~~~
 LL | use std::alloc;
    |     ~~~~~~~~~~
 
diff --git a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
index 49736205f20..ee1a336ea98 100644
--- a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
+++ b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
@@ -4,7 +4,7 @@ error[E0422]: cannot find struct, variant or union type `Drain` in this scope
 LL |     let _d = Drain {};
    |              ^^^^^ not found in this scope
    |
-help: consider importing one of these items
+help: consider importing one of these structs
    |
 LL + use crate::plumbing::Drain;
    |
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed
new file mode 100644
index 00000000000..02d667d9844
--- /dev/null
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed
@@ -0,0 +1,22 @@
+//@ edition:2018
+//
+// This is a regression test for #83564.
+// For some reason, Rust 2018 or higher is required to reproduce the bug.
+//@ run-rustfix
+//@ revisions: no_std std
+//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
+#![cfg_attr(no_std, no_std)]
+
+use core::num::NonZero;
+
+fn main() {
+    //~^ HELP consider importing this struct
+    let _x = NonZero::new(5u32).unwrap();
+    //~^ ERROR failed to resolve: use of undeclared type `NonZero`
+}
+
+#[allow(dead_code)]
+#[cfg_attr(no_std, panic_handler)]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+    loop {}
+}
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.stderr
index 8665cc6d87c..d73f613bf9c 100644
--- a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.stderr
@@ -1,15 +1,13 @@
 error[E0433]: failed to resolve: use of undeclared type `NonZero`
-  --> $DIR/core-std-import-order-issue-83564.rs:8:14
+  --> $DIR/core-std-import-order-issue-83564.rs:12:14
    |
 LL |     let _x = NonZero::new(5u32).unwrap();
    |              ^^^^^^^ use of undeclared type `NonZero`
    |
-help: consider importing one of these items
+help: consider importing this struct
    |
 LL + use core::num::NonZero;
    |
-LL + use std::num::NonZero;
-   |
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.rs b/tests/ui/suggestions/core-std-import-order-issue-83564.rs
index 6f2bdd7a38a..5bb5bfe176b 100644
--- a/tests/ui/suggestions/core-std-import-order-issue-83564.rs
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.rs
@@ -2,9 +2,19 @@
 //
 // This is a regression test for #83564.
 // For some reason, Rust 2018 or higher is required to reproduce the bug.
+//@ run-rustfix
+//@ revisions: no_std std
+//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
+#![cfg_attr(no_std, no_std)]
 
 fn main() {
-    //~^ HELP consider importing one of these items
+    //~^ HELP consider importing this struct
     let _x = NonZero::new(5u32).unwrap();
     //~^ ERROR failed to resolve: use of undeclared type `NonZero`
 }
+
+#[allow(dead_code)]
+#[cfg_attr(no_std, panic_handler)]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+    loop {}
+}
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed b/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed
new file mode 100644
index 00000000000..3492b42c685
--- /dev/null
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed
@@ -0,0 +1,22 @@
+//@ edition:2018
+//
+// This is a regression test for #83564.
+// For some reason, Rust 2018 or higher is required to reproduce the bug.
+//@ run-rustfix
+//@ revisions: no_std std
+//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
+#![cfg_attr(no_std, no_std)]
+
+use std::num::NonZero;
+
+fn main() {
+    //~^ HELP consider importing this struct
+    let _x = NonZero::new(5u32).unwrap();
+    //~^ ERROR failed to resolve: use of undeclared type `NonZero`
+}
+
+#[allow(dead_code)]
+#[cfg_attr(no_std, panic_handler)]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+    loop {}
+}
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.std.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.std.stderr
new file mode 100644
index 00000000000..ebfe197b45d
--- /dev/null
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.std.stderr
@@ -0,0 +1,14 @@
+error[E0433]: failed to resolve: use of undeclared type `NonZero`
+  --> $DIR/core-std-import-order-issue-83564.rs:12:14
+   |
+LL |     let _x = NonZero::new(5u32).unwrap();
+   |              ^^^^^^^ use of undeclared type `NonZero`
+   |
+help: consider importing this struct
+   |
+LL + use std::num::NonZero;
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0433`.
diff --git a/tests/ui/suggestions/crate-or-module-typo.stderr b/tests/ui/suggestions/crate-or-module-typo.stderr
index 457d7790646..084d0408a8e 100644
--- a/tests/ui/suggestions/crate-or-module-typo.stderr
+++ b/tests/ui/suggestions/crate-or-module-typo.stderr
@@ -30,9 +30,7 @@ help: there is a crate or module with a similar name
    |
 LL |     bar: std::cell::Cell<bool>
    |          ~~~
-help: consider importing one of these items
-   |
-LL + use core::cell;
+help: consider importing this module
    |
 LL + use std::cell;
    |
diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.rs b/tests/ui/suggestions/suggest-tryinto-edition-change.rs
index 37321774874..f45670ae7c1 100644
--- a/tests/ui/suggestions/suggest-tryinto-edition-change.rs
+++ b/tests/ui/suggestions/suggest-tryinto-edition-change.rs
@@ -1,5 +1,5 @@
 // Make sure that trying to access `TryInto`, `TryFrom`, `FromIterator` in pre-2021 mentions
-// Edition 2021 change
+// Edition 2021 change.
 //@ edition:2018
 
 fn test() {
@@ -11,19 +11,16 @@ fn test() {
     //~^ ERROR failed to resolve: use of undeclared type
     //~| NOTE use of undeclared type
     //~| NOTE 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
-    //~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
 
     let _i: i16 = TryInto::try_into(0_i32).unwrap();
     //~^ ERROR failed to resolve: use of undeclared type
     //~| NOTE use of undeclared type
     //~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021
-    //~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021
 
     let _v: Vec<_> = FromIterator::from_iter(&[1]);
     //~^ ERROR failed to resolve: use of undeclared type
     //~| NOTE use of undeclared type
     //~| NOTE 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
-    //~| NOTE 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
 }
 
 fn main() {
diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
index db7c40101cd..5be55f75cd1 100644
--- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
+++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
@@ -4,45 +4,36 @@ error[E0433]: failed to resolve: use of undeclared type `TryFrom`
 LL |     let _i: i16 = TryFrom::try_from(0_i32).unwrap();
    |                   ^^^^^^^ use of undeclared type `TryFrom`
    |
-   = note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
    = note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
-help: consider importing one of these items
-   |
-LL + use core::convert::TryFrom;
+help: consider importing this trait
    |
 LL + use std::convert::TryFrom;
    |
 
 error[E0433]: failed to resolve: use of undeclared type `TryInto`
-  --> $DIR/suggest-tryinto-edition-change.rs:16:19
+  --> $DIR/suggest-tryinto-edition-change.rs:15:19
    |
 LL |     let _i: i16 = TryInto::try_into(0_i32).unwrap();
    |                   ^^^^^^^ use of undeclared type `TryInto`
    |
-   = note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
    = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
-help: consider importing one of these items
-   |
-LL + use core::convert::TryInto;
+help: consider importing this trait
    |
 LL + use std::convert::TryInto;
    |
 
 error[E0433]: failed to resolve: use of undeclared type `FromIterator`
-  --> $DIR/suggest-tryinto-edition-change.rs:22:22
+  --> $DIR/suggest-tryinto-edition-change.rs:20:22
    |
 LL |     let _v: Vec<_> = FromIterator::from_iter(&[1]);
    |                      ^^^^^^^^^^^^ use of undeclared type `FromIterator`
    |
-   = note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
    = note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
 help: a trait with a similar name exists
    |
 LL |     let _v: Vec<_> = IntoIterator::from_iter(&[1]);
    |                      ~~~~~~~~~~~~
-help: consider importing one of these items
-   |
-LL + use core::iter::FromIterator;
+help: consider importing this trait
    |
 LL + use std::iter::FromIterator;
    |