From 5b40aa5eb484b31c9a82c1b1a0f414840477b9ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Esteban=20K=C3=BCber?= <esteban@kuber.com.ar>
Date: Sat, 18 Mar 2023 02:18:39 +0000
Subject: [PATCH 1/2] Tweak output for 'add line' suggestion

---
 compiler/rustc_errors/src/emitter.rs          | 41 ++++++++++++++++-
 .../clippy/tests/ui/crashes/ice-6252.stderr   |  9 ++--
 .../clippy/tests/ui/derivable_impls.stderr    | 24 ++++++----
 .../tests/ui/new_without_default.stderr       |  6 +++
 .../ui/array-slice-vec/repeat_empty_ok.stderr |  6 ++-
 .../defaults-suitability.stderr               |  6 ++-
 tests/ui/binop/issue-28837.stderr             | 18 +++++---
 tests/ui/box/unit/unique-pinned-nocopy.stderr |  3 +-
 tests/ui/coherence/coherence_inherent.stderr  |  3 +-
 .../ui/coherence/coherence_inherent_cc.stderr |  3 +-
 .../generic_const_exprs/issue-94287.stderr    |  1 +
 .../const-generics/issues/issue-82956.stderr  | 12 +++--
 .../const-blocks/fn-call-in-non-const.stderr  |  3 +-
 .../consts/const-blocks/migrate-fail.stderr   |  6 ++-
 tests/ui/consts/const-blocks/nll-fail.stderr  |  6 ++-
 .../min_const_fn_libstd_stability.stderr      |  6 ++-
 ...in_const_unsafe_fn_libstd_stability.stderr |  6 ++-
 tests/ui/derived-errors/issue-31997-1.stderr  |  3 +-
 .../derives/derive-assoc-type-not-impl.stderr |  3 +-
 ...ives-span-Clone-enum-struct-variant.stderr |  3 +-
 .../ui/derives/derives-span-Clone-enum.stderr |  3 +-
 .../derives/derives-span-Clone-struct.stderr  |  3 +-
 .../derives-span-Clone-tuple-struct.stderr    |  3 +-
 ...ives-span-Debug-enum-struct-variant.stderr |  3 +-
 .../ui/derives/derives-span-Debug-enum.stderr |  3 +-
 .../derives/derives-span-Debug-struct.stderr  |  3 +-
 .../derives-span-Debug-tuple-struct.stderr    |  3 +-
 .../derives-span-Default-struct.stderr        |  3 +-
 .../derives-span-Default-tuple-struct.stderr  |  3 +-
 ...derives-span-Eq-enum-struct-variant.stderr |  3 +-
 tests/ui/derives/derives-span-Eq-enum.stderr  |  3 +-
 .../ui/derives/derives-span-Eq-struct.stderr  |  3 +-
 .../derives-span-Eq-tuple-struct.stderr       |  3 +-
 ...rives-span-Hash-enum-struct-variant.stderr |  3 +-
 .../ui/derives/derives-span-Hash-enum.stderr  |  3 +-
 .../derives/derives-span-Hash-struct.stderr   |  3 +-
 .../derives-span-Hash-tuple-struct.stderr     |  3 +-
 ...erives-span-Ord-enum-struct-variant.stderr |  3 +-
 tests/ui/derives/derives-span-Ord-enum.stderr |  3 +-
 .../ui/derives/derives-span-Ord-struct.stderr |  3 +-
 .../derives-span-Ord-tuple-struct.stderr      |  3 +-
 ...-span-PartialEq-enum-struct-variant.stderr |  3 +-
 .../derives-span-PartialEq-enum.stderr        |  3 +-
 .../derives-span-PartialEq-struct.stderr      |  3 +-
 ...derives-span-PartialEq-tuple-struct.stderr |  3 +-
 ...span-PartialOrd-enum-struct-variant.stderr |  3 +-
 .../derives-span-PartialOrd-enum.stderr       |  3 +-
 .../derives-span-PartialOrd-struct.stderr     |  3 +-
 ...erives-span-PartialOrd-tuple-struct.stderr |  3 +-
 ...eriving-no-inner-impl-error-message.stderr |  6 ++-
 .../deriving-with-repr-packed-2.stderr        |  3 +-
 tests/ui/derives/issue-91492.stderr           |  9 ++--
 tests/ui/derives/issue-91550.stderr           | 12 +++--
 ...ssue-56028-there-is-an-enum-variant.stderr | 12 +++--
 tests/ui/error-codes/E0277-3.stderr           |  3 +-
 tests/ui/fmt/format-args-argument-span.stderr |  6 ++-
 tests/ui/generator/clone-impl.stderr          |  6 ++-
 ...issue-87429-associated-type-default.stderr |  3 +-
 .../issue-87429-specialization.stderr         |  3 +-
 tests/ui/hygiene/globs.stderr                 |  6 ++-
 tests/ui/hygiene/no_implicit_prelude.stderr   |  6 ++-
 tests/ui/hygiene/trait_items.stderr           |  3 +-
 .../no-method-suggested-traits.stderr         | 36 ++++++++++-----
 .../impl-trait/universal_wrong_bounds.stderr  |  6 ++-
 tests/ui/imports/glob-resolve1.stderr         |  3 +-
 tests/ui/imports/issue-38293.stderr           |  3 +-
 tests/ui/imports/issue-4366-2.stderr          |  3 +-
 tests/ui/imports/issue-4366.stderr            |  3 +-
 tests/ui/imports/overlapping_pub_trait.stderr |  3 +-
 tests/ui/imports/unnamed_pub_trait.stderr     |  3 +-
 .../internal/internal-unstable-const.stderr   |  6 ++-
 tests/ui/issues/issue-10465.stderr            |  3 +-
 tests/ui/issues/issue-17546.stderr            | 24 ++++++----
 tests/ui/issues/issue-20162.stderr            |  3 +-
 tests/ui/issues/issue-21160.stderr            |  3 +-
 tests/ui/issues/issue-35976.unimported.stderr |  3 +-
 tests/ui/issues/issue-37534.stderr            |  3 +-
 tests/ui/issues/issue-39175.stderr            |  3 +-
 tests/ui/issues/issue-56175.stderr            |  6 ++-
 tests/ui/issues/issue-62375.stderr            |  3 +-
 tests/ui/issues/issue-77919.stderr            |  3 +-
 .../ui/kindck/kindck-impl-type-params.stderr  |  3 +-
 tests/ui/layout/issue-84108.stderr            |  6 ++-
 tests/ui/macros/issue-100199.stderr           |  3 +-
 tests/ui/macros/macro-outer-attributes.stderr |  3 +-
 .../malformed/malformed-derive-entry.stderr   |  6 ++-
 .../method-help-unsatisfied-bound.stderr      |  3 +-
 tests/ui/modules/issue-107649.stderr          |  3 +-
 tests/ui/namespace/namespace-mix.stderr       | 24 ++++++----
 tests/ui/not-clone-closure.stderr             |  3 +-
 tests/ui/on-unimplemented/no-debug.stderr     |  3 +-
 tests/ui/parser/circular_modules_main.stderr  |  3 +-
 tests/ui/privacy/privacy-ns1.stderr           |  9 ++--
 tests/ui/privacy/privacy-ns2.stderr           |  9 ++--
 tests/ui/proc-macro/amputate-span.stderr      |  6 ++-
 .../attributes-on-modules-fail.stderr         |  6 ++-
 .../repeat-to-run-dtor-twice.stderr           |  3 +-
 tests/ui/resolve/crate-in-paths.stderr        |  3 +-
 .../ui/resolve/enums-are-namespaced-xc.stderr |  9 ++--
 tests/ui/resolve/filter-intrinsics.stderr     |  6 ++-
 tests/ui/resolve/issue-102946.stderr          |  3 +-
 tests/ui/resolve/issue-16058.stderr           |  9 ++--
 tests/ui/resolve/issue-17518.stderr           |  3 +-
 tests/ui/resolve/issue-21221-1.stderr         | 21 ++++++---
 tests/ui/resolve/issue-21221-2.stderr         |  6 ++-
 tests/ui/resolve/issue-21221-3.stderr         |  3 +-
 tests/ui/resolve/issue-21221-4.stderr         |  3 +-
 tests/ui/resolve/issue-2356.stderr            |  3 +-
 tests/ui/resolve/issue-26545.stderr           |  3 +-
 tests/ui/resolve/issue-35675.stderr           |  6 ++-
 tests/ui/resolve/issue-3907.stderr            |  3 +-
 tests/ui/resolve/issue-50599.stderr           |  6 ++-
 tests/ui/resolve/issue-73427.stderr           |  6 ++-
 tests/ui/resolve/issue-90113.stderr           |  3 +-
 tests/ui/resolve/missing-in-namespace.stderr  |  3 +-
 .../resolve/no-implicit-prelude-nested.stderr | 45 ++++++++++++-------
 tests/ui/resolve/no-implicit-prelude.stderr   | 15 ++++---
 tests/ui/resolve/privacy-enum-ctor.stderr     | 12 +++--
 .../resolve/resolve-primitive-fallback.stderr |  3 +-
 tests/ui/resolve/use_suggestion.stderr        |  6 ++-
 .../resolve/use_suggestion_placement.stderr   |  9 ++--
 .../dbg-macro-requires-debug.stderr           |  3 +-
 .../derive-const-non-const-type.stderr        |  3 +-
 .../issue-52202-use-suggestions.stderr        | 12 +++--
 .../rust-2018/trait-import-suggestions.stderr |  9 ++--
 .../uniform-paths/issue-87932.stderr          |  3 +-
 .../future-prelude-collision-shadow.stderr    |  6 ++-
 tests/ui/self/class-missing-self.stderr       |  3 +-
 .../ui/shadowed/shadowed-trait-methods.stderr |  3 +-
 ...incompatible-closure-captures-96258.stderr |  3 +-
 tests/ui/span/issue-35987.stderr              |  1 +
 tests/ui/span/issue-71363.stderr              |  3 +-
 tests/ui/specialization/issue-59435.stderr    |  3 +-
 .../structs/struct-path-alias-bounds.stderr   |  3 +-
 ...n-unconstrained-borrowed-type-param.stderr |  3 +-
 .../core-std-import-order-issue-83564.stderr  |  6 ++-
 .../derive-macro-missing-bounds.stderr        |  3 +-
 .../derive-trait-for-method-call.stderr       |  9 ++--
 .../dont-wrap-ambiguous-receivers.stderr      |  6 ++-
 .../import-trait-for-method-call.stderr       |  3 +-
 tests/ui/suggestions/invalid-bin-op.stderr    |  3 +-
 .../suggestions/issue-84973-blacklist.stderr  |  3 +-
 .../no-extern-crate-in-type.stderr            |  3 +-
 .../raw-name-use-suggestion.stderr            |  3 +-
 .../suggest-tryinto-edition-change.stderr     | 21 ++++++---
 .../suggestions/use-placement-resolve.stderr  |  3 +-
 .../suggestions/use-placement-typeck.stderr   |  3 +-
 .../impl-bound-with-references-error.stderr   |  3 +-
 ...owed-path-in-trait-bound-suggestion.stderr |  3 +-
 .../supertrait-auto-trait.stderr              |  3 +-
 tests/ui/traits/issue-71136.stderr            |  3 +-
 tests/ui/traits/issue-78372.stderr            |  3 +-
 tests/ui/traits/item-privacy.stderr           |  9 ++--
 tests/ui/traits/method-private.stderr         |  3 +-
 tests/ui/typeck/explain_clone_autoref.stderr  |  3 +-
 tests/ui/typeck/issue-43189.stderr            |  3 +-
 tests/ui/underscore-imports/shadow.stderr     |  3 +-
 .../union-derive-clone.mirunsafeck.stderr     |  6 ++-
 .../union-derive-clone.thirunsafeck.stderr    |  6 ++-
 .../union/union-derive-eq.mirunsafeck.stderr  |  3 +-
 .../union/union-derive-eq.thirunsafeck.stderr |  3 +-
 .../unresolved/unresolved-candidates.stderr   |  3 +-
 tests/ui/wf/wf-const-type.stderr              |  3 +-
 tests/ui/wf/wf-static-type.stderr             |  3 +-
 .../where-clauses-method-unsatisfied.stderr   |  3 +-
 .../where-clauses-unsatisfied.stderr          |  3 +-
 166 files changed, 634 insertions(+), 294 deletions(-)

diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 81e8bcbf7cd54..7b6d65511c15b 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -1832,6 +1832,12 @@ impl EmitterWriter {
             }
             let show_code_change = if has_deletion && !is_multiline {
                 DisplaySuggestion::Diff
+            } else if let [part] = &parts[..]
+                && part.snippet.ends_with('\n')
+                && part.snippet.trim() == complete.trim()
+            {
+                // We are adding a line(s) of code before code that was already there.
+                DisplaySuggestion::Add
             } else if (parts.len() != 1 || parts[0].snippet.trim() != complete.trim())
                 && !is_multiline
             {
@@ -1879,7 +1885,9 @@ impl EmitterWriter {
                 row_num += line_end - line_start;
             }
             let mut unhighlighted_lines = Vec::new();
+            let mut last_pos = 0;
             for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() {
+                last_pos = line_pos;
                 debug!(%line_pos, %line, ?highlight_parts);
 
                 // Remember lines that are not highlighted to hide them if needed
@@ -1963,13 +1971,39 @@ impl EmitterWriter {
                     is_multiline,
                 )
             }
+            if let DisplaySuggestion::Add = show_code_change {
+                // The suggestion adds an entire line of code, ending on a newline, so we'll also
+                // print the *following* line, to provide context of what we're advicing people to
+                // do. Otherwise you would only see contextless code that can be confused for
+                // already existing code, despite the colors and UI elements.
+                let file_lines = sm
+                    .span_to_lines(span.primary_span().unwrap().shrink_to_hi())
+                    .expect("span_to_lines failed when emitting suggestion");
+                let line_num = sm.lookup_char_pos(parts[0].span.lo()).line;
+                if let Some(line) = file_lines.file.get_line(line_num - 1) {
+                    let line = normalize_whitespace(&line);
+                    self.draw_code_line(
+                        &mut buffer,
+                        &mut row_num,
+                        &[],
+                        line_num + last_pos + 1,
+                        &line,
+                        DisplaySuggestion::None,
+                        max_line_num_len,
+                        &file_lines,
+                        is_multiline,
+                    )
+                }
+            }
 
             // This offset and the ones below need to be signed to account for replacement code
             // that is shorter than the original code.
             let mut offsets: Vec<(usize, isize)> = Vec::new();
             // Only show an underline in the suggestions if the suggestion is not the
             // entirety of the code being shown and the displayed code is not multiline.
-            if let DisplaySuggestion::Diff | DisplaySuggestion::Underline = show_code_change {
+            if let DisplaySuggestion::Diff | DisplaySuggestion::Underline | DisplaySuggestion::Add =
+                show_code_change
+            {
                 draw_col_separator_no_space(&mut buffer, row_num, max_line_num_len + 1);
                 for part in parts {
                     let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display;
@@ -2247,6 +2281,10 @@ impl EmitterWriter {
                 }
             }
             buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
+        } else if let DisplaySuggestion::Add = show_code_change {
+            buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
+            buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
+            buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
         } else {
             buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
             draw_col_separator(buffer, *row_num, max_line_num_len + 1);
@@ -2281,6 +2319,7 @@ enum DisplaySuggestion {
     Underline,
     Diff,
     None,
+    Add,
 }
 
 impl FileWithAnnotatedLines {
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
index efdd56dd47d39..3c7e08ebeae85 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
@@ -6,11 +6,14 @@ LL |     _n: PhantomData,
    |
 help: consider importing one of these items
    |
-LL | use core::marker::PhantomData;
+LL + use core::marker::PhantomData;
+LL | trait TypeVal<T> {
    |
-LL | use serde::__private::PhantomData;
+LL + use serde::__private::PhantomData;
+LL | trait TypeVal<T> {
    |
-LL | use std::marker::PhantomData;
+LL + use std::marker::PhantomData;
+LL | trait TypeVal<T> {
    |
 
 error[E0412]: cannot find type `VAL` in this scope
diff --git a/src/tools/clippy/tests/ui/derivable_impls.stderr b/src/tools/clippy/tests/ui/derivable_impls.stderr
index 81963c3be5b5d..8089f5ea0fcb2 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.stderr
+++ b/src/tools/clippy/tests/ui/derivable_impls.stderr
@@ -14,7 +14,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct FooDefault<'a> {
    |
 
 error: this `impl` can be derived
@@ -30,7 +31,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct TupleDefault(bool, i32, u64);
    |
 
 error: this `impl` can be derived
@@ -46,7 +48,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct StrDefault<'a>(&'a str);
    |
 
 error: this `impl` can be derived
@@ -62,7 +65,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct Y(u32);
    |
 
 error: this `impl` can be derived
@@ -78,7 +82,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct WithoutSelfCurly {
    |
 
 error: this `impl` can be derived
@@ -94,7 +99,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct WithoutSelfParan(bool);
    |
 
 error: this `impl` can be derived
@@ -110,7 +116,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | pub struct RepeatDefault1 {
    |
 
 error: this `impl` can be derived
@@ -126,7 +133,8 @@ LL | | }
    = help: remove the manual implementation...
 help: ...and instead derive it...
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | pub enum SimpleEnum {
    |
 help: ...and mark the default variant
    |
diff --git a/src/tools/clippy/tests/ui/new_without_default.stderr b/src/tools/clippy/tests/ui/new_without_default.stderr
index 583dd327d6a5d..9b0a2f6ca5bf2 100644
--- a/src/tools/clippy/tests/ui/new_without_default.stderr
+++ b/src/tools/clippy/tests/ui/new_without_default.stderr
@@ -14,6 +14,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl Foo {
    |
 
 error: you should consider adding a `Default` implementation for `Bar`
@@ -31,6 +32,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl Bar {
    |
 
 error: you should consider adding a `Default` implementation for `LtKo<'c>`
@@ -48,6 +50,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl<'c> LtKo<'c> {
    |
 
 error: you should consider adding a `Default` implementation for `NewNotEqualToDerive`
@@ -65,6 +68,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl NewNotEqualToDerive {
    |
 
 error: you should consider adding a `Default` implementation for `FooGenerics<T>`
@@ -82,6 +86,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl<T> FooGenerics<T> {
    |
 
 error: you should consider adding a `Default` implementation for `BarGenerics<T>`
@@ -99,6 +104,7 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
+LL | impl<T: Copy> BarGenerics<T> {
    |
 
 error: you should consider adding a `Default` implementation for `Foo<T>`
diff --git a/tests/ui/array-slice-vec/repeat_empty_ok.stderr b/tests/ui/array-slice-vec/repeat_empty_ok.stderr
index 724bdcd920ab4..e8bac04ac4503 100644
--- a/tests/ui/array-slice-vec/repeat_empty_ok.stderr
+++ b/tests/ui/array-slice-vec/repeat_empty_ok.stderr
@@ -7,7 +7,8 @@ LL |     let headers = [Header{value: &[]}; 128];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Header<'_>` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | pub struct Header<'a> {
    |
 
 error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
@@ -19,7 +20,8 @@ LL |     let headers = [Header{value: &[0]}; 128];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Header<'_>` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | pub struct Header<'a> {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/associated-types/defaults-suitability.stderr b/tests/ui/associated-types/defaults-suitability.stderr
index 2485758757b9b..4b2094691f8cc 100644
--- a/tests/ui/associated-types/defaults-suitability.stderr
+++ b/tests/ui/associated-types/defaults-suitability.stderr
@@ -11,7 +11,8 @@ LL |     type Ty: Clone = NotClone;
    |              ^^^^^ required by this bound in `Tr::Ty`
 help: consider annotating `NotClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NotClone;
    |
 
 error[E0277]: the trait bound `NotClone: Clone` is not satisfied
@@ -30,7 +31,8 @@ LL |     type Ty = NotClone;
    |          -- required by a bound in this associated type
 help: consider annotating `NotClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NotClone;
    |
 
 error[E0277]: the trait bound `T: Clone` is not satisfied
diff --git a/tests/ui/binop/issue-28837.stderr b/tests/ui/binop/issue-28837.stderr
index cca1da3b6ac49..bb9f3b8af0ff1 100644
--- a/tests/ui/binop/issue-28837.stderr
+++ b/tests/ui/binop/issue-28837.stderr
@@ -157,7 +157,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialEq<_>`
 help: consider annotating `A` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct A;
    |
 
 error[E0369]: binary operation `!=` cannot be applied to type `A`
@@ -175,7 +176,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialEq<_>`
 help: consider annotating `A` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct A;
    |
 
 error[E0369]: binary operation `<` cannot be applied to type `A`
@@ -193,7 +195,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialOrd<_>`
 help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialEq, PartialOrd)]
+LL + #[derive(PartialEq, PartialOrd)]
+LL | struct A;
    |
 
 error[E0369]: binary operation `<=` cannot be applied to type `A`
@@ -211,7 +214,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialOrd<_>`
 help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialEq, PartialOrd)]
+LL + #[derive(PartialEq, PartialOrd)]
+LL | struct A;
    |
 
 error[E0369]: binary operation `>` cannot be applied to type `A`
@@ -229,7 +233,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialOrd<_>`
 help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialEq, PartialOrd)]
+LL + #[derive(PartialEq, PartialOrd)]
+LL | struct A;
    |
 
 error[E0369]: binary operation `>=` cannot be applied to type `A`
@@ -247,7 +252,8 @@ LL | struct A;
    | ^^^^^^^^ must implement `PartialOrd<_>`
 help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialEq, PartialOrd)]
+LL + #[derive(PartialEq, PartialOrd)]
+LL | struct A;
    |
 
 error: aborting due to 15 previous errors
diff --git a/tests/ui/box/unit/unique-pinned-nocopy.stderr b/tests/ui/box/unit/unique-pinned-nocopy.stderr
index de6611324cac1..2fd5b0d82e8fa 100644
--- a/tests/ui/box/unit/unique-pinned-nocopy.stderr
+++ b/tests/ui/box/unit/unique-pinned-nocopy.stderr
@@ -19,7 +19,8 @@ LL |       let _j = i.clone();
            candidate #1: `Clone`
 help: consider annotating `R` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct R {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr
index 46b128c08fef9..48f70700046f3 100644
--- a/tests/ui/coherence/coherence_inherent.stderr
+++ b/tests/ui/coherence/coherence_inherent.stderr
@@ -7,7 +7,8 @@ LL |         s.the_fn();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use Lib::TheTrait;
+LL +     use Lib::TheTrait;
+LL |     use Lib::TheStruct;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr
index af0ef3b693262..58254740f82e0 100644
--- a/tests/ui/coherence/coherence_inherent_cc.stderr
+++ b/tests/ui/coherence/coherence_inherent_cc.stderr
@@ -7,7 +7,8 @@ LL |         s.the_fn();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use coherence_inherent_cc_lib::TheTrait;
+LL +     use coherence_inherent_cc_lib::TheTrait;
+LL |     use coherence_inherent_cc_lib::TheStruct;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
index 7390a007742fc..1e4e4edb596bb 100644
--- a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
@@ -8,6 +8,7 @@ LL |     If<{ FRAC <= 32 }>: True,
 help: consider enabling this feature
   --> $DIR/issue-94287.rs:1:1
    |
+LL + #![feature(generic_const_exprs)]
 LL | #![feature(generic_const_exprs)]
    |
 
diff --git a/tests/ui/const-generics/issues/issue-82956.stderr b/tests/ui/const-generics/issues/issue-82956.stderr
index d2320293e857e..d1d5073255109 100644
--- a/tests/ui/const-generics/issues/issue-82956.stderr
+++ b/tests/ui/const-generics/issues/issue-82956.stderr
@@ -6,13 +6,17 @@ LL |         let mut iter = IntoIter::new(self);
    |
 help: consider importing one of these items
    |
-LL | use std::array::IntoIter;
+LL + use std::array::IntoIter;
+LL | pub struct ConstCheck<const CHECK: bool>;
    |
-LL | use std::collections::binary_heap::IntoIter;
+LL + use std::collections::binary_heap::IntoIter;
+LL | pub struct ConstCheck<const CHECK: bool>;
    |
-LL | use std::collections::btree_map::IntoIter;
+LL + use std::collections::btree_map::IntoIter;
+LL | pub struct ConstCheck<const CHECK: bool>;
    |
-LL | use std::collections::btree_set::IntoIter;
+LL + use std::collections::btree_set::IntoIter;
+LL | pub struct ConstCheck<const CHECK: bool>;
    |
      and 8 other candidates
 
diff --git a/tests/ui/consts/const-blocks/fn-call-in-non-const.stderr b/tests/ui/consts/const-blocks/fn-call-in-non-const.stderr
index ee352700c307c..174103eeba4c4 100644
--- a/tests/ui/consts/const-blocks/fn-call-in-non-const.stderr
+++ b/tests/ui/consts/const-blocks/fn-call-in-non-const.stderr
@@ -10,7 +10,8 @@ LL |     let _: [Option<Bar>; 2] = [no_copy(); 2];
    = help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
 help: consider annotating `Bar` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Bar;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/consts/const-blocks/migrate-fail.stderr b/tests/ui/consts/const-blocks/migrate-fail.stderr
index 928ffd0839db5..d1896f755d530 100644
--- a/tests/ui/consts/const-blocks/migrate-fail.stderr
+++ b/tests/ui/consts/const-blocks/migrate-fail.stderr
@@ -8,7 +8,8 @@ LL |         let arr: [Option<Bar>; 2] = [x; 2];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Bar` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Bar;
    |
 
 error[E0277]: the trait bound `Bar: Copy` is not satisfied
@@ -21,7 +22,8 @@ LL |         let arr: [Option<Bar>; 2] = [x; 2];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Bar` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Bar;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/consts/const-blocks/nll-fail.stderr b/tests/ui/consts/const-blocks/nll-fail.stderr
index fede0084547c9..807c964a51d6f 100644
--- a/tests/ui/consts/const-blocks/nll-fail.stderr
+++ b/tests/ui/consts/const-blocks/nll-fail.stderr
@@ -8,7 +8,8 @@ LL |         let arr: [Option<Bar>; 2] = [x; 2];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Bar` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Bar;
    |
 
 error[E0277]: the trait bound `Bar: Copy` is not satisfied
@@ -21,7 +22,8 @@ LL |         let arr: [Option<Bar>; 2] = [x; 2];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Bar` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Bar;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
index 778b0e55f6620..7ec2508ca93a6 100644
--- a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
@@ -22,11 +22,13 @@ LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 help: if it is not part of the public API, make this function unstably const
    |
-LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+LL + #[rustc_const_unstable(feature = "...", issue = "...")]
+LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
    |
-LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 
 error: `foo2_gated` is not yet stable as a const fn
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
index 0174cb77f332d..72c1f175d1d6b 100644
--- a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
@@ -22,11 +22,13 @@ LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 help: if it is not part of the public API, make this function unstably const
    |
-LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+LL + #[rustc_const_unstable(feature = "...", issue = "...")]
+LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
    |
-LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
    |
 
 error: `foo2_gated` is not yet stable as a const fn
diff --git a/tests/ui/derived-errors/issue-31997-1.stderr b/tests/ui/derived-errors/issue-31997-1.stderr
index 2f4aabf845311..2ea3d910dbfa7 100644
--- a/tests/ui/derived-errors/issue-31997-1.stderr
+++ b/tests/ui/derived-errors/issue-31997-1.stderr
@@ -6,7 +6,8 @@ LL |     let mut map = HashMap::new();
    |
 help: consider importing this struct
    |
-LL | use std::collections::HashMap;
+LL + use std::collections::HashMap;
+LL | use std::io::prelude::*;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derive-assoc-type-not-impl.stderr b/tests/ui/derives/derive-assoc-type-not-impl.stderr
index 91b334b412bc9..9f17c76c2ec6d 100644
--- a/tests/ui/derives/derive-assoc-type-not-impl.stderr
+++ b/tests/ui/derives/derive-assoc-type-not-impl.stderr
@@ -23,7 +23,8 @@ LL | #[derive(Clone)]
            candidate #1: `Clone`
 help: consider annotating `NotClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NotClone;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Clone-enum-struct-variant.stderr b/tests/ui/derives/derives-span-Clone-enum-struct-variant.stderr
index 7326324b03cca..31ab589cf385a 100644
--- a/tests/ui/derives/derives-span-Clone-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-Clone-enum-struct-variant.stderr
@@ -10,7 +10,8 @@ LL |      x: Error
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Clone-enum.stderr b/tests/ui/derives/derives-span-Clone-enum.stderr
index 229a4f7d9ff94..b5580c02f38f3 100644
--- a/tests/ui/derives/derives-span-Clone-enum.stderr
+++ b/tests/ui/derives/derives-span-Clone-enum.stderr
@@ -10,7 +10,8 @@ LL |      Error
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Clone-struct.stderr b/tests/ui/derives/derives-span-Clone-struct.stderr
index 96bad9edad94c..fbe7e3f8479da 100644
--- a/tests/ui/derives/derives-span-Clone-struct.stderr
+++ b/tests/ui/derives/derives-span-Clone-struct.stderr
@@ -10,7 +10,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Clone-tuple-struct.stderr b/tests/ui/derives/derives-span-Clone-tuple-struct.stderr
index b61341e57e671..639f4d5425478 100644
--- a/tests/ui/derives/derives-span-Clone-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Clone-tuple-struct.stderr
@@ -10,7 +10,8 @@ LL |     Error
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Debug-enum-struct-variant.stderr b/tests/ui/derives/derives-span-Debug-enum-struct-variant.stderr
index 58a64a4f53bfc..7ff6851f6555b 100644
--- a/tests/ui/derives/derives-span-Debug-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-Debug-enum-struct-variant.stderr
@@ -12,7 +12,8 @@ LL |      x: Error
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Debug-enum.stderr b/tests/ui/derives/derives-span-Debug-enum.stderr
index e9bb5f960b04a..346cbec90a940 100644
--- a/tests/ui/derives/derives-span-Debug-enum.stderr
+++ b/tests/ui/derives/derives-span-Debug-enum.stderr
@@ -12,7 +12,8 @@ LL |      Error
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Debug-struct.stderr b/tests/ui/derives/derives-span-Debug-struct.stderr
index 0a117c060ff38..4b39eeb09ee8a 100644
--- a/tests/ui/derives/derives-span-Debug-struct.stderr
+++ b/tests/ui/derives/derives-span-Debug-struct.stderr
@@ -12,7 +12,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Debug-tuple-struct.stderr b/tests/ui/derives/derives-span-Debug-tuple-struct.stderr
index f2e90a418455f..f3043abcadd22 100644
--- a/tests/ui/derives/derives-span-Debug-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Debug-tuple-struct.stderr
@@ -12,7 +12,8 @@ LL |     Error
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Default-struct.stderr b/tests/ui/derives/derives-span-Default-struct.stderr
index d4affd535eef4..4844b63592402 100644
--- a/tests/ui/derives/derives-span-Default-struct.stderr
+++ b/tests/ui/derives/derives-span-Default-struct.stderr
@@ -10,7 +10,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Default)]`
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Default-tuple-struct.stderr b/tests/ui/derives/derives-span-Default-tuple-struct.stderr
index 129351f599899..9cac7f10780ff 100644
--- a/tests/ui/derives/derives-span-Default-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Default-tuple-struct.stderr
@@ -10,7 +10,8 @@ LL |     Error
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Default)]`
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Eq-enum-struct-variant.stderr b/tests/ui/derives/derives-span-Eq-enum-struct-variant.stderr
index 2be69a30b1c12..1a9ff9832557d 100644
--- a/tests/ui/derives/derives-span-Eq-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-Eq-enum-struct-variant.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Eq-enum.stderr b/tests/ui/derives/derives-span-Eq-enum.stderr
index 4f4f821cca3e7..8205657bb7104 100644
--- a/tests/ui/derives/derives-span-Eq-enum.stderr
+++ b/tests/ui/derives/derives-span-Eq-enum.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Eq-struct.stderr b/tests/ui/derives/derives-span-Eq-struct.stderr
index f15659c3e166c..af510181df7db 100644
--- a/tests/ui/derives/derives-span-Eq-struct.stderr
+++ b/tests/ui/derives/derives-span-Eq-struct.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Eq-tuple-struct.stderr b/tests/ui/derives/derives-span-Eq-tuple-struct.stderr
index 4e5659b35f47a..f7c371d7d05ac 100644
--- a/tests/ui/derives/derives-span-Eq-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Eq-tuple-struct.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/tests/ui/derives/derives-span-Hash-enum-struct-variant.stderr
index fe5e0e96ac7af..311edade0f3d8 100644
--- a/tests/ui/derives/derives-span-Hash-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-Hash-enum-struct-variant.stderr
@@ -10,7 +10,8 @@ LL |      x: Error
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Hash)]`
    |
-LL | #[derive(Hash)]
+LL + #[derive(Hash)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Hash-enum.stderr b/tests/ui/derives/derives-span-Hash-enum.stderr
index 99785b87ca83e..043aa954bfa10 100644
--- a/tests/ui/derives/derives-span-Hash-enum.stderr
+++ b/tests/ui/derives/derives-span-Hash-enum.stderr
@@ -10,7 +10,8 @@ LL |      Error
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Hash)]`
    |
-LL | #[derive(Hash)]
+LL + #[derive(Hash)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Hash-struct.stderr b/tests/ui/derives/derives-span-Hash-struct.stderr
index 4db83dd130010..26d31b6613fe7 100644
--- a/tests/ui/derives/derives-span-Hash-struct.stderr
+++ b/tests/ui/derives/derives-span-Hash-struct.stderr
@@ -10,7 +10,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Hash)]`
    |
-LL | #[derive(Hash)]
+LL + #[derive(Hash)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Hash-tuple-struct.stderr b/tests/ui/derives/derives-span-Hash-tuple-struct.stderr
index 8660c97e69e1c..3155a023ce8a9 100644
--- a/tests/ui/derives/derives-span-Hash-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Hash-tuple-struct.stderr
@@ -10,7 +10,8 @@ LL |     Error
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Hash)]`
    |
-LL | #[derive(Hash)]
+LL + #[derive(Hash)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Ord-enum-struct-variant.stderr b/tests/ui/derives/derives-span-Ord-enum-struct-variant.stderr
index 6e48332c25067..1a06aee5235ad 100644
--- a/tests/ui/derives/derives-span-Ord-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-Ord-enum-struct-variant.stderr
@@ -10,7 +10,8 @@ LL |      x: Error
    = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Ord)]`
    |
-LL | #[derive(Ord)]
+LL + #[derive(Ord)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Ord-enum.stderr b/tests/ui/derives/derives-span-Ord-enum.stderr
index b05cf0a057b23..377728e8a7f66 100644
--- a/tests/ui/derives/derives-span-Ord-enum.stderr
+++ b/tests/ui/derives/derives-span-Ord-enum.stderr
@@ -10,7 +10,8 @@ LL |      Error
    = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Ord)]`
    |
-LL | #[derive(Ord)]
+LL + #[derive(Ord)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Ord-struct.stderr b/tests/ui/derives/derives-span-Ord-struct.stderr
index c4def34a83dad..e00e990da2a5b 100644
--- a/tests/ui/derives/derives-span-Ord-struct.stderr
+++ b/tests/ui/derives/derives-span-Ord-struct.stderr
@@ -10,7 +10,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Ord)]`
    |
-LL | #[derive(Ord)]
+LL + #[derive(Ord)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-Ord-tuple-struct.stderr b/tests/ui/derives/derives-span-Ord-tuple-struct.stderr
index a3b288d0fb9cc..959d0b9640408 100644
--- a/tests/ui/derives/derives-span-Ord-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-Ord-tuple-struct.stderr
@@ -10,7 +10,8 @@ LL |     Error
    = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(Ord)]`
    |
-LL | #[derive(Ord)]
+LL + #[derive(Ord)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr b/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr
index 9953154fd4b71..9fc25f2ade426 100644
--- a/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr
@@ -15,7 +15,8 @@ LL | struct Error;
    = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialEq-enum.stderr b/tests/ui/derives/derives-span-PartialEq-enum.stderr
index 7c130452301d3..f56e784478d5f 100644
--- a/tests/ui/derives/derives-span-PartialEq-enum.stderr
+++ b/tests/ui/derives/derives-span-PartialEq-enum.stderr
@@ -15,7 +15,8 @@ LL | struct Error;
    = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialEq-struct.stderr b/tests/ui/derives/derives-span-PartialEq-struct.stderr
index ba3d6ced3f49d..76c0b0104afb6 100644
--- a/tests/ui/derives/derives-span-PartialEq-struct.stderr
+++ b/tests/ui/derives/derives-span-PartialEq-struct.stderr
@@ -15,7 +15,8 @@ LL | struct Error;
    = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialEq-tuple-struct.stderr b/tests/ui/derives/derives-span-PartialEq-tuple-struct.stderr
index ab0b56a9eefbb..7dae01dbb9916 100644
--- a/tests/ui/derives/derives-span-PartialEq-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-PartialEq-tuple-struct.stderr
@@ -15,7 +15,8 @@ LL | struct Error;
    = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr b/tests/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr
index 2d19aaf68afb1..746c1d5d21fd4 100644
--- a/tests/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr
+++ b/tests/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr
@@ -11,7 +11,8 @@ LL |      x: Error
    = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL + #[derive(PartialOrd)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialOrd-enum.stderr b/tests/ui/derives/derives-span-PartialOrd-enum.stderr
index dfbb8060ffa12..8af1776dac87b 100644
--- a/tests/ui/derives/derives-span-PartialOrd-enum.stderr
+++ b/tests/ui/derives/derives-span-PartialOrd-enum.stderr
@@ -11,7 +11,8 @@ LL |      Error
    = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL + #[derive(PartialOrd)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialOrd-struct.stderr b/tests/ui/derives/derives-span-PartialOrd-struct.stderr
index ba63d86e8e46c..11ea7f9dc31be 100644
--- a/tests/ui/derives/derives-span-PartialOrd-struct.stderr
+++ b/tests/ui/derives/derives-span-PartialOrd-struct.stderr
@@ -11,7 +11,8 @@ LL |     x: Error
    = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL + #[derive(PartialOrd)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/derives-span-PartialOrd-tuple-struct.stderr b/tests/ui/derives/derives-span-PartialOrd-tuple-struct.stderr
index 7686ed8064e79..0a41a3db31eac 100644
--- a/tests/ui/derives/derives-span-PartialOrd-tuple-struct.stderr
+++ b/tests/ui/derives/derives-span-PartialOrd-tuple-struct.stderr
@@ -11,7 +11,8 @@ LL |     Error
    = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Error` with `#[derive(PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL + #[derive(PartialOrd)]
+LL | struct Error;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/deriving-no-inner-impl-error-message.stderr b/tests/ui/derives/deriving-no-inner-impl-error-message.stderr
index ef8c44caacfa1..10af5d36ed936 100644
--- a/tests/ui/derives/deriving-no-inner-impl-error-message.stderr
+++ b/tests/ui/derives/deriving-no-inner-impl-error-message.stderr
@@ -15,7 +15,8 @@ LL | struct NoCloneOrEq;
    = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `NoCloneOrEq` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct NoCloneOrEq;
    |
 
 error[E0277]: the trait bound `NoCloneOrEq: Clone` is not satisfied
@@ -30,7 +31,8 @@ LL |     x: NoCloneOrEq
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `NoCloneOrEq` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NoCloneOrEq;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/derives/deriving-with-repr-packed-2.stderr b/tests/ui/derives/deriving-with-repr-packed-2.stderr
index ab3646057a55c..afeca9fec2b84 100644
--- a/tests/ui/derives/deriving-with-repr-packed-2.stderr
+++ b/tests/ui/derives/deriving-with-repr-packed-2.stderr
@@ -25,7 +25,8 @@ LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
    |                ^^^^^ unsatisfied trait bound introduced in this `derive` macro
 help: consider annotating `NonCopy` with `#[derive(Clone, Copy)]`
    |
-LL | #[derive(Clone, Copy)]
+LL + #[derive(Clone, Copy)]
+LL | struct NonCopy;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/derives/issue-91492.stderr b/tests/ui/derives/issue-91492.stderr
index cee30ac50a6a2..fc64828b1533c 100644
--- a/tests/ui/derives/issue-91492.stderr
+++ b/tests/ui/derives/issue-91492.stderr
@@ -11,7 +11,8 @@ LL |     foo.extend_from_slice(bar);
            `NoDerives: Clone`
 help: consider annotating `NoDerives` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | pub struct NoDerives;
    |
 
 error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<SomeDerives>`, but its trait bounds were not satisfied
@@ -27,7 +28,8 @@ LL |     foo.extend_from_slice(bar);
            `SomeDerives: Clone`
 help: consider annotating `SomeDerives` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | pub struct SomeDerives;
    |
 
 error[E0599]: the method `use_clone` exists for struct `Object<NoDerives, SomeDerives>`, but its trait bounds were not satisfied
@@ -51,7 +53,8 @@ LL | impl<T: Clone, A: Default> Object<T, A> {
    |         unsatisfied trait bound introduced here
 help: consider annotating `NoDerives` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | pub struct NoDerives;
    |
 
 error: aborting due to 3 previous errors
diff --git a/tests/ui/derives/issue-91550.stderr b/tests/ui/derives/issue-91550.stderr
index af03f0e5e5f43..1324b80b5fcdb 100644
--- a/tests/ui/derives/issue-91550.stderr
+++ b/tests/ui/derives/issue-91550.stderr
@@ -18,7 +18,8 @@ LL |     hs.insert(Value(0));
            `Value: Hash`
 help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]`
    |
-LL | #[derive(Eq, Hash, PartialEq)]
+LL + #[derive(Eq, Hash, PartialEq)]
+LL | struct Value(u32);
    |
 
 error[E0599]: the method `use_eq` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
@@ -48,7 +49,8 @@ LL | impl<T: Eq> Object<T> {
            which is required by `NoDerives: Eq`
 help: consider annotating `NoDerives` with `#[derive(Eq, PartialEq)]`
    |
-LL | #[derive(Eq, PartialEq)]
+LL + #[derive(Eq, PartialEq)]
+LL | pub struct NoDerives;
    |
 
 error[E0599]: the method `use_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
@@ -84,7 +86,8 @@ LL | impl<T: Ord> Object<T> {
            which is required by `NoDerives: Ord`
 help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
    |
-LL | #[derive(Eq, Ord, PartialEq, PartialOrd)]
+LL + #[derive(Eq, Ord, PartialEq, PartialOrd)]
+LL | pub struct NoDerives;
    |
 
 error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
@@ -123,7 +126,8 @@ LL | impl<T: Ord + PartialOrd> Object<T> {
            which is required by `NoDerives: PartialOrd`
 help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
    |
-LL | #[derive(Eq, Ord, PartialEq, PartialOrd)]
+LL + #[derive(Eq, Ord, PartialEq, PartialOrd)]
+LL | pub struct NoDerives;
    |
 
 error: aborting due to 4 previous errors
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 abc040c0546b4..11cdcfadef36c 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
@@ -24,13 +24,17 @@ LL | fn setup() -> Set { Set }
    |
 help: consider importing one of these items
    |
-LL | use AffixHeart::Set;
+LL + use AffixHeart::Set;
+LL | enum PutDown { Set }
    |
-LL | use CauseToBe::Set;
+LL + use CauseToBe::Set;
+LL | enum PutDown { Set }
    |
-LL | use Determine::Set;
+LL + use Determine::Set;
+LL | enum PutDown { Set }
    |
-LL | use PutDown::Set;
+LL + use PutDown::Set;
+LL | enum PutDown { Set }
    |
      and 3 other candidates
 
diff --git a/tests/ui/error-codes/E0277-3.stderr b/tests/ui/error-codes/E0277-3.stderr
index 0127e1ccc81ec..0d4782935df41 100644
--- a/tests/ui/error-codes/E0277-3.stderr
+++ b/tests/ui/error-codes/E0277-3.stderr
@@ -14,7 +14,8 @@ LL | fn foo<T: PartialEq>(_: T) {}
    |           ^^^^^^^^^ required by this bound in `foo`
 help: consider annotating `S` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct S;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/fmt/format-args-argument-span.stderr b/tests/ui/fmt/format-args-argument-span.stderr
index b060b2cd33930..4e2702383d6cb 100644
--- a/tests/ui/fmt/format-args-argument-span.stderr
+++ b/tests/ui/fmt/format-args-argument-span.stderr
@@ -29,7 +29,8 @@ LL |     println!("{x} {x:?} {x}");
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `DisplayOnly` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct DisplayOnly;
    |
 
 error[E0277]: `DisplayOnly` doesn't implement `Debug`
@@ -43,7 +44,8 @@ LL |     println!("{x} {x:?} {x}", x = DisplayOnly);
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `DisplayOnly` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct DisplayOnly;
    |
 
 error: aborting due to 4 previous errors
diff --git a/tests/ui/generator/clone-impl.stderr b/tests/ui/generator/clone-impl.stderr
index a92646b198cf4..64eb47c1a5a03 100644
--- a/tests/ui/generator/clone-impl.stderr
+++ b/tests/ui/generator/clone-impl.stderr
@@ -110,7 +110,8 @@ LL | fn check_copy<T: Copy>(_x: &T) {}
    |                  ^^^^ required by this bound in `check_copy`
 help: consider annotating `NonClone` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct NonClone;
    |
 
 error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `[generator@$DIR/clone-impl.rs:62:25: 62:32]`
@@ -134,7 +135,8 @@ LL | fn check_clone<T: Clone>(_x: &T) {}
    |                   ^^^^^ required by this bound in `check_clone`
 help: consider annotating `NonClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NonClone;
    |
 
 error: aborting due to 6 previous errors
diff --git a/tests/ui/generic-associated-types/issue-87429-associated-type-default.stderr b/tests/ui/generic-associated-types/issue-87429-associated-type-default.stderr
index b1abe012be23d..a44bb6993d49d 100644
--- a/tests/ui/generic-associated-types/issue-87429-associated-type-default.stderr
+++ b/tests/ui/generic-associated-types/issue-87429-associated-type-default.stderr
@@ -12,7 +12,8 @@ LL |     type Member<'a>: for<'b> PartialEq<Self::Member<'b>> = Foo;
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family2::Member`
 help: consider annotating `Foo` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Foo;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/generic-associated-types/issue-87429-specialization.stderr b/tests/ui/generic-associated-types/issue-87429-specialization.stderr
index 11c4ebf604e74..c259c89a712ec 100644
--- a/tests/ui/generic-associated-types/issue-87429-specialization.stderr
+++ b/tests/ui/generic-associated-types/issue-87429-specialization.stderr
@@ -22,7 +22,8 @@ LL |     type Member<'a>: for<'b> PartialEq<Self::Member<'b>>;
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family::Member`
 help: consider annotating `Foo` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct Foo;
    |
 
 error: aborting due to previous error; 1 warning emitted
diff --git a/tests/ui/hygiene/globs.stderr b/tests/ui/hygiene/globs.stderr
index c01901be5fe78..b68950b66dbae 100644
--- a/tests/ui/hygiene/globs.stderr
+++ b/tests/ui/hygiene/globs.stderr
@@ -13,7 +13,8 @@ LL |         g();
    |         ~
 help: consider importing this function
    |
-LL | use foo::f;
+LL + use foo::f;
+LL | mod foo {
    |
 
 error[E0425]: cannot find function `g` in this scope
@@ -39,7 +40,8 @@ LL |     f();
    |     ~
 help: consider importing this function
    |
-LL | use bar::g;
+LL + use bar::g;
+LL | mod foo {
    |
 
 error[E0425]: cannot find function `f` in this scope
diff --git a/tests/ui/hygiene/no_implicit_prelude.stderr b/tests/ui/hygiene/no_implicit_prelude.stderr
index c48c840352fa0..21cecfefd349f 100644
--- a/tests/ui/hygiene/no_implicit_prelude.stderr
+++ b/tests/ui/hygiene/no_implicit_prelude.stderr
@@ -10,7 +10,8 @@ LL |         Vec::new();
    = note: this error originates in the macro `::bar::m` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider importing this struct
    |
-LL |     use std::vec::Vec;
+LL +     use std::vec::Vec;
+LL |     pub macro m() { Vec::<i32>::new(); ().clone() }
    |
 
 error[E0599]: no method named `clone` found for unit type `()` in the current scope
@@ -26,7 +27,8 @@ LL |         ().clone()
    = note: this error originates in the macro `::bar::m` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use std::clone::Clone;
+LL +     use std::clone::Clone;
+LL |     pub macro m() { Vec::<i32>::new(); ().clone() }
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/hygiene/trait_items.stderr b/tests/ui/hygiene/trait_items.stderr
index 80bdbe0e21e04..60cf6787f82fb 100644
--- a/tests/ui/hygiene/trait_items.stderr
+++ b/tests/ui/hygiene/trait_items.stderr
@@ -14,7 +14,8 @@ LL |     pub macro m() { ().f() }
    = note: this error originates in the macro `::baz::m` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use foo::T;
+LL +     use foo::T;
+LL |     use foo::*;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr
index 3c2c01dc227b9..0d37ea38b58cd 100644
--- a/tests/ui/impl-trait/no-method-suggested-traits.stderr
+++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr
@@ -7,13 +7,17 @@ LL |     1u32.method();
    = help: items from traits can only be used if the trait is in scope
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
-LL | use foo::Bar;
+LL + use foo::Bar;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::Reexported;
+LL + use no_method_suggested_traits::Reexported;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::foo::PubPub;
+LL + use no_method_suggested_traits::foo::PubPub;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::qux::PrivPub;
+LL + use no_method_suggested_traits::qux::PrivPub;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&u32>>` in the current scope
@@ -25,13 +29,17 @@ LL |     std::rc::Rc::new(&mut Box::new(&1u32)).method();
    = help: items from traits can only be used if the trait is in scope
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
-LL | use foo::Bar;
+LL + use foo::Bar;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::Reexported;
+LL + use no_method_suggested_traits::Reexported;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::foo::PubPub;
+LL + use no_method_suggested_traits::foo::PubPub;
+LL | extern crate no_method_suggested_traits;
    |
-LL | use no_method_suggested_traits::qux::PrivPub;
+LL + use no_method_suggested_traits::qux::PrivPub;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for type `char` in the current scope
@@ -46,7 +54,8 @@ LL |     'a'.method();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use foo::Bar;
+LL + use foo::Bar;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in the current scope
@@ -58,7 +67,8 @@ LL |     std::rc::Rc::new(&mut Box::new(&'a')).method();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use foo::Bar;
+LL + use foo::Bar;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for type `i32` in the current scope
@@ -75,7 +85,8 @@ LL |         fn method(&self) {}
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use no_method_suggested_traits::foo::PubPub;
+LL + use no_method_suggested_traits::foo::PubPub;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in the current scope
@@ -87,7 +98,8 @@ LL |     std::rc::Rc::new(&mut Box::new(&1i32)).method();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use no_method_suggested_traits::foo::PubPub;
+LL + use no_method_suggested_traits::foo::PubPub;
+LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Foo` in the current scope
diff --git a/tests/ui/impl-trait/universal_wrong_bounds.stderr b/tests/ui/impl-trait/universal_wrong_bounds.stderr
index 3b1a5e5f4ad00..1561708efba37 100644
--- a/tests/ui/impl-trait/universal_wrong_bounds.stderr
+++ b/tests/ui/impl-trait/universal_wrong_bounds.stderr
@@ -6,7 +6,8 @@ LL | fn wants_debug(g: impl Debug) { }
    |
 help: consider importing this trait instead
    |
-LL | use std::fmt::Debug;
+LL + use std::fmt::Debug;
+LL | use std::fmt::Display;
    |
 
 error[E0404]: expected trait, found derive macro `Debug`
@@ -17,7 +18,8 @@ LL | fn wants_display(g: impl Debug) { }
    |
 help: consider importing this trait instead
    |
-LL | use std::fmt::Debug;
+LL + use std::fmt::Debug;
+LL | use std::fmt::Display;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/glob-resolve1.stderr b/tests/ui/imports/glob-resolve1.stderr
index 3b66a5e315050..6d7ceb25a8fd5 100644
--- a/tests/ui/imports/glob-resolve1.stderr
+++ b/tests/ui/imports/glob-resolve1.stderr
@@ -60,7 +60,8 @@ LL |     import();
    |
 help: consider importing this function
    |
-LL | use other::import;
+LL + use other::import;
+LL | use bar::*;
    |
 
 error[E0412]: cannot find type `A` in this scope
diff --git a/tests/ui/imports/issue-38293.stderr b/tests/ui/imports/issue-38293.stderr
index d2450ab125062..7a3b405a78222 100644
--- a/tests/ui/imports/issue-38293.stderr
+++ b/tests/ui/imports/issue-38293.stderr
@@ -12,7 +12,8 @@ LL |     baz();
    |
 help: consider importing this function instead
    |
-LL | use bar::baz;
+LL + use bar::baz;
+LL | use foo::f::{self};
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/issue-4366-2.stderr b/tests/ui/imports/issue-4366-2.stderr
index 4c94634ee60f7..d8539f9a9d4fd 100644
--- a/tests/ui/imports/issue-4366-2.stderr
+++ b/tests/ui/imports/issue-4366-2.stderr
@@ -18,7 +18,8 @@ LL |     foo();
    |
 help: consider importing this function instead
    |
-LL | use foo::foo;
+LL + use foo::foo;
+LL | use m1::*;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/issue-4366.stderr b/tests/ui/imports/issue-4366.stderr
index 469ea93e90468..724db83e99ada 100644
--- a/tests/ui/imports/issue-4366.stderr
+++ b/tests/ui/imports/issue-4366.stderr
@@ -6,7 +6,8 @@ LL |         fn sub() -> isize { foo(); 1 }
    |
 help: consider importing this function
    |
-LL |         use foo::foo;
+LL +         use foo::foo;
+LL |         use a::b::*;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/imports/overlapping_pub_trait.stderr b/tests/ui/imports/overlapping_pub_trait.stderr
index d0c845a5e523f..268709e11b67c 100644
--- a/tests/ui/imports/overlapping_pub_trait.stderr
+++ b/tests/ui/imports/overlapping_pub_trait.stderr
@@ -12,7 +12,8 @@ LL |     pub trait Tr { fn method(&self); }
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use overlapping_pub_trait_source::m::Tr;
+LL + use overlapping_pub_trait_source::m::Tr;
+LL | extern crate overlapping_pub_trait_source;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/imports/unnamed_pub_trait.stderr b/tests/ui/imports/unnamed_pub_trait.stderr
index 319dfd7e1b28b..47fa6d3a39881 100644
--- a/tests/ui/imports/unnamed_pub_trait.stderr
+++ b/tests/ui/imports/unnamed_pub_trait.stderr
@@ -12,7 +12,8 @@ LL |     pub trait Tr { fn method(&self); }
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use unnamed_pub_trait_source::prelude::*; // trait Tr
+LL + use unnamed_pub_trait_source::prelude::*; // trait Tr
+LL | extern crate unnamed_pub_trait_source;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/internal/internal-unstable-const.stderr b/tests/ui/internal/internal-unstable-const.stderr
index 37d2ea6d2dc45..5c63992d81985 100644
--- a/tests/ui/internal/internal-unstable-const.stderr
+++ b/tests/ui/internal/internal-unstable-const.stderr
@@ -6,11 +6,13 @@ LL |     1.0 + 1.0
    |
 help: if it is not part of the public API, make this function unstably const
    |
-LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+LL + #[rustc_const_unstable(feature = "...", issue = "...")]
+LL | pub const fn foo() -> f32 {
    |
 help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
    |
-LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+LL | pub const fn foo() -> f32 {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-10465.stderr b/tests/ui/issues/issue-10465.stderr
index 0ccf69dc06076..9941e14a94e06 100644
--- a/tests/ui/issues/issue-10465.stderr
+++ b/tests/ui/issues/issue-10465.stderr
@@ -7,7 +7,8 @@ LL |             b.foo();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |         use a::A;
+LL +         use a::A;
+LL |         use b::B;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-17546.stderr b/tests/ui/issues/issue-17546.stderr
index 81592320a2791..23a12fa167b7f 100644
--- a/tests/ui/issues/issue-17546.stderr
+++ b/tests/ui/issues/issue-17546.stderr
@@ -24,13 +24,17 @@ LL |     fn new() -> Result<foo::MyEnum, String> {
    |
 help: consider importing one of these items instead
    |
-LL |     use std::fmt::Result;
+LL +     use std::fmt::Result;
+LL |     use foo::MyEnum::Result;
    |
-LL |     use std::io::Result;
+LL +     use std::io::Result;
+LL |     use foo::MyEnum::Result;
    |
-LL |     use std::result::Result;
+LL +     use std::result::Result;
+LL |     use foo::MyEnum::Result;
    |
-LL |     use std::thread::Result;
+LL +     use std::thread::Result;
+LL |     use foo::MyEnum::Result;
    |
 
 error[E0573]: expected type, found variant `Result`
@@ -41,13 +45,17 @@ LL | fn new() -> Result<foo::MyEnum, String> {
    |
 help: consider importing one of these items instead
    |
-LL | use std::fmt::Result;
+LL + use std::fmt::Result;
+LL | use foo::MyEnum::Result;
    |
-LL | use std::io::Result;
+LL + use std::io::Result;
+LL | use foo::MyEnum::Result;
    |
-LL | use std::result::Result;
+LL + use std::result::Result;
+LL | use foo::MyEnum::Result;
    |
-LL | use std::thread::Result;
+LL + use std::thread::Result;
+LL | use foo::MyEnum::Result;
    |
 
 error[E0573]: expected type, found variant `NoResult`
diff --git a/tests/ui/issues/issue-20162.stderr b/tests/ui/issues/issue-20162.stderr
index 1c5b76fbfc10b..ebdf2528fe1f2 100644
--- a/tests/ui/issues/issue-20162.stderr
+++ b/tests/ui/issues/issue-20162.stderr
@@ -8,7 +8,8 @@ note: required by a bound in `slice::<impl [T]>::sort`
   --> $SRC_DIR/alloc/src/slice.rs:LL:COL
 help: consider annotating `X` with `#[derive(Ord)]`
    |
-LL | #[derive(Ord)]
+LL + #[derive(Ord)]
+LL | struct X { x: i32 }
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-21160.stderr b/tests/ui/issues/issue-21160.stderr
index 266749376eb05..b39a3aad37198 100644
--- a/tests/ui/issues/issue-21160.stderr
+++ b/tests/ui/issues/issue-21160.stderr
@@ -9,7 +9,8 @@ LL | struct Foo(Bar);
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Bar` with `#[derive(Hash)]`
    |
-LL | #[derive(Hash)]
+LL + #[derive(Hash)]
+LL | struct Bar;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-35976.unimported.stderr b/tests/ui/issues/issue-35976.unimported.stderr
index 5d61bb8ea3799..8a3e2fcd08333 100644
--- a/tests/ui/issues/issue-35976.unimported.stderr
+++ b/tests/ui/issues/issue-35976.unimported.stderr
@@ -9,7 +9,8 @@ LL |     arg.wait();
    |
 help: another candidate was found in the following trait, perhaps add a `use` for it:
    |
-LL | use private::Future;
+LL + use private::Future;
+LL | mod private {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-37534.stderr b/tests/ui/issues/issue-37534.stderr
index 895479986f1d1..8449eb9c6925a 100644
--- a/tests/ui/issues/issue-37534.stderr
+++ b/tests/ui/issues/issue-37534.stderr
@@ -6,7 +6,8 @@ LL | struct Foo<T: ?Hash> { }
    |
 help: consider importing this trait instead
    |
-LL | use std::hash::Hash;
+LL + use std::hash::Hash;
+LL | struct Foo<T: ?Hash> { }
    |
 
 warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
diff --git a/tests/ui/issues/issue-39175.stderr b/tests/ui/issues/issue-39175.stderr
index afceae82e68be..19e7f5162a77c 100644
--- a/tests/ui/issues/issue-39175.stderr
+++ b/tests/ui/issues/issue-39175.stderr
@@ -7,7 +7,8 @@ LL |     Command::new("echo").arg("hello").exec();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use std::os::unix::process::CommandExt;
+LL + use std::os::unix::process::CommandExt;
+LL | use std::process::Command;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-56175.stderr b/tests/ui/issues/issue-56175.stderr
index 013a440ed0457..bedbaef29b9c4 100644
--- a/tests/ui/issues/issue-56175.stderr
+++ b/tests/ui/issues/issue-56175.stderr
@@ -12,7 +12,8 @@ LL |         fn trait_method(&self) {
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use reexported_trait::Trait;
+LL + use reexported_trait::Trait;
+LL | fn main() {
    |
 
 error[E0599]: no method named `trait_method_b` found for struct `FooStruct` in the current scope
@@ -29,7 +30,8 @@ LL |         fn trait_method_b(&self) {
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use reexported_trait::TraitBRename;
+LL + use reexported_trait::TraitBRename;
+LL | fn main() {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/issues/issue-62375.stderr b/tests/ui/issues/issue-62375.stderr
index 478e025bed230..a6fd3700edda8 100644
--- a/tests/ui/issues/issue-62375.stderr
+++ b/tests/ui/issues/issue-62375.stderr
@@ -13,7 +13,8 @@ LL | enum A {
    | ^^^^^^ must implement `PartialEq<_>`
 help: consider annotating `A` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | enum A {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-77919.stderr b/tests/ui/issues/issue-77919.stderr
index d154bfe0cb553..1f3f6cb33c7fb 100644
--- a/tests/ui/issues/issue-77919.stderr
+++ b/tests/ui/issues/issue-77919.stderr
@@ -6,7 +6,8 @@ LL |     _n: PhantomData,
    |
 help: consider importing this struct
    |
-LL | use std::marker::PhantomData;
+LL + use std::marker::PhantomData;
+LL | fn main() {
    |
 
 error[E0412]: cannot find type `VAL` in this scope
diff --git a/tests/ui/kindck/kindck-impl-type-params.stderr b/tests/ui/kindck/kindck-impl-type-params.stderr
index 6fd1fc3f7a1aa..efb25bf83e1df 100644
--- a/tests/ui/kindck/kindck-impl-type-params.stderr
+++ b/tests/ui/kindck/kindck-impl-type-params.stderr
@@ -107,7 +107,8 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
    = note: required for the cast from `S<Foo>` to the object type `dyn Gettable<Foo>`
 help: consider annotating `Foo` with `#[derive(Copy)]`
    |
-LL |     #[derive(Copy)]
+LL +     #[derive(Copy)]
+LL |     struct Foo; // does not impl Copy
    |
 
 error: aborting due to 6 previous errors
diff --git a/tests/ui/layout/issue-84108.stderr b/tests/ui/layout/issue-84108.stderr
index 36be642411009..cdc21df79a7e5 100644
--- a/tests/ui/layout/issue-84108.stderr
+++ b/tests/ui/layout/issue-84108.stderr
@@ -6,7 +6,8 @@ LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
    |
 help: consider importing this struct
    |
-LL | use std::ffi::OsStr;
+LL + use std::ffi::OsStr;
+LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
    |
 
 error[E0412]: cannot find type `Path` in this scope
@@ -17,7 +18,8 @@ LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
    |
 help: consider importing this struct
    |
-LL | use std::path::Path;
+LL + use std::path::Path;
+LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
    |
 
 error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
diff --git a/tests/ui/macros/issue-100199.stderr b/tests/ui/macros/issue-100199.stderr
index 2cb45dc12473e..ab6bc08b5f7c5 100644
--- a/tests/ui/macros/issue-100199.stderr
+++ b/tests/ui/macros/issue-100199.stderr
@@ -7,7 +7,8 @@ LL | #[issue_100199::struct_with_bound]
    = note: this error originates in the attribute macro `issue_100199::struct_with_bound` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider importing this trait
    |
-LL | use traits::MyTrait;
+LL + use traits::MyTrait;
+LL | #[issue_100199::struct_with_bound]
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/macros/macro-outer-attributes.stderr b/tests/ui/macros/macro-outer-attributes.stderr
index 4ea760ab82b9c..cfd1c7739ba4c 100644
--- a/tests/ui/macros/macro-outer-attributes.stderr
+++ b/tests/ui/macros/macro-outer-attributes.stderr
@@ -6,7 +6,8 @@ LL |     a::bar();
    |
 help: consider importing this function
    |
-LL | use b::bar;
+LL + use b::bar;
+LL | macro_rules! test { ($nm:ident,
    |
 help: if you import `bar`, refer to it directly
    |
diff --git a/tests/ui/malformed/malformed-derive-entry.stderr b/tests/ui/malformed/malformed-derive-entry.stderr
index 6ff6fbabb4a5f..3059d75d718a5 100644
--- a/tests/ui/malformed/malformed-derive-entry.stderr
+++ b/tests/ui/malformed/malformed-derive-entry.stderr
@@ -27,7 +27,8 @@ note: required by a bound in `Copy`
    = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Test1` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Test1;
    |
 
 error[E0277]: the trait bound `Test2: Clone` is not satisfied
@@ -41,7 +42,8 @@ note: required by a bound in `Copy`
    = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Test2` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Test2;
    |
 
 error: aborting due to 5 previous errors
diff --git a/tests/ui/mismatched_types/method-help-unsatisfied-bound.stderr b/tests/ui/mismatched_types/method-help-unsatisfied-bound.stderr
index d3b7525072ff4..9dab3e5225570 100644
--- a/tests/ui/mismatched_types/method-help-unsatisfied-bound.stderr
+++ b/tests/ui/mismatched_types/method-help-unsatisfied-bound.stderr
@@ -10,7 +10,8 @@ note: required by a bound in `Result::<T, E>::unwrap`
   --> $SRC_DIR/core/src/result.rs:LL:COL
 help: consider annotating `Foo` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Foo;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/modules/issue-107649.stderr b/tests/ui/modules/issue-107649.stderr
index 1cea71f2829fd..38a910b57b474 100644
--- a/tests/ui/modules/issue-107649.stderr
+++ b/tests/ui/modules/issue-107649.stderr
@@ -10,7 +10,8 @@ error[E0277]: `Dummy` doesn't implement `Debug`
 help: consider annotating `Dummy` with `#[derive(Debug)]`
    --> $DIR/auxiliary/dummy_lib.rs:2:1
     |
-2   | #[derive(Debug)]
+2   + #[derive(Debug)]
+3   | #[path = "auxiliary/dummy_lib.rs"]
     |
 
 error: aborting due to previous error
diff --git a/tests/ui/namespace/namespace-mix.stderr b/tests/ui/namespace/namespace-mix.stderr
index cb72d4a1c4292..216548180bc50 100644
--- a/tests/ui/namespace/namespace-mix.stderr
+++ b/tests/ui/namespace/namespace-mix.stderr
@@ -14,9 +14,11 @@ LL |     check(m1::TS);
    |               ~~
 help: consider importing one of these items instead
    |
-LL | use m2::S;
+LL + use m2::S;
+LL | use namespace_mix::*;
    |
-LL | use xm2::S;
+LL + use xm2::S;
+LL | use namespace_mix::*;
    |
 help: if you import `S`, refer to it directly
    |
@@ -42,9 +44,11 @@ LL |     check(xm1::TS);
    |                ~~
 help: consider importing one of these items instead
    |
-LL | use m2::S;
+LL + use m2::S;
+LL | use namespace_mix::*;
    |
-LL | use xm2::S;
+LL + use xm2::S;
+LL | use namespace_mix::*;
    |
 help: if you import `S`, refer to it directly
    |
@@ -68,9 +72,11 @@ LL |     check(m7::TV);
    |               ~~
 help: consider importing one of these items instead
    |
-LL | use m8::V;
+LL + use m8::V;
+LL | use namespace_mix::*;
    |
-LL | use xm8::V;
+LL + use xm8::V;
+LL | use namespace_mix::*;
    |
 help: if you import `V`, refer to it directly
    |
@@ -96,9 +102,11 @@ LL |     check(xm7::TV);
    |                ~~
 help: consider importing one of these items instead
    |
-LL | use m8::V;
+LL + use m8::V;
+LL | use namespace_mix::*;
    |
-LL | use xm8::V;
+LL + use xm8::V;
+LL | use namespace_mix::*;
    |
 help: if you import `V`, refer to it directly
    |
diff --git a/tests/ui/not-clone-closure.stderr b/tests/ui/not-clone-closure.stderr
index 37d94cf0ebd8c..db9307c61853f 100644
--- a/tests/ui/not-clone-closure.stderr
+++ b/tests/ui/not-clone-closure.stderr
@@ -14,7 +14,8 @@ LL |     let hello = move || {
    |                 ^^^^^^^
 help: consider annotating `S` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct S(i32);
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/on-unimplemented/no-debug.stderr b/tests/ui/on-unimplemented/no-debug.stderr
index 1035da54d8a77..97d67dbd82e77 100644
--- a/tests/ui/on-unimplemented/no-debug.stderr
+++ b/tests/ui/on-unimplemented/no-debug.stderr
@@ -9,7 +9,8 @@ LL |     println!("{:?} {:?}", Foo, Bar);
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Foo` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct Foo;
    |
 
 error[E0277]: `Bar` doesn't implement `Debug`
diff --git a/tests/ui/parser/circular_modules_main.stderr b/tests/ui/parser/circular_modules_main.stderr
index 1094def6014a9..2804c6ebf5097 100644
--- a/tests/ui/parser/circular_modules_main.stderr
+++ b/tests/ui/parser/circular_modules_main.stderr
@@ -12,7 +12,8 @@ LL |     println!("{}", circular_modules_main::hi_str());
    |
 help: consider importing this function
    |
-LL | use hi_str;
+LL + use hi_str;
+LL | #[path = "circular_modules_main.rs"]
    |
 help: if you import `hi_str`, refer to it directly
    |
diff --git a/tests/ui/privacy/privacy-ns1.stderr b/tests/ui/privacy/privacy-ns1.stderr
index 91bc84e70ac51..fe3e4a78a84b0 100644
--- a/tests/ui/privacy/privacy-ns1.stderr
+++ b/tests/ui/privacy/privacy-ns1.stderr
@@ -13,7 +13,8 @@ LL |     Baz();
    |     ~~~
 help: consider importing this function instead
    |
-LL | use foo2::Bar;
+LL + use foo2::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0425]: cannot find function, tuple struct or tuple variant `Bar` in this scope
@@ -31,7 +32,8 @@ LL |     Baz();
    |     ~~~
 help: consider importing this function
    |
-LL | use foo2::Bar;
+LL + use foo2::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0412]: cannot find type `Bar` in this scope
@@ -49,7 +51,8 @@ LL |     let _x: Box<Baz>;
    |                 ~~~
 help: consider importing this trait
    |
-LL | use foo1::Bar;
+LL + use foo1::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0747]: constant provided when a type was expected
diff --git a/tests/ui/privacy/privacy-ns2.stderr b/tests/ui/privacy/privacy-ns2.stderr
index 904e9013f94a8..73a24bd20f33c 100644
--- a/tests/ui/privacy/privacy-ns2.stderr
+++ b/tests/ui/privacy/privacy-ns2.stderr
@@ -6,7 +6,8 @@ LL |     Bar();
    |
 help: consider importing this function instead
    |
-LL | use foo2::Bar;
+LL + use foo2::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0423]: expected function, tuple struct or tuple variant, found trait `Bar`
@@ -24,7 +25,8 @@ LL |     Baz();
    |     ~~~
 help: consider importing this function instead
    |
-LL | use foo2::Bar;
+LL + use foo2::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0573]: expected type, found function `Bar`
@@ -39,7 +41,8 @@ LL |     let _x = Bar();
    |            ~
 help: consider importing this trait instead
    |
-LL | use foo1::Bar;
+LL + use foo1::Bar;
+LL | pub mod foo1 {
    |
 
 error[E0603]: trait `Bar` is private
diff --git a/tests/ui/proc-macro/amputate-span.stderr b/tests/ui/proc-macro/amputate-span.stderr
index ab46704114460..fa83707e79d5b 100644
--- a/tests/ui/proc-macro/amputate-span.stderr
+++ b/tests/ui/proc-macro/amputate-span.stderr
@@ -6,7 +6,8 @@ LL |     Command::new("git");
    |
 help: consider importing this struct
    |
-LL | use std::process::Command;
+LL + use std::process::Command;
+LL | #[amputate_span::drop_first_token]
    |
 
 error[E0433]: failed to resolve: use of undeclared type `Command`
@@ -17,7 +18,8 @@ LL |         Command::new("git");
    |
 help: consider importing this struct
    |
-LL |     use std::process::Command;
+LL +     use std::process::Command;
+LL |     #[amputate_span::drop_first_token]
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/proc-macro/attributes-on-modules-fail.stderr b/tests/ui/proc-macro/attributes-on-modules-fail.stderr
index bb6cbb6984d7c..a0ab9999c088c 100644
--- a/tests/ui/proc-macro/attributes-on-modules-fail.stderr
+++ b/tests/ui/proc-macro/attributes-on-modules-fail.stderr
@@ -50,7 +50,8 @@ LL |     type A = Y;
    |
 help: consider importing this struct
    |
-LL |     use Y;
+LL +     use Y;
+LL |     pub struct X;
    |
 
 error[E0412]: cannot find type `X` in this scope
@@ -61,7 +62,8 @@ LL | type A = X;
    |
 help: consider importing this struct
    |
-LL | use m::X;
+LL + use m::X;
+LL | #[macro_use]
    |
 
 error: aborting due to 7 previous errors
diff --git a/tests/ui/repeat-expr/repeat-to-run-dtor-twice.stderr b/tests/ui/repeat-expr/repeat-to-run-dtor-twice.stderr
index 36b93616375e0..1bf8e6e062f2e 100644
--- a/tests/ui/repeat-expr/repeat-to-run-dtor-twice.stderr
+++ b/tests/ui/repeat-expr/repeat-to-run-dtor-twice.stderr
@@ -7,7 +7,8 @@ LL |     let _ = [ a; 5 ];
    = note: the `Copy` trait is required because this value will be copied for each element of the array
 help: consider annotating `Foo` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct Foo {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/crate-in-paths.stderr b/tests/ui/resolve/crate-in-paths.stderr
index b7cf4950759e3..45ecf5a59adfe 100644
--- a/tests/ui/resolve/crate-in-paths.stderr
+++ b/tests/ui/resolve/crate-in-paths.stderr
@@ -6,7 +6,8 @@ LL |     Foo;
    |
 help: consider importing this unit struct
    |
-LL | use crate::bar::Foo;
+LL + use crate::bar::Foo;
+LL | mod bar {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/enums-are-namespaced-xc.stderr b/tests/ui/resolve/enums-are-namespaced-xc.stderr
index 6448e596d56cf..efebf15684b90 100644
--- a/tests/ui/resolve/enums-are-namespaced-xc.stderr
+++ b/tests/ui/resolve/enums-are-namespaced-xc.stderr
@@ -6,7 +6,8 @@ LL |     let _ = namespaced_enums::A;
    |
 help: consider importing this unit variant
    |
-LL | use namespaced_enums::Foo::A;
+LL + use namespaced_enums::Foo::A;
+LL | extern crate namespaced_enums;
    |
 help: if you import `A`, refer to it directly
    |
@@ -22,7 +23,8 @@ LL |     let _ = namespaced_enums::B(10);
    |
 help: consider importing this tuple variant
    |
-LL | use namespaced_enums::Foo::B;
+LL + use namespaced_enums::Foo::B;
+LL | extern crate namespaced_enums;
    |
 help: if you import `B`, refer to it directly
    |
@@ -38,7 +40,8 @@ LL |     let _ = namespaced_enums::C { a: 10 };
    |
 help: consider importing this variant
    |
-LL | use namespaced_enums::Foo::C;
+LL + use namespaced_enums::Foo::C;
+LL | extern crate namespaced_enums;
    |
 help: if you import `C`, refer to it directly
    |
diff --git a/tests/ui/resolve/filter-intrinsics.stderr b/tests/ui/resolve/filter-intrinsics.stderr
index 955070891fbbe..3b4a09a25e7f1 100644
--- a/tests/ui/resolve/filter-intrinsics.stderr
+++ b/tests/ui/resolve/filter-intrinsics.stderr
@@ -6,7 +6,8 @@ LL |     let _ = size_of::<usize>();
    |
 help: consider importing this function
    |
-LL | use std::mem::size_of;
+LL + use std::mem::size_of;
+LL | fn main() {
    |
 
 error[E0425]: cannot find function `fabsf64` in this scope
@@ -17,7 +18,8 @@ LL |     let _ = fabsf64(1.0);
    |
 help: consider importing this function
    |
-LL | use std::intrinsics::fabsf64;
+LL + use std::intrinsics::fabsf64;
+LL | fn main() {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/resolve/issue-102946.stderr b/tests/ui/resolve/issue-102946.stderr
index 65be0258e6dba..7384384921407 100644
--- a/tests/ui/resolve/issue-102946.stderr
+++ b/tests/ui/resolve/issue-102946.stderr
@@ -6,7 +6,8 @@ LL | impl Error for str::Utf8Error {
    |
 help: consider importing this trait
    |
-LL | use std::error::Error;
+LL + use std::error::Error;
+LL | impl Error for str::Utf8Error {
    |
 
 error[E0223]: ambiguous associated type
diff --git a/tests/ui/resolve/issue-16058.stderr b/tests/ui/resolve/issue-16058.stderr
index c47d22cef5f6c..65dba047234a2 100644
--- a/tests/ui/resolve/issue-16058.stderr
+++ b/tests/ui/resolve/issue-16058.stderr
@@ -6,11 +6,14 @@ LL |         Result {
    |
 help: consider importing one of these items instead
    |
-LL | use std::fmt::Result;
+LL + use std::fmt::Result;
+LL | pub struct GslResult {
    |
-LL | use std::io::Result;
+LL + use std::io::Result;
+LL | pub struct GslResult {
    |
-LL | use std::thread::Result;
+LL + use std::thread::Result;
+LL | pub struct GslResult {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-17518.stderr b/tests/ui/resolve/issue-17518.stderr
index 034d0d01bfb80..19b59b841e042 100644
--- a/tests/ui/resolve/issue-17518.stderr
+++ b/tests/ui/resolve/issue-17518.stderr
@@ -6,7 +6,8 @@ LL |     E { name: "foobar" };
    |
 help: consider importing this variant
    |
-LL | use SomeEnum::E;
+LL + use SomeEnum::E;
+LL | enum SomeEnum {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-1.stderr b/tests/ui/resolve/issue-21221-1.stderr
index 538eeead9fc9d..836ea564f4ee1 100644
--- a/tests/ui/resolve/issue-21221-1.stderr
+++ b/tests/ui/resolve/issue-21221-1.stderr
@@ -6,11 +6,14 @@ LL | impl Mul for Foo {
    |
 help: consider importing one of these items
    |
-LL | use mul1::Mul;
+LL + use mul1::Mul;
+LL | mod mul1 {
    |
-LL | use mul2::Mul;
+LL + use mul2::Mul;
+LL | mod mul1 {
    |
-LL | use std::ops::Mul;
+LL + use std::ops::Mul;
+LL | mod mul1 {
    |
 
 error[E0412]: cannot find type `Mul` in this scope
@@ -21,11 +24,14 @@ LL | fn getMul() -> Mul {
    |
 help: consider importing one of these items
    |
-LL | use mul1::Mul;
+LL + use mul1::Mul;
+LL | mod mul1 {
    |
-LL | use mul2::Mul;
+LL + use mul2::Mul;
+LL | mod mul1 {
    |
-LL | use std::ops::Mul;
+LL + use std::ops::Mul;
+LL | mod mul1 {
    |
 
 error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
@@ -42,7 +48,8 @@ LL | impl Div for Foo {
    |
 help: consider importing this trait
    |
-LL | use std::ops::Div;
+LL + use std::ops::Div;
+LL | mod mul1 {
    |
 
 error: aborting due to 4 previous errors
diff --git a/tests/ui/resolve/issue-21221-2.stderr b/tests/ui/resolve/issue-21221-2.stderr
index d4fd7cb1257e0..e88274e6c60b3 100644
--- a/tests/ui/resolve/issue-21221-2.stderr
+++ b/tests/ui/resolve/issue-21221-2.stderr
@@ -6,9 +6,11 @@ LL | impl T for Foo { }
    |
 help: consider importing one of these items
    |
-LL | use baz::T;
+LL + use baz::T;
+LL | pub mod foo {
    |
-LL | use foo::bar::T;
+LL + use foo::bar::T;
+LL | pub mod foo {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-3.stderr b/tests/ui/resolve/issue-21221-3.stderr
index f12e5b09bacd0..e02eaec05e3ec 100644
--- a/tests/ui/resolve/issue-21221-3.stderr
+++ b/tests/ui/resolve/issue-21221-3.stderr
@@ -6,7 +6,8 @@ LL | impl OuterTrait for Foo {}
    |
 help: consider importing this trait
    |
-LL | use issue_21221_3::outer::OuterTrait;
+LL + use issue_21221_3::outer::OuterTrait;
+LL | extern crate issue_21221_3;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-4.stderr b/tests/ui/resolve/issue-21221-4.stderr
index fc15444d0c0fb..e8c38ed6acf08 100644
--- a/tests/ui/resolve/issue-21221-4.stderr
+++ b/tests/ui/resolve/issue-21221-4.stderr
@@ -6,7 +6,8 @@ LL | impl T for Foo {}
    |
 help: consider importing this trait
    |
-LL | use issue_21221_4::T;
+LL + use issue_21221_4::T;
+LL | extern crate issue_21221_4;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-2356.stderr b/tests/ui/resolve/issue-2356.stderr
index 36f3da7c95537..ed820f15c83e5 100644
--- a/tests/ui/resolve/issue-2356.stderr
+++ b/tests/ui/resolve/issue-2356.stderr
@@ -10,7 +10,8 @@ LL |     Self::default();
    |     ~~~~~~~~~~~~~
 help: consider importing this function
    |
-LL | use std::default::default;
+LL + use std::default::default;
+LL | trait Groom {
    |
 
 error[E0425]: cannot find value `whiskers` in this scope
diff --git a/tests/ui/resolve/issue-26545.stderr b/tests/ui/resolve/issue-26545.stderr
index d3c86692501d6..2b98b5b8a7bf5 100644
--- a/tests/ui/resolve/issue-26545.stderr
+++ b/tests/ui/resolve/issue-26545.stderr
@@ -6,7 +6,8 @@ LL |         B(());
    |
 help: consider importing this tuple struct
    |
-LL |     use foo::B;
+LL +     use foo::B;
+LL |     fn foo() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-35675.stderr b/tests/ui/resolve/issue-35675.stderr
index 4a06196d548e3..d285614537158 100644
--- a/tests/ui/resolve/issue-35675.stderr
+++ b/tests/ui/resolve/issue-35675.stderr
@@ -17,7 +17,8 @@ LL |     Apple(5)
    |
 help: consider importing this tuple variant
    |
-LL | use Fruit::Apple;
+LL + use Fruit::Apple;
+LL | enum Fruit {
    |
 
 error[E0573]: expected type, found variant `Fruit::Apple`
@@ -37,7 +38,8 @@ LL |     Apple(5)
    |
 help: consider importing this tuple variant
    |
-LL | use Fruit::Apple;
+LL + use Fruit::Apple;
+LL | enum Fruit {
    |
 
 error[E0573]: expected type, found variant `Ok`
diff --git a/tests/ui/resolve/issue-3907.stderr b/tests/ui/resolve/issue-3907.stderr
index 6fc61cae84339..50ad668f8dbf6 100644
--- a/tests/ui/resolve/issue-3907.stderr
+++ b/tests/ui/resolve/issue-3907.stderr
@@ -10,7 +10,8 @@ LL | trait Foo = dyn issue_3907::Foo;
    |
 help: consider importing this trait instead
    |
-LL | use issue_3907::Foo;
+LL + use issue_3907::Foo;
+LL | extern crate issue_3907;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-50599.stderr b/tests/ui/resolve/issue-50599.stderr
index b07482c83ccc2..548d215b00acd 100644
--- a/tests/ui/resolve/issue-50599.stderr
+++ b/tests/ui/resolve/issue-50599.stderr
@@ -6,9 +6,11 @@ LL |     const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize;
    |
 help: consider importing one of these items
    |
-LL | use std::f32::consts::LOG10_2;
+LL + use std::f32::consts::LOG10_2;
+LL | fn main() {
    |
-LL | use std::f64::consts::LOG10_2;
+LL + use std::f64::consts::LOG10_2;
+LL | fn main() {
    |
 help: if you import `LOG10_2`, refer to it directly
    |
diff --git a/tests/ui/resolve/issue-73427.stderr b/tests/ui/resolve/issue-73427.stderr
index 4af5f29d8093d..5a663ae79bcb1 100644
--- a/tests/ui/resolve/issue-73427.stderr
+++ b/tests/ui/resolve/issue-73427.stderr
@@ -107,9 +107,11 @@ LL |     (E::TupleWithFields(/* fields */)).foo();
    |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 help: consider importing one of these items instead
    |
-LL | use std::f32::consts::E;
+LL + use std::f32::consts::E;
+LL | enum A {
    |
-LL | use std::f64::consts::E;
+LL + use std::f64::consts::E;
+LL | enum A {
    |
 
 error[E0532]: expected tuple struct or tuple variant, found enum `A`
diff --git a/tests/ui/resolve/issue-90113.stderr b/tests/ui/resolve/issue-90113.stderr
index 1b78720571c65..a9d4b573f110b 100644
--- a/tests/ui/resolve/issue-90113.stderr
+++ b/tests/ui/resolve/issue-90113.stderr
@@ -6,7 +6,8 @@ LL |         Cons(..) => {}
    |
 help: consider importing this tuple variant
    |
-LL | use list::List::Cons;
+LL + use list::List::Cons;
+LL | mod list {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/missing-in-namespace.stderr b/tests/ui/resolve/missing-in-namespace.stderr
index fc925ba3b6a8f..66f40102a3ed3 100644
--- a/tests/ui/resolve/missing-in-namespace.stderr
+++ b/tests/ui/resolve/missing-in-namespace.stderr
@@ -6,7 +6,8 @@ LL |     let _map = std::hahmap::HashMap::new();
    |
 help: consider importing this struct
    |
-LL | use std::collections::HashMap;
+LL + use std::collections::HashMap;
+LL | fn main() {
    |
 help: if you import `HashMap`, refer to it directly
    |
diff --git a/tests/ui/resolve/no-implicit-prelude-nested.stderr b/tests/ui/resolve/no-implicit-prelude-nested.stderr
index 198b630c52c8f..4df6c31d31644 100644
--- a/tests/ui/resolve/no-implicit-prelude-nested.stderr
+++ b/tests/ui/resolve/no-implicit-prelude-nested.stderr
@@ -6,7 +6,8 @@ LL |         impl Add for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::ops::Add;
+LL +         use std::ops::Add;
+LL |         struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -17,7 +18,8 @@ LL |         impl Clone for Test {}
    |
 help: consider importing this trait instead
    |
-LL |         use std::clone::Clone;
+LL +         use std::clone::Clone;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -28,7 +30,8 @@ LL |         impl Iterator for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::iter::Iterator;
+LL +         use std::iter::Iterator;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -39,7 +42,8 @@ LL |         impl ToString for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::string::ToString;
+LL +         use std::string::ToString;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -56,7 +60,8 @@ LL |             drop(2)
    |
 help: consider importing this function
    |
-LL |         use std::mem::drop;
+LL +         use std::mem::drop;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Add` in this scope
@@ -67,7 +72,8 @@ LL |     impl Add for Test {}
    |
 help: consider importing this trait
    |
-LL |     use std::ops::Add;
+LL +     use std::ops::Add;
+LL |     mod baz {
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -78,7 +84,8 @@ LL |     impl Clone for Test {}
    |
 help: consider importing this trait instead
    |
-LL |     use std::clone::Clone;
+LL +     use std::clone::Clone;
+LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -89,7 +96,8 @@ LL |     impl Iterator for Test {}
    |
 help: consider importing this trait
    |
-LL |     use std::iter::Iterator;
+LL +     use std::iter::Iterator;
+LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -100,7 +108,8 @@ LL |     impl ToString for Test {}
    |
 help: consider importing this trait
    |
-LL |     use std::string::ToString;
+LL +     use std::string::ToString;
+LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -117,7 +126,8 @@ LL |         drop(2)
    |
 help: consider importing this function
    |
-LL |     use std::mem::drop;
+LL +     use std::mem::drop;
+LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Add` in this scope
@@ -128,7 +138,8 @@ LL |         impl Add for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::ops::Add;
+LL +         use std::ops::Add;
+LL |         struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -139,7 +150,8 @@ LL |         impl Clone for Test {}
    |
 help: consider importing this trait instead
    |
-LL |         use std::clone::Clone;
+LL +         use std::clone::Clone;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -150,7 +162,8 @@ LL |         impl Iterator for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::iter::Iterator;
+LL +         use std::iter::Iterator;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -161,7 +174,8 @@ LL |         impl ToString for Test {}
    |
 help: consider importing this trait
    |
-LL |         use std::string::ToString;
+LL +         use std::string::ToString;
+LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -178,7 +192,8 @@ LL |             drop(2)
    |
 help: consider importing this function
    |
-LL |         use std::mem::drop;
+LL +         use std::mem::drop;
+LL |         struct Test;
    |
 
 error: aborting due to 18 previous errors
diff --git a/tests/ui/resolve/no-implicit-prelude.stderr b/tests/ui/resolve/no-implicit-prelude.stderr
index 36a9b65b7d161..a8e5f1b69e230 100644
--- a/tests/ui/resolve/no-implicit-prelude.stderr
+++ b/tests/ui/resolve/no-implicit-prelude.stderr
@@ -6,7 +6,8 @@ LL | impl Add for Test {}
    |
 help: consider importing this trait
    |
-LL | use std::ops::Add;
+LL + use std::ops::Add;
+LL | struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -17,7 +18,8 @@ LL | impl Clone for Test {}
    |
 help: consider importing this trait instead
    |
-LL | use std::clone::Clone;
+LL + use std::clone::Clone;
+LL | struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -28,7 +30,8 @@ LL | impl Iterator for Test {}
    |
 help: consider importing this trait
    |
-LL | use std::iter::Iterator;
+LL + use std::iter::Iterator;
+LL | struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -39,7 +42,8 @@ LL | impl ToString for Test {}
    |
 help: consider importing this trait
    |
-LL | use std::string::ToString;
+LL + use std::string::ToString;
+LL | struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -56,7 +60,8 @@ LL |     drop(2)
    |
 help: consider importing this function
    |
-LL | use std::mem::drop;
+LL + use std::mem::drop;
+LL | struct Test;
    |
 
 error: aborting due to 6 previous errors
diff --git a/tests/ui/resolve/privacy-enum-ctor.stderr b/tests/ui/resolve/privacy-enum-ctor.stderr
index 3c051429fd0e9..76dc25539d07d 100644
--- a/tests/ui/resolve/privacy-enum-ctor.stderr
+++ b/tests/ui/resolve/privacy-enum-ctor.stderr
@@ -84,9 +84,11 @@ LL |     let _: E = m::f;
    |                   ~
 help: consider importing one of these items instead
    |
-LL | use std::f32::consts::E;
+LL + use std::f32::consts::E;
+LL | use m::E; // OK, only the type is imported
    |
-LL | use std::f64::consts::E;
+LL + use std::f64::consts::E;
+LL | use m::E; // OK, only the type is imported
    |
 help: if you import `E`, refer to it directly
    |
@@ -121,9 +123,11 @@ LL |     let _: E = (E::Fn(/* fields */));
    |                ~~~~~~~~~~~~~~~~~~~~~
 help: consider importing one of these items instead
    |
-LL | use std::f32::consts::E;
+LL + use std::f32::consts::E;
+LL | use m::E; // OK, only the type is imported
    |
-LL | use std::f64::consts::E;
+LL + use std::f64::consts::E;
+LL | use m::E; // OK, only the type is imported
    |
 
 error[E0412]: cannot find type `Z` in this scope
diff --git a/tests/ui/resolve/resolve-primitive-fallback.stderr b/tests/ui/resolve/resolve-primitive-fallback.stderr
index f803f9da2af1a..2227522d6eab6 100644
--- a/tests/ui/resolve/resolve-primitive-fallback.stderr
+++ b/tests/ui/resolve/resolve-primitive-fallback.stderr
@@ -12,7 +12,8 @@ LL |     let _: ::u8;
    |
 help: consider importing this builtin type
    |
-LL | use std::primitive::u8;
+LL + use std::primitive::u8;
+LL | fn main() {
    |
 help: if you import `u8`, refer to it directly
    |
diff --git a/tests/ui/resolve/use_suggestion.stderr b/tests/ui/resolve/use_suggestion.stderr
index 54ad853831f36..a30dbd954e12b 100644
--- a/tests/ui/resolve/use_suggestion.stderr
+++ b/tests/ui/resolve/use_suggestion.stderr
@@ -6,7 +6,8 @@ LL |     let x1 = HashMap::new();
    |
 help: consider importing this struct
    |
-LL | use std::collections::HashMap;
+LL + use std::collections::HashMap;
+LL | fn main() {
    |
 
 error[E0412]: cannot find type `HashMap` in this scope
@@ -17,7 +18,8 @@ LL |     let y1: HashMap;
    |
 help: consider importing this struct
    |
-LL | use std::collections::HashMap;
+LL + use std::collections::HashMap;
+LL | fn main() {
    |
 
 error[E0412]: cannot find type `GooMap` in this scope
diff --git a/tests/ui/resolve/use_suggestion_placement.stderr b/tests/ui/resolve/use_suggestion_placement.stderr
index 0aadd82f6c292..9288530ad2e8c 100644
--- a/tests/ui/resolve/use_suggestion_placement.stderr
+++ b/tests/ui/resolve/use_suggestion_placement.stderr
@@ -6,7 +6,8 @@ LL |     type Bar = Path;
    |
 help: consider importing this struct
    |
-LL |     use std::path::Path;
+LL +     use std::path::Path;
+LL |     #[derive(Debug)]
    |
 
 error[E0425]: cannot find value `A` in this scope
@@ -17,7 +18,8 @@ LL |     let _ = A;
    |
 help: consider importing this constant
    |
-LL | use m::A;
+LL + use m::A;
+LL | macro_rules! y {
    |
 
 error[E0412]: cannot find type `HashMap` in this scope
@@ -28,7 +30,8 @@ LL |     type Dict<K, V> = HashMap<K, V>;
    |
 help: consider importing this struct
    |
-LL | use std::collections::HashMap;
+LL + use std::collections::HashMap;
+LL | macro_rules! y {
    |
 
 error: aborting due to 3 previous errors
diff --git a/tests/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr b/tests/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr
index d8b5a9e63643d..ce165e6463292 100644
--- a/tests/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr
+++ b/tests/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr
@@ -9,7 +9,8 @@ LL |     let _: NotDebug = dbg!(NotDebug);
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `NotDebug` with `#[derive(Debug)]`
    |
-LL | #[derive(Debug)]
+LL + #[derive(Debug)]
+LL | struct NotDebug;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/rfc-2632-const-trait-impl/const_derives/derive-const-non-const-type.stderr b/tests/ui/rfc-2632-const-trait-impl/const_derives/derive-const-non-const-type.stderr
index 6b6c578bff8ae..653037ef39895 100644
--- a/tests/ui/rfc-2632-const-trait-impl/const_derives/derive-const-non-const-type.stderr
+++ b/tests/ui/rfc-2632-const-trait-impl/const_derives/derive-const-non-const-type.stderr
@@ -16,7 +16,8 @@ LL | pub struct S(A);
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `A` with `#[derive(Default)]`
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | pub struct A;
    |
 
 error[E0015]: cannot call non-const fn `<A as Default>::default` in constant functions
diff --git a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
index 38cd9713d1a13..5450ede822300 100644
--- a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
+++ b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
@@ -6,13 +6,17 @@ LL |     let _d = Drain {};
    |
 help: consider importing one of these items
    |
-LL | use crate::plumbing::Drain;
+LL + use crate::plumbing::Drain;
+LL | mod plumbing {
    |
-LL | use std::collections::binary_heap::Drain;
+LL + use std::collections::binary_heap::Drain;
+LL | mod plumbing {
    |
-LL | use std::collections::hash_map::Drain;
+LL + use std::collections::hash_map::Drain;
+LL | mod plumbing {
    |
-LL | use std::collections::hash_set::Drain;
+LL + use std::collections::hash_set::Drain;
+LL | mod plumbing {
    |
      and 3 other candidates
 
diff --git a/tests/ui/rust-2018/trait-import-suggestions.stderr b/tests/ui/rust-2018/trait-import-suggestions.stderr
index 6454b6045e466..4be5c7b0d0c40 100644
--- a/tests/ui/rust-2018/trait-import-suggestions.stderr
+++ b/tests/ui/rust-2018/trait-import-suggestions.stderr
@@ -10,7 +10,8 @@ LL |         x.foobar();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use crate::foo::foobar::Foobar;
+LL +     use crate::foo::foobar::Foobar;
+LL |     mod foobar {
    |
 
 error[E0599]: no method named `bar` found for type `u32` in the current scope
@@ -25,7 +26,8 @@ LL |     x.bar();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use crate::foo::Bar;
+LL + use crate::foo::Bar;
+LL | mod foo {
    |
 
 error[E0599]: no method named `baz` found for type `u32` in the current scope
@@ -43,7 +45,8 @@ LL |     let y = u32::from_str("33");
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use std::str::FromStr;
+LL + use std::str::FromStr;
+LL | mod foo {
    |
 help: there is an associated function with a similar name
    |
diff --git a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
index b52720ae3d9de..e5e17f22c5f17 100644
--- a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
+++ b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
@@ -10,7 +10,8 @@ LL |     A::deserialize();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use <crate::A as issue_87932_a::Deserialize>::deserialize::_a::Deserialize;
+LL + use <crate::A as issue_87932_a::Deserialize>::deserialize::_a::Deserialize;
+LL | pub struct A {}
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
index 3d21b735aea0a..34bf68e8913f6 100644
--- a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
+++ b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
@@ -8,9 +8,11 @@ LL |         let _: u32 = 3u8.try_into().unwrap();
    = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
-LL |     use crate::m::TryIntoU32;
+LL +     use crate::m::TryIntoU32;
+LL |     use crate::m::AnotherTrick as TryIntoU32;
    |
-LL |     use std::convert::TryInto;
+LL +     use std::convert::TryInto;
+LL |     use crate::m::AnotherTrick as TryIntoU32;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/self/class-missing-self.stderr b/tests/ui/self/class-missing-self.stderr
index 063c3f013c539..2f35b30dbcb0c 100644
--- a/tests/ui/self/class-missing-self.stderr
+++ b/tests/ui/self/class-missing-self.stderr
@@ -16,7 +16,8 @@ LL |       self.sleep();
    |       +++++
 help: consider importing this function
    |
-LL | use std::thread::sleep;
+LL + use std::thread::sleep;
+LL | struct Cat {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr
index c3b9084affdb3..6d7ab27f3e154 100644
--- a/tests/ui/shadowed/shadowed-trait-methods.stderr
+++ b/tests/ui/shadowed/shadowed-trait-methods.stderr
@@ -10,7 +10,8 @@ LL |     ().f()
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use foo::T;
+LL + use foo::T;
+LL | mod foo {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
index 37b2f4138603d..626cc67d9eb93 100644
--- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
+++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
@@ -15,7 +15,8 @@ LL |         interval: Duration,
    |
 help: consider importing this struct
    |
-LL | use std::time::Duration;
+LL + use std::time::Duration;
+LL | fn main() {}
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/span/issue-35987.stderr b/tests/ui/span/issue-35987.stderr
index 057d40ac0cb92..0e64bcb010693 100644
--- a/tests/ui/span/issue-35987.stderr
+++ b/tests/ui/span/issue-35987.stderr
@@ -11,6 +11,7 @@ LL | impl<T: Clone, Add> Add for Foo<T> {
    |
 help: consider importing this trait instead
    |
+LL + use std::ops::Add;
 LL | use std::ops::Add;
    |
 
diff --git a/tests/ui/span/issue-71363.stderr b/tests/ui/span/issue-71363.stderr
index cb5cc320276d8..90b623e89cffa 100644
--- a/tests/ui/span/issue-71363.stderr
+++ b/tests/ui/span/issue-71363.stderr
@@ -21,7 +21,8 @@ note: required by a bound in `std::error::Error`
  --> $SRC_DIR/core/src/error.rs:LL:COL
 help: consider annotating `MyError` with `#[derive(Debug)]`
   |
-3 | #[derive(Debug)]
+3 + #[derive(Debug)]
+4 | struct MyError;
   |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/specialization/issue-59435.stderr b/tests/ui/specialization/issue-59435.stderr
index 2114594066861..e8a12e4d928e1 100644
--- a/tests/ui/specialization/issue-59435.stderr
+++ b/tests/ui/specialization/issue-59435.stderr
@@ -11,7 +11,8 @@ LL |     type MyType: Default;
    |                  ^^^^^^^ required by this bound in `MyTrait::MyType`
 help: consider annotating `MyStruct` with `#[derive(Default)]`
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct MyStruct {}
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/structs/struct-path-alias-bounds.stderr b/tests/ui/structs/struct-path-alias-bounds.stderr
index 266291f62b45d..5b01208c56fbf 100644
--- a/tests/ui/structs/struct-path-alias-bounds.stderr
+++ b/tests/ui/structs/struct-path-alias-bounds.stderr
@@ -11,7 +11,8 @@ LL | struct S<T: Clone> { a: T }
    |             ^^^^^ required by this bound in `S`
 help: consider annotating `NoClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NoClone;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr b/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr
index 45593035b9d60..0716005c679a6 100644
--- a/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr
+++ b/tests/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr
@@ -35,7 +35,8 @@ LL |     t.clone()
    |     ^
 help: consider annotating `Foo` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Foo;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
index e4e1fc591c476..c87ff95255326 100644
--- a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
@@ -6,9 +6,11 @@ LL |     let _x = NonZeroU32::new(5).unwrap();
    |
 help: consider importing one of these items
    |
-LL | use core::num::NonZeroU32;
+LL + use core::num::NonZeroU32;
+LL | fn main() {
    |
-LL | use std::num::NonZeroU32;
+LL + use std::num::NonZeroU32;
+LL | fn main() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/derive-macro-missing-bounds.stderr b/tests/ui/suggestions/derive-macro-missing-bounds.stderr
index 79036279df954..c3f305c1770ac 100644
--- a/tests/ui/suggestions/derive-macro-missing-bounds.stderr
+++ b/tests/ui/suggestions/derive-macro-missing-bounds.stderr
@@ -11,7 +11,8 @@ LL |     struct Outer<T>(Inner<T>);
    = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `a::Inner<T>` with `#[derive(Debug)]`
    |
-LL |     #[derive(Debug)]
+LL +     #[derive(Debug)]
+LL |     struct Inner<T>(T);
    |
 help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
    |
diff --git a/tests/ui/suggestions/derive-trait-for-method-call.stderr b/tests/ui/suggestions/derive-trait-for-method-call.stderr
index 924b26a8c75fd..e2db0da74f022 100644
--- a/tests/ui/suggestions/derive-trait-for-method-call.stderr
+++ b/tests/ui/suggestions/derive-trait-for-method-call.stderr
@@ -32,7 +32,8 @@ note: the trait `Default` must be implemented
   --> $SRC_DIR/core/src/default.rs:LL:COL
 help: consider annotating `Enum` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | enum Enum {
    |
 
 error[E0599]: the method `test` exists for struct `Foo<Struct, CloneStruct>`, but its trait bounds were not satisfied
@@ -67,11 +68,13 @@ LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
    |         unsatisfied trait bound introduced here
 help: consider annotating `CloneStruct` with `#[derive(Default)]`
    |
-LL | #[derive(Default)]
+LL + #[derive(Default)]
+LL | struct CloneStruct {
    |
 help: consider annotating `Struct` with `#[derive(Clone, Default)]`
    |
-LL | #[derive(Clone, Default)]
+LL + #[derive(Clone, Default)]
+LL | struct Struct {
    |
 
 error[E0599]: the method `test` exists for struct `Foo<Vec<Enum>, Instant>`, but its trait bounds were not satisfied
diff --git a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
index 4658ecb3a7a95..6eced1d416e48 100644
--- a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
+++ b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
@@ -10,9 +10,11 @@ LL |     banana::Chaenomeles.pick()
    = help: items from traits can only be used if the trait is in scope
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
-LL | use banana::Apple;
+LL + use banana::Apple;
+LL | mod banana {
    |
-LL | use banana::Peach;
+LL + use banana::Peach;
+LL | mod banana {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/import-trait-for-method-call.stderr b/tests/ui/suggestions/import-trait-for-method-call.stderr
index f159b51a26969..464fe85ac175b 100644
--- a/tests/ui/suggestions/import-trait-for-method-call.stderr
+++ b/tests/ui/suggestions/import-trait-for-method-call.stderr
@@ -10,7 +10,8 @@ LL |     h.finish()
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use std::hash::Hasher;
+LL + use std::hash::Hasher;
+LL | use std::hash::BuildHasher;
    |
 
 error[E0599]: the method `as_ref` exists for reference `&dyn Bar`, but its trait bounds were not satisfied
diff --git a/tests/ui/suggestions/invalid-bin-op.stderr b/tests/ui/suggestions/invalid-bin-op.stderr
index 08502dfeb2d59..e291cedb8357e 100644
--- a/tests/ui/suggestions/invalid-bin-op.stderr
+++ b/tests/ui/suggestions/invalid-bin-op.stderr
@@ -13,7 +13,8 @@ LL | struct S<T>(T);
    | ^^^^^^^^^^^ must implement `PartialEq<_>`
 help: consider annotating `S<T>` with `#[derive(PartialEq)]`
    |
-LL | #[derive(PartialEq)]
+LL + #[derive(PartialEq)]
+LL | struct S<T>(T);
    |
 help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
    |
diff --git a/tests/ui/suggestions/issue-84973-blacklist.stderr b/tests/ui/suggestions/issue-84973-blacklist.stderr
index c20cc816484b4..1e243f81b10ee 100644
--- a/tests/ui/suggestions/issue-84973-blacklist.stderr
+++ b/tests/ui/suggestions/issue-84973-blacklist.stderr
@@ -27,7 +27,8 @@ LL | fn f_clone<T: Clone>(t: T) {}
    |               ^^^^^ required by this bound in `f_clone`
 help: consider annotating `S` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct S;
    |
 
 error[E0277]: `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` cannot be unpinned
diff --git a/tests/ui/suggestions/no-extern-crate-in-type.stderr b/tests/ui/suggestions/no-extern-crate-in-type.stderr
index 876eef2b6249a..d8e53229f49fc 100644
--- a/tests/ui/suggestions/no-extern-crate-in-type.stderr
+++ b/tests/ui/suggestions/no-extern-crate-in-type.stderr
@@ -6,7 +6,8 @@ LL | type Output = Option<Foo>;
    |
 help: consider importing this struct
    |
-LL | use foo::Foo;
+LL + use foo::Foo;
+LL | extern crate foo;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/raw-name-use-suggestion.stderr b/tests/ui/suggestions/raw-name-use-suggestion.stderr
index 95c26b9ade8b9..733af9079d598 100644
--- a/tests/ui/suggestions/raw-name-use-suggestion.stderr
+++ b/tests/ui/suggestions/raw-name-use-suggestion.stderr
@@ -28,7 +28,8 @@ LL |     r#break();
    |
 help: consider importing this function
    |
-LL | use foo::r#break;
+LL + use foo::r#break;
+LL | mod foo {
    |
 
 error: aborting due to 3 previous errors
diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
index 018083f9e03af..525a5bc164de0 100644
--- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
+++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
@@ -8,9 +8,11 @@ LL |     let _i: i16 = TryFrom::try_from(0_i32).unwrap();
    = note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
 help: consider importing one of these items
    |
-LL | use core::convert::TryFrom;
+LL + use core::convert::TryFrom;
+LL | fn test() {
    |
-LL | use std::convert::TryFrom;
+LL + use std::convert::TryFrom;
+LL | fn test() {
    |
 
 error[E0433]: failed to resolve: use of undeclared type `TryInto`
@@ -23,9 +25,11 @@ LL |     let _i: i16 = TryInto::try_into(0_i32).unwrap();
    = note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
 help: consider importing one of these items
    |
-LL | use core::convert::TryInto;
+LL + use core::convert::TryInto;
+LL | fn test() {
    |
-LL | use std::convert::TryInto;
+LL + use std::convert::TryInto;
+LL | fn test() {
    |
 
 error[E0433]: failed to resolve: use of undeclared type `FromIterator`
@@ -42,9 +46,11 @@ LL |     let _v: Vec<_> = IntoIterator::from_iter(&[1]);
    |                      ~~~~~~~~~~~~
 help: consider importing one of these items
    |
-LL | use core::iter::FromIterator;
+LL + use core::iter::FromIterator;
+LL | fn test() {
    |
-LL | use std::iter::FromIterator;
+LL + use std::iter::FromIterator;
+LL | fn test() {
    |
 
 error[E0599]: no method named `try_into` found for type `i32` in the current scope
@@ -60,7 +66,8 @@ LL |     let _i: i16 = 0_i32.try_into().unwrap();
    = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use std::convert::TryInto;
+LL + use std::convert::TryInto;
+LL | fn test() {
    |
 
 error: aborting due to 4 previous errors
diff --git a/tests/ui/suggestions/use-placement-resolve.stderr b/tests/ui/suggestions/use-placement-resolve.stderr
index 9da9e8e27021d..16cbc9edcef79 100644
--- a/tests/ui/suggestions/use-placement-resolve.stderr
+++ b/tests/ui/suggestions/use-placement-resolve.stderr
@@ -6,7 +6,8 @@ LL | fn foobar<T: Debug>(x: T) {}
    |
 help: consider importing this trait instead
    |
-LL | use std::fmt::Debug;
+LL + use std::fmt::Debug;
+LL | fn main() {}
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/use-placement-typeck.stderr b/tests/ui/suggestions/use-placement-typeck.stderr
index 3b2749773a134..dc0586302f59b 100644
--- a/tests/ui/suggestions/use-placement-typeck.stderr
+++ b/tests/ui/suggestions/use-placement-typeck.stderr
@@ -13,7 +13,8 @@ LL |     pub struct S;
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use m::Foo;
+LL + use m::Foo;
+LL | fn main() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/trait-bounds/impl-bound-with-references-error.stderr b/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
index 95fd6bd504cdd..cc3b887cf072e 100644
--- a/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
+++ b/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
@@ -6,7 +6,8 @@ LL |     T: Into<Cow<'static, str>>,
    |
 help: consider importing this enum
    |
-LL | use std::borrow::Cow;
+LL + use std::borrow::Cow;
+LL | pub enum LabelText {
    |
 
 error[E0119]: conflicting implementations of trait `From<LabelText>` for type `LabelText`
diff --git a/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr b/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
index b297662955e39..60a86cc8e41ea 100644
--- a/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
+++ b/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
@@ -6,7 +6,8 @@ LL |     pub struct A<H: A::Trait>(pub H);
    |
 help: consider importing this trait
    |
-LL |     use A::Trait;
+LL +     use A::Trait;
+LL |     pub struct A<H: A::Trait>(pub H);
    |
 help: if you import `Trait`, refer to it directly
    |
diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
index dc967d5129871..e723c7c51814a 100644
--- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
+++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
@@ -26,7 +26,8 @@ LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
    |            ^^^^^ required by this bound in `copy`
 help: consider annotating `NoClone` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct NoClone;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/traits/issue-71136.stderr b/tests/ui/traits/issue-71136.stderr
index f541733929d36..ef55796187ee7 100644
--- a/tests/ui/traits/issue-71136.stderr
+++ b/tests/ui/traits/issue-71136.stderr
@@ -11,7 +11,8 @@ LL |     the_foos: Vec<Foo>,
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `Foo` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct Foo(u8);
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/traits/issue-78372.stderr b/tests/ui/traits/issue-78372.stderr
index 8e7fd5f255710..f9c2c0d6dec7d 100644
--- a/tests/ui/traits/issue-78372.stderr
+++ b/tests/ui/traits/issue-78372.stderr
@@ -6,7 +6,8 @@ LL | struct Smaht<T, MISC>(PhantomData);
    |
 help: consider importing this struct
    |
-LL | use std::marker::PhantomData;
+LL + use std::marker::PhantomData;
+LL | use std::ops::DispatchFromDyn;
    |
 
 error[E0412]: cannot find type `U` in this scope
diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr
index 04995b3a17b29..f505f36aaeadf 100644
--- a/tests/ui/traits/item-privacy.stderr
+++ b/tests/ui/traits/item-privacy.stderr
@@ -29,7 +29,8 @@ LL |     S.b();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use method::B;
+LL + use method::B;
+LL | struct S;
    |
 
 error[E0624]: method `a` is private
@@ -69,7 +70,8 @@ LL |     S::b(&S);
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use method::B;
+LL + use method::B;
+LL | struct S;
    |
 
 error[E0624]: method `a` is private
@@ -109,7 +111,8 @@ LL |     S::B;
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use assoc_const::B;
+LL + use assoc_const::B;
+LL | struct S;
    |
 
 error[E0624]: associated constant `A` is private
diff --git a/tests/ui/traits/method-private.stderr b/tests/ui/traits/method-private.stderr
index 55656f21e00ca..2b047df75a004 100644
--- a/tests/ui/traits/method-private.stderr
+++ b/tests/ui/traits/method-private.stderr
@@ -10,7 +10,8 @@ LL |     foo.method();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use inner::Bar;
+LL + use inner::Bar;
+LL | mod inner {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/typeck/explain_clone_autoref.stderr b/tests/ui/typeck/explain_clone_autoref.stderr
index 4539da4389b3b..38cb7fe551841 100644
--- a/tests/ui/typeck/explain_clone_autoref.stderr
+++ b/tests/ui/typeck/explain_clone_autoref.stderr
@@ -14,7 +14,8 @@ LL |     nc.clone()
    |     ^^
 help: consider annotating `NotClone` with `#[derive(Clone)]`
    |
-LL | #[derive(Clone)]
+LL + #[derive(Clone)]
+LL | struct NotClone;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr
index caf7530b85af1..fa8a614362295 100644
--- a/tests/ui/typeck/issue-43189.stderr
+++ b/tests/ui/typeck/issue-43189.stderr
@@ -12,7 +12,8 @@ LL |     fn a(&self) {}
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL | use xcrate_issue_43189_b::xcrate_issue_43189_a::A;
+LL + use xcrate_issue_43189_b::xcrate_issue_43189_a::A;
+LL | extern crate xcrate_issue_43189_b;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/underscore-imports/shadow.stderr b/tests/ui/underscore-imports/shadow.stderr
index 7faede4e6d0a9..b0ecf129ca3d7 100644
--- a/tests/ui/underscore-imports/shadow.stderr
+++ b/tests/ui/underscore-imports/shadow.stderr
@@ -7,7 +7,8 @@ LL |         x.deref();
    = help: items from traits can only be used if the trait is in scope
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
-LL |     use std::ops::Deref;
+LL +     use std::ops::Deref;
+LL |     use crate::b::Shadow as _; // Only imports the struct
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/union/union-derive-clone.mirunsafeck.stderr b/tests/ui/union/union-derive-clone.mirunsafeck.stderr
index b80e8b988adb1..4d23d230fa3f6 100644
--- a/tests/ui/union/union-derive-clone.mirunsafeck.stderr
+++ b/tests/ui/union/union-derive-clone.mirunsafeck.stderr
@@ -9,7 +9,8 @@ note: required by a bound in `AssertParamIsCopy`
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `U1` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | union U1 {
    |
 
 error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
@@ -34,7 +35,8 @@ LL | #[derive(Clone, Copy)]
    |          ^^^^^ unsatisfied trait bound introduced in this `derive` macro
 help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
    |
-LL | #[derive(Clone, Copy)]
+LL + #[derive(Clone, Copy)]
+LL | struct CloneNoCopy;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/union/union-derive-clone.thirunsafeck.stderr b/tests/ui/union/union-derive-clone.thirunsafeck.stderr
index b80e8b988adb1..4d23d230fa3f6 100644
--- a/tests/ui/union/union-derive-clone.thirunsafeck.stderr
+++ b/tests/ui/union/union-derive-clone.thirunsafeck.stderr
@@ -9,7 +9,8 @@ note: required by a bound in `AssertParamIsCopy`
    = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `U1` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | union U1 {
    |
 
 error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
@@ -34,7 +35,8 @@ LL | #[derive(Clone, Copy)]
    |          ^^^^^ unsatisfied trait bound introduced in this `derive` macro
 help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
    |
-LL | #[derive(Clone, Copy)]
+LL + #[derive(Clone, Copy)]
+LL | struct CloneNoCopy;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/union/union-derive-eq.mirunsafeck.stderr b/tests/ui/union/union-derive-eq.mirunsafeck.stderr
index 9e55390b54dbe..136cd883e26ce 100644
--- a/tests/ui/union/union-derive-eq.mirunsafeck.stderr
+++ b/tests/ui/union/union-derive-eq.mirunsafeck.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct PartialEqNotEq;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/union/union-derive-eq.thirunsafeck.stderr b/tests/ui/union/union-derive-eq.thirunsafeck.stderr
index 9e55390b54dbe..136cd883e26ce 100644
--- a/tests/ui/union/union-derive-eq.thirunsafeck.stderr
+++ b/tests/ui/union/union-derive-eq.thirunsafeck.stderr
@@ -12,7 +12,8 @@ note: required by a bound in `AssertParamIsEq`
    = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct PartialEqNotEq;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/unresolved/unresolved-candidates.stderr b/tests/ui/unresolved/unresolved-candidates.stderr
index ea737c567b960..53f63c1c840c9 100644
--- a/tests/ui/unresolved/unresolved-candidates.stderr
+++ b/tests/ui/unresolved/unresolved-candidates.stderr
@@ -17,7 +17,8 @@ LL |     impl Trait for () {}
    |
 help: consider importing this trait
    |
-LL |     use a::Trait;
+LL +     use a::Trait;
+LL |     impl Trait for () {}
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/wf/wf-const-type.stderr b/tests/ui/wf/wf-const-type.stderr
index 85938364ede10..617969720a60a 100644
--- a/tests/ui/wf/wf-const-type.stderr
+++ b/tests/ui/wf/wf-const-type.stderr
@@ -12,7 +12,8 @@ LL | struct IsCopy<T:Copy> { t: T }
    |                 ^^^^ required by this bound in `IsCopy`
 help: consider annotating `NotCopy` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct NotCopy;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/wf/wf-static-type.stderr b/tests/ui/wf/wf-static-type.stderr
index 16c6124b65299..bb5a57834ebd2 100644
--- a/tests/ui/wf/wf-static-type.stderr
+++ b/tests/ui/wf/wf-static-type.stderr
@@ -12,7 +12,8 @@ LL | struct IsCopy<T:Copy> { t: T }
    |                 ^^^^ required by this bound in `IsCopy`
 help: consider annotating `NotCopy` with `#[derive(Copy)]`
    |
-LL | #[derive(Copy)]
+LL + #[derive(Copy)]
+LL | struct NotCopy;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/where-clauses/where-clauses-method-unsatisfied.stderr b/tests/ui/where-clauses/where-clauses-method-unsatisfied.stderr
index e90502977ff6a..6cf717295141b 100644
--- a/tests/ui/where-clauses/where-clauses-method-unsatisfied.stderr
+++ b/tests/ui/where-clauses/where-clauses-method-unsatisfied.stderr
@@ -11,7 +11,8 @@ LL |     fn equals(&self, u: &Foo<T>) -> bool where T : Eq {
    |                                                    ^^ required by this bound in `Foo::<T>::equals`
 help: consider annotating `Bar` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Bar; // does not implement Eq
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/where-clauses/where-clauses-unsatisfied.stderr b/tests/ui/where-clauses/where-clauses-unsatisfied.stderr
index b1805a4522f4d..4d239bf43079f 100644
--- a/tests/ui/where-clauses/where-clauses-unsatisfied.stderr
+++ b/tests/ui/where-clauses/where-clauses-unsatisfied.stderr
@@ -11,7 +11,8 @@ LL | fn equal<T>(a: &T, b: &T) -> bool where T : Eq { a == b }
    |                                             ^^ required by this bound in `equal`
 help: consider annotating `Struct` with `#[derive(Eq)]`
    |
-LL | #[derive(Eq)]
+LL + #[derive(Eq)]
+LL | struct Struct;
    |
 
 error: aborting due to previous error

From 9fadcc143a49a124fa1d0d3261593defb986a987 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Esteban=20K=C3=BCber?= <esteban@kuber.com.ar>
Date: Mon, 10 Apr 2023 16:46:12 +0000
Subject: [PATCH 2/2] Special-case item attributes in the suggestion output

---
 compiler/rustc_errors/src/emitter.rs              | 11 ++++++++++-
 src/tools/clippy/tests/ui/crashes/ice-6252.stderr |  3 ---
 .../clippy/tests/ui/new_without_default.stderr    |  6 ------
 tests/ui/coherence/coherence_inherent.stderr      |  1 -
 tests/ui/coherence/coherence_inherent_cc.stderr   |  1 -
 .../generic_const_exprs/issue-94287.stderr        |  1 -
 tests/ui/const-generics/issues/issue-82956.stderr |  4 ----
 tests/ui/derived-errors/issue-31997-1.stderr      |  1 -
 .../issue-56028-there-is-an-enum-variant.stderr   |  4 ----
 tests/ui/hygiene/globs.stderr                     |  2 --
 tests/ui/hygiene/no_implicit_prelude.stderr       |  2 --
 tests/ui/hygiene/trait_items.stderr               |  1 -
 .../impl-trait/no-method-suggested-traits.stderr  | 12 ------------
 tests/ui/impl-trait/universal_wrong_bounds.stderr |  2 --
 tests/ui/imports/glob-resolve1.stderr             |  1 -
 tests/ui/imports/issue-38293.stderr               |  1 -
 tests/ui/imports/issue-4366-2.stderr              |  1 -
 tests/ui/imports/issue-4366.stderr                |  1 -
 tests/ui/imports/overlapping_pub_trait.stderr     |  1 -
 tests/ui/imports/unnamed_pub_trait.stderr         |  1 -
 tests/ui/issues/issue-10465.stderr                |  1 -
 tests/ui/issues/issue-17546.stderr                |  8 --------
 tests/ui/issues/issue-35976.unimported.stderr     |  1 -
 tests/ui/issues/issue-37534.stderr                |  1 -
 tests/ui/issues/issue-39175.stderr                |  1 -
 tests/ui/issues/issue-56175.stderr                |  2 --
 tests/ui/issues/issue-77919.stderr                |  1 -
 tests/ui/layout/issue-84108.stderr                |  2 --
 tests/ui/macros/issue-100199.stderr               |  1 -
 tests/ui/macros/macro-outer-attributes.stderr     |  1 -
 tests/ui/namespace/namespace-mix.stderr           |  8 --------
 tests/ui/parser/circular_modules_main.stderr      |  1 -
 tests/ui/privacy/privacy-ns1.stderr               |  3 ---
 tests/ui/privacy/privacy-ns2.stderr               |  3 ---
 tests/ui/proc-macro/amputate-span.stderr          |  2 --
 .../proc-macro/attributes-on-modules-fail.stderr  |  2 --
 tests/ui/resolve/crate-in-paths.stderr            |  1 -
 tests/ui/resolve/enums-are-namespaced-xc.stderr   |  3 ---
 tests/ui/resolve/filter-intrinsics.stderr         |  2 --
 tests/ui/resolve/issue-102946.stderr              |  1 -
 tests/ui/resolve/issue-16058.stderr               |  3 ---
 tests/ui/resolve/issue-17518.stderr               |  1 -
 tests/ui/resolve/issue-21221-1.stderr             |  7 -------
 tests/ui/resolve/issue-21221-2.stderr             |  2 --
 tests/ui/resolve/issue-21221-3.stderr             |  1 -
 tests/ui/resolve/issue-21221-4.stderr             |  1 -
 tests/ui/resolve/issue-2356.stderr                |  1 -
 tests/ui/resolve/issue-26545.stderr               |  1 -
 tests/ui/resolve/issue-35675.stderr               |  2 --
 tests/ui/resolve/issue-3907.stderr                |  1 -
 tests/ui/resolve/issue-50599.stderr               |  2 --
 tests/ui/resolve/issue-73427.stderr               |  2 --
 tests/ui/resolve/issue-90113.stderr               |  1 -
 tests/ui/resolve/missing-in-namespace.stderr      |  1 -
 .../ui/resolve/no-implicit-prelude-nested.stderr  | 15 ---------------
 tests/ui/resolve/no-implicit-prelude.stderr       |  5 -----
 tests/ui/resolve/privacy-enum-ctor.stderr         |  4 ----
 .../ui/resolve/resolve-primitive-fallback.stderr  |  1 -
 tests/ui/resolve/use_suggestion.stderr            |  2 --
 tests/ui/resolve/use_suggestion_placement.stderr  |  3 ---
 .../rust-2018/issue-52202-use-suggestions.stderr  |  4 ----
 .../ui/rust-2018/trait-import-suggestions.stderr  |  3 ---
 .../ui/rust-2018/uniform-paths/issue-87932.stderr |  1 -
 .../future-prelude-collision-shadow.stderr        |  2 --
 tests/ui/self/class-missing-self.stderr           |  1 -
 tests/ui/shadowed/shadowed-trait-methods.stderr   |  1 -
 ...021-incompatible-closure-captures-96258.stderr |  1 -
 tests/ui/span/issue-35987.stderr                  |  1 -
 .../core-std-import-order-issue-83564.stderr      |  2 --
 .../dont-wrap-ambiguous-receivers.stderr          |  2 --
 .../import-trait-for-method-call.stderr           |  1 -
 .../ui/suggestions/no-extern-crate-in-type.stderr |  1 -
 .../ui/suggestions/raw-name-use-suggestion.stderr |  1 -
 .../suggest-tryinto-edition-change.stderr         |  7 -------
 tests/ui/suggestions/use-placement-resolve.stderr |  1 -
 tests/ui/suggestions/use-placement-typeck.stderr  |  1 -
 .../impl-bound-with-references-error.stderr       |  1 -
 ...shadowed-path-in-trait-bound-suggestion.stderr |  1 -
 tests/ui/traits/issue-78372.stderr                |  1 -
 tests/ui/traits/item-privacy.stderr               |  3 ---
 tests/ui/traits/method-private.stderr             |  1 -
 tests/ui/typeck/issue-43189.stderr                |  1 -
 tests/ui/underscore-imports/shadow.stderr         |  1 -
 tests/ui/unresolved/unresolved-candidates.stderr  |  1 -
 84 files changed, 10 insertions(+), 188 deletions(-)

diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 7b6d65511c15b..fe44799efdb6a 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -1886,6 +1886,7 @@ impl EmitterWriter {
             }
             let mut unhighlighted_lines = Vec::new();
             let mut last_pos = 0;
+            let mut is_item_attribute = false;
             for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() {
                 last_pos = line_pos;
                 debug!(%line_pos, %line, ?highlight_parts);
@@ -1895,6 +1896,12 @@ impl EmitterWriter {
                     unhighlighted_lines.push((line_pos, line));
                     continue;
                 }
+                if highlight_parts.len() == 1
+                    && line.trim().starts_with("#[")
+                    && line.trim().ends_with(']')
+                {
+                    is_item_attribute = true;
+                }
 
                 match unhighlighted_lines.len() {
                     0 => (),
@@ -1971,11 +1978,13 @@ impl EmitterWriter {
                     is_multiline,
                 )
             }
-            if let DisplaySuggestion::Add = show_code_change {
+            if let DisplaySuggestion::Add = show_code_change && is_item_attribute {
                 // The suggestion adds an entire line of code, ending on a newline, so we'll also
                 // print the *following* line, to provide context of what we're advicing people to
                 // do. Otherwise you would only see contextless code that can be confused for
                 // already existing code, despite the colors and UI elements.
+                // We special case `#[derive(_)]\n` and other attribute suggestions, because those
+                // are the ones where context is most useful.
                 let file_lines = sm
                     .span_to_lines(span.primary_span().unwrap().shrink_to_hi())
                     .expect("span_to_lines failed when emitting suggestion");
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
index 3c7e08ebeae85..4787282f504a6 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
@@ -7,13 +7,10 @@ LL |     _n: PhantomData,
 help: consider importing one of these items
    |
 LL + use core::marker::PhantomData;
-LL | trait TypeVal<T> {
    |
 LL + use serde::__private::PhantomData;
-LL | trait TypeVal<T> {
    |
 LL + use std::marker::PhantomData;
-LL | trait TypeVal<T> {
    |
 
 error[E0412]: cannot find type `VAL` in this scope
diff --git a/src/tools/clippy/tests/ui/new_without_default.stderr b/src/tools/clippy/tests/ui/new_without_default.stderr
index 9b0a2f6ca5bf2..583dd327d6a5d 100644
--- a/src/tools/clippy/tests/ui/new_without_default.stderr
+++ b/src/tools/clippy/tests/ui/new_without_default.stderr
@@ -14,7 +14,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl Foo {
    |
 
 error: you should consider adding a `Default` implementation for `Bar`
@@ -32,7 +31,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl Bar {
    |
 
 error: you should consider adding a `Default` implementation for `LtKo<'c>`
@@ -50,7 +48,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl<'c> LtKo<'c> {
    |
 
 error: you should consider adding a `Default` implementation for `NewNotEqualToDerive`
@@ -68,7 +65,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl NewNotEqualToDerive {
    |
 
 error: you should consider adding a `Default` implementation for `FooGenerics<T>`
@@ -86,7 +82,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl<T> FooGenerics<T> {
    |
 
 error: you should consider adding a `Default` implementation for `BarGenerics<T>`
@@ -104,7 +99,6 @@ LL +     fn default() -> Self {
 LL +         Self::new()
 LL +     }
 LL + }
-LL | impl<T: Copy> BarGenerics<T> {
    |
 
 error: you should consider adding a `Default` implementation for `Foo<T>`
diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr
index 48f70700046f3..b381b0680734f 100644
--- a/tests/ui/coherence/coherence_inherent.stderr
+++ b/tests/ui/coherence/coherence_inherent.stderr
@@ -8,7 +8,6 @@ LL |         s.the_fn();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use Lib::TheTrait;
-LL |     use Lib::TheStruct;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr
index 58254740f82e0..7b6cb7d4390b4 100644
--- a/tests/ui/coherence/coherence_inherent_cc.stderr
+++ b/tests/ui/coherence/coherence_inherent_cc.stderr
@@ -8,7 +8,6 @@ LL |         s.the_fn();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use coherence_inherent_cc_lib::TheTrait;
-LL |     use coherence_inherent_cc_lib::TheStruct;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
index 1e4e4edb596bb..dc7d0c54fcc9a 100644
--- a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
@@ -9,7 +9,6 @@ help: consider enabling this feature
   --> $DIR/issue-94287.rs:1:1
    |
 LL + #![feature(generic_const_exprs)]
-LL | #![feature(generic_const_exprs)]
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/const-generics/issues/issue-82956.stderr b/tests/ui/const-generics/issues/issue-82956.stderr
index d1d5073255109..d70c8d0bfbf34 100644
--- a/tests/ui/const-generics/issues/issue-82956.stderr
+++ b/tests/ui/const-generics/issues/issue-82956.stderr
@@ -7,16 +7,12 @@ LL |         let mut iter = IntoIter::new(self);
 help: consider importing one of these items
    |
 LL + use std::array::IntoIter;
-LL | pub struct ConstCheck<const CHECK: bool>;
    |
 LL + use std::collections::binary_heap::IntoIter;
-LL | pub struct ConstCheck<const CHECK: bool>;
    |
 LL + use std::collections::btree_map::IntoIter;
-LL | pub struct ConstCheck<const CHECK: bool>;
    |
 LL + use std::collections::btree_set::IntoIter;
-LL | pub struct ConstCheck<const CHECK: bool>;
    |
      and 8 other candidates
 
diff --git a/tests/ui/derived-errors/issue-31997-1.stderr b/tests/ui/derived-errors/issue-31997-1.stderr
index 2ea3d910dbfa7..a0262f4c1e597 100644
--- a/tests/ui/derived-errors/issue-31997-1.stderr
+++ b/tests/ui/derived-errors/issue-31997-1.stderr
@@ -7,7 +7,6 @@ LL |     let mut map = HashMap::new();
 help: consider importing this struct
    |
 LL + use std::collections::HashMap;
-LL | use std::io::prelude::*;
    |
 
 error: aborting due to previous error
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 11cdcfadef36c..5c610f36322dc 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
@@ -25,16 +25,12 @@ LL | fn setup() -> Set { Set }
 help: consider importing one of these items
    |
 LL + use AffixHeart::Set;
-LL | enum PutDown { Set }
    |
 LL + use CauseToBe::Set;
-LL | enum PutDown { Set }
    |
 LL + use Determine::Set;
-LL | enum PutDown { Set }
    |
 LL + use PutDown::Set;
-LL | enum PutDown { Set }
    |
      and 3 other candidates
 
diff --git a/tests/ui/hygiene/globs.stderr b/tests/ui/hygiene/globs.stderr
index b68950b66dbae..180172644402b 100644
--- a/tests/ui/hygiene/globs.stderr
+++ b/tests/ui/hygiene/globs.stderr
@@ -14,7 +14,6 @@ LL |         g();
 help: consider importing this function
    |
 LL + use foo::f;
-LL | mod foo {
    |
 
 error[E0425]: cannot find function `g` in this scope
@@ -41,7 +40,6 @@ LL |     f();
 help: consider importing this function
    |
 LL + use bar::g;
-LL | mod foo {
    |
 
 error[E0425]: cannot find function `f` in this scope
diff --git a/tests/ui/hygiene/no_implicit_prelude.stderr b/tests/ui/hygiene/no_implicit_prelude.stderr
index 21cecfefd349f..96187b1c50161 100644
--- a/tests/ui/hygiene/no_implicit_prelude.stderr
+++ b/tests/ui/hygiene/no_implicit_prelude.stderr
@@ -11,7 +11,6 @@ LL |         Vec::new();
 help: consider importing this struct
    |
 LL +     use std::vec::Vec;
-LL |     pub macro m() { Vec::<i32>::new(); ().clone() }
    |
 
 error[E0599]: no method named `clone` found for unit type `()` in the current scope
@@ -28,7 +27,6 @@ LL |         ().clone()
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use std::clone::Clone;
-LL |     pub macro m() { Vec::<i32>::new(); ().clone() }
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/hygiene/trait_items.stderr b/tests/ui/hygiene/trait_items.stderr
index 60cf6787f82fb..f303534c709fc 100644
--- a/tests/ui/hygiene/trait_items.stderr
+++ b/tests/ui/hygiene/trait_items.stderr
@@ -15,7 +15,6 @@ LL |     pub macro m() { ().f() }
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use foo::T;
-LL |     use foo::*;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr
index 0d37ea38b58cd..160cc044078ed 100644
--- a/tests/ui/impl-trait/no-method-suggested-traits.stderr
+++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr
@@ -8,16 +8,12 @@ LL |     1u32.method();
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
 LL + use foo::Bar;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::Reexported;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::foo::PubPub;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::qux::PrivPub;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&u32>>` in the current scope
@@ -30,16 +26,12 @@ LL |     std::rc::Rc::new(&mut Box::new(&1u32)).method();
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
 LL + use foo::Bar;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::Reexported;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::foo::PubPub;
-LL | extern crate no_method_suggested_traits;
    |
 LL + use no_method_suggested_traits::qux::PrivPub;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for type `char` in the current scope
@@ -55,7 +47,6 @@ LL |     'a'.method();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use foo::Bar;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in the current scope
@@ -68,7 +59,6 @@ LL |     std::rc::Rc::new(&mut Box::new(&'a')).method();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use foo::Bar;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for type `i32` in the current scope
@@ -86,7 +76,6 @@ LL |         fn method(&self) {}
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use no_method_suggested_traits::foo::PubPub;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in the current scope
@@ -99,7 +88,6 @@ LL |     std::rc::Rc::new(&mut Box::new(&1i32)).method();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use no_method_suggested_traits::foo::PubPub;
-LL | extern crate no_method_suggested_traits;
    |
 
 error[E0599]: no method named `method` found for struct `Foo` in the current scope
diff --git a/tests/ui/impl-trait/universal_wrong_bounds.stderr b/tests/ui/impl-trait/universal_wrong_bounds.stderr
index 1561708efba37..464d689589e91 100644
--- a/tests/ui/impl-trait/universal_wrong_bounds.stderr
+++ b/tests/ui/impl-trait/universal_wrong_bounds.stderr
@@ -7,7 +7,6 @@ LL | fn wants_debug(g: impl Debug) { }
 help: consider importing this trait instead
    |
 LL + use std::fmt::Debug;
-LL | use std::fmt::Display;
    |
 
 error[E0404]: expected trait, found derive macro `Debug`
@@ -19,7 +18,6 @@ LL | fn wants_display(g: impl Debug) { }
 help: consider importing this trait instead
    |
 LL + use std::fmt::Debug;
-LL | use std::fmt::Display;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/glob-resolve1.stderr b/tests/ui/imports/glob-resolve1.stderr
index 6d7ceb25a8fd5..4401ef58732e8 100644
--- a/tests/ui/imports/glob-resolve1.stderr
+++ b/tests/ui/imports/glob-resolve1.stderr
@@ -61,7 +61,6 @@ LL |     import();
 help: consider importing this function
    |
 LL + use other::import;
-LL | use bar::*;
    |
 
 error[E0412]: cannot find type `A` in this scope
diff --git a/tests/ui/imports/issue-38293.stderr b/tests/ui/imports/issue-38293.stderr
index 7a3b405a78222..1bb7ae29e1083 100644
--- a/tests/ui/imports/issue-38293.stderr
+++ b/tests/ui/imports/issue-38293.stderr
@@ -13,7 +13,6 @@ LL |     baz();
 help: consider importing this function instead
    |
 LL + use bar::baz;
-LL | use foo::f::{self};
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/issue-4366-2.stderr b/tests/ui/imports/issue-4366-2.stderr
index d8539f9a9d4fd..412423f4d595e 100644
--- a/tests/ui/imports/issue-4366-2.stderr
+++ b/tests/ui/imports/issue-4366-2.stderr
@@ -19,7 +19,6 @@ LL |     foo();
 help: consider importing this function instead
    |
 LL + use foo::foo;
-LL | use m1::*;
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/imports/issue-4366.stderr b/tests/ui/imports/issue-4366.stderr
index 724db83e99ada..4d5b392a7e104 100644
--- a/tests/ui/imports/issue-4366.stderr
+++ b/tests/ui/imports/issue-4366.stderr
@@ -7,7 +7,6 @@ LL |         fn sub() -> isize { foo(); 1 }
 help: consider importing this function
    |
 LL +         use foo::foo;
-LL |         use a::b::*;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/imports/overlapping_pub_trait.stderr b/tests/ui/imports/overlapping_pub_trait.stderr
index 268709e11b67c..490dccd3e808e 100644
--- a/tests/ui/imports/overlapping_pub_trait.stderr
+++ b/tests/ui/imports/overlapping_pub_trait.stderr
@@ -13,7 +13,6 @@ LL |     pub trait Tr { fn method(&self); }
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use overlapping_pub_trait_source::m::Tr;
-LL | extern crate overlapping_pub_trait_source;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/imports/unnamed_pub_trait.stderr b/tests/ui/imports/unnamed_pub_trait.stderr
index 47fa6d3a39881..5133273c22f6c 100644
--- a/tests/ui/imports/unnamed_pub_trait.stderr
+++ b/tests/ui/imports/unnamed_pub_trait.stderr
@@ -13,7 +13,6 @@ LL |     pub trait Tr { fn method(&self); }
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use unnamed_pub_trait_source::prelude::*; // trait Tr
-LL | extern crate unnamed_pub_trait_source;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-10465.stderr b/tests/ui/issues/issue-10465.stderr
index 9941e14a94e06..1b7b9d5909ebb 100644
--- a/tests/ui/issues/issue-10465.stderr
+++ b/tests/ui/issues/issue-10465.stderr
@@ -8,7 +8,6 @@ LL |             b.foo();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +         use a::A;
-LL |         use b::B;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-17546.stderr b/tests/ui/issues/issue-17546.stderr
index 23a12fa167b7f..cf7ed1bbd6682 100644
--- a/tests/ui/issues/issue-17546.stderr
+++ b/tests/ui/issues/issue-17546.stderr
@@ -25,16 +25,12 @@ LL |     fn new() -> Result<foo::MyEnum, String> {
 help: consider importing one of these items instead
    |
 LL +     use std::fmt::Result;
-LL |     use foo::MyEnum::Result;
    |
 LL +     use std::io::Result;
-LL |     use foo::MyEnum::Result;
    |
 LL +     use std::result::Result;
-LL |     use foo::MyEnum::Result;
    |
 LL +     use std::thread::Result;
-LL |     use foo::MyEnum::Result;
    |
 
 error[E0573]: expected type, found variant `Result`
@@ -46,16 +42,12 @@ LL | fn new() -> Result<foo::MyEnum, String> {
 help: consider importing one of these items instead
    |
 LL + use std::fmt::Result;
-LL | use foo::MyEnum::Result;
    |
 LL + use std::io::Result;
-LL | use foo::MyEnum::Result;
    |
 LL + use std::result::Result;
-LL | use foo::MyEnum::Result;
    |
 LL + use std::thread::Result;
-LL | use foo::MyEnum::Result;
    |
 
 error[E0573]: expected type, found variant `NoResult`
diff --git a/tests/ui/issues/issue-35976.unimported.stderr b/tests/ui/issues/issue-35976.unimported.stderr
index 8a3e2fcd08333..b31d2a31551ef 100644
--- a/tests/ui/issues/issue-35976.unimported.stderr
+++ b/tests/ui/issues/issue-35976.unimported.stderr
@@ -10,7 +10,6 @@ LL |     arg.wait();
 help: another candidate was found in the following trait, perhaps add a `use` for it:
    |
 LL + use private::Future;
-LL | mod private {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-37534.stderr b/tests/ui/issues/issue-37534.stderr
index 8449eb9c6925a..7d3dd8800bd34 100644
--- a/tests/ui/issues/issue-37534.stderr
+++ b/tests/ui/issues/issue-37534.stderr
@@ -7,7 +7,6 @@ LL | struct Foo<T: ?Hash> { }
 help: consider importing this trait instead
    |
 LL + use std::hash::Hash;
-LL | struct Foo<T: ?Hash> { }
    |
 
 warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
diff --git a/tests/ui/issues/issue-39175.stderr b/tests/ui/issues/issue-39175.stderr
index 19e7f5162a77c..3a1476ac0e3af 100644
--- a/tests/ui/issues/issue-39175.stderr
+++ b/tests/ui/issues/issue-39175.stderr
@@ -8,7 +8,6 @@ LL |     Command::new("echo").arg("hello").exec();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use std::os::unix::process::CommandExt;
-LL | use std::process::Command;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/issues/issue-56175.stderr b/tests/ui/issues/issue-56175.stderr
index bedbaef29b9c4..1ddee1f4895bb 100644
--- a/tests/ui/issues/issue-56175.stderr
+++ b/tests/ui/issues/issue-56175.stderr
@@ -13,7 +13,6 @@ LL |         fn trait_method(&self) {
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use reexported_trait::Trait;
-LL | fn main() {
    |
 
 error[E0599]: no method named `trait_method_b` found for struct `FooStruct` in the current scope
@@ -31,7 +30,6 @@ LL |         fn trait_method_b(&self) {
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use reexported_trait::TraitBRename;
-LL | fn main() {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/issues/issue-77919.stderr b/tests/ui/issues/issue-77919.stderr
index 1f3f6cb33c7fb..d6dcc8997b9ab 100644
--- a/tests/ui/issues/issue-77919.stderr
+++ b/tests/ui/issues/issue-77919.stderr
@@ -7,7 +7,6 @@ LL |     _n: PhantomData,
 help: consider importing this struct
    |
 LL + use std::marker::PhantomData;
-LL | fn main() {
    |
 
 error[E0412]: cannot find type `VAL` in this scope
diff --git a/tests/ui/layout/issue-84108.stderr b/tests/ui/layout/issue-84108.stderr
index cdc21df79a7e5..5ad450bed0781 100644
--- a/tests/ui/layout/issue-84108.stderr
+++ b/tests/ui/layout/issue-84108.stderr
@@ -7,7 +7,6 @@ LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
 help: consider importing this struct
    |
 LL + use std::ffi::OsStr;
-LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
    |
 
 error[E0412]: cannot find type `Path` in this scope
@@ -19,7 +18,6 @@ LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
 help: consider importing this struct
    |
 LL + use std::path::Path;
-LL | static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
    |
 
 error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
diff --git a/tests/ui/macros/issue-100199.stderr b/tests/ui/macros/issue-100199.stderr
index ab6bc08b5f7c5..89a6f585ce415 100644
--- a/tests/ui/macros/issue-100199.stderr
+++ b/tests/ui/macros/issue-100199.stderr
@@ -8,7 +8,6 @@ LL | #[issue_100199::struct_with_bound]
 help: consider importing this trait
    |
 LL + use traits::MyTrait;
-LL | #[issue_100199::struct_with_bound]
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/macros/macro-outer-attributes.stderr b/tests/ui/macros/macro-outer-attributes.stderr
index cfd1c7739ba4c..0bdc3416f807e 100644
--- a/tests/ui/macros/macro-outer-attributes.stderr
+++ b/tests/ui/macros/macro-outer-attributes.stderr
@@ -7,7 +7,6 @@ LL |     a::bar();
 help: consider importing this function
    |
 LL + use b::bar;
-LL | macro_rules! test { ($nm:ident,
    |
 help: if you import `bar`, refer to it directly
    |
diff --git a/tests/ui/namespace/namespace-mix.stderr b/tests/ui/namespace/namespace-mix.stderr
index 216548180bc50..3ac5e96c5742b 100644
--- a/tests/ui/namespace/namespace-mix.stderr
+++ b/tests/ui/namespace/namespace-mix.stderr
@@ -15,10 +15,8 @@ LL |     check(m1::TS);
 help: consider importing one of these items instead
    |
 LL + use m2::S;
-LL | use namespace_mix::*;
    |
 LL + use xm2::S;
-LL | use namespace_mix::*;
    |
 help: if you import `S`, refer to it directly
    |
@@ -45,10 +43,8 @@ LL |     check(xm1::TS);
 help: consider importing one of these items instead
    |
 LL + use m2::S;
-LL | use namespace_mix::*;
    |
 LL + use xm2::S;
-LL | use namespace_mix::*;
    |
 help: if you import `S`, refer to it directly
    |
@@ -73,10 +69,8 @@ LL |     check(m7::TV);
 help: consider importing one of these items instead
    |
 LL + use m8::V;
-LL | use namespace_mix::*;
    |
 LL + use xm8::V;
-LL | use namespace_mix::*;
    |
 help: if you import `V`, refer to it directly
    |
@@ -103,10 +97,8 @@ LL |     check(xm7::TV);
 help: consider importing one of these items instead
    |
 LL + use m8::V;
-LL | use namespace_mix::*;
    |
 LL + use xm8::V;
-LL | use namespace_mix::*;
    |
 help: if you import `V`, refer to it directly
    |
diff --git a/tests/ui/parser/circular_modules_main.stderr b/tests/ui/parser/circular_modules_main.stderr
index 2804c6ebf5097..2de70789358b0 100644
--- a/tests/ui/parser/circular_modules_main.stderr
+++ b/tests/ui/parser/circular_modules_main.stderr
@@ -13,7 +13,6 @@ LL |     println!("{}", circular_modules_main::hi_str());
 help: consider importing this function
    |
 LL + use hi_str;
-LL | #[path = "circular_modules_main.rs"]
    |
 help: if you import `hi_str`, refer to it directly
    |
diff --git a/tests/ui/privacy/privacy-ns1.stderr b/tests/ui/privacy/privacy-ns1.stderr
index fe3e4a78a84b0..9710cc48637bc 100644
--- a/tests/ui/privacy/privacy-ns1.stderr
+++ b/tests/ui/privacy/privacy-ns1.stderr
@@ -14,7 +14,6 @@ LL |     Baz();
 help: consider importing this function instead
    |
 LL + use foo2::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0425]: cannot find function, tuple struct or tuple variant `Bar` in this scope
@@ -33,7 +32,6 @@ LL |     Baz();
 help: consider importing this function
    |
 LL + use foo2::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0412]: cannot find type `Bar` in this scope
@@ -52,7 +50,6 @@ LL |     let _x: Box<Baz>;
 help: consider importing this trait
    |
 LL + use foo1::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0747]: constant provided when a type was expected
diff --git a/tests/ui/privacy/privacy-ns2.stderr b/tests/ui/privacy/privacy-ns2.stderr
index 73a24bd20f33c..75e735e1e6a28 100644
--- a/tests/ui/privacy/privacy-ns2.stderr
+++ b/tests/ui/privacy/privacy-ns2.stderr
@@ -7,7 +7,6 @@ LL |     Bar();
 help: consider importing this function instead
    |
 LL + use foo2::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0423]: expected function, tuple struct or tuple variant, found trait `Bar`
@@ -26,7 +25,6 @@ LL |     Baz();
 help: consider importing this function instead
    |
 LL + use foo2::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0573]: expected type, found function `Bar`
@@ -42,7 +40,6 @@ LL |     let _x = Bar();
 help: consider importing this trait instead
    |
 LL + use foo1::Bar;
-LL | pub mod foo1 {
    |
 
 error[E0603]: trait `Bar` is private
diff --git a/tests/ui/proc-macro/amputate-span.stderr b/tests/ui/proc-macro/amputate-span.stderr
index fa83707e79d5b..aa797339be467 100644
--- a/tests/ui/proc-macro/amputate-span.stderr
+++ b/tests/ui/proc-macro/amputate-span.stderr
@@ -7,7 +7,6 @@ LL |     Command::new("git");
 help: consider importing this struct
    |
 LL + use std::process::Command;
-LL | #[amputate_span::drop_first_token]
    |
 
 error[E0433]: failed to resolve: use of undeclared type `Command`
@@ -19,7 +18,6 @@ LL |         Command::new("git");
 help: consider importing this struct
    |
 LL +     use std::process::Command;
-LL |     #[amputate_span::drop_first_token]
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/proc-macro/attributes-on-modules-fail.stderr b/tests/ui/proc-macro/attributes-on-modules-fail.stderr
index a0ab9999c088c..97521f23aeef3 100644
--- a/tests/ui/proc-macro/attributes-on-modules-fail.stderr
+++ b/tests/ui/proc-macro/attributes-on-modules-fail.stderr
@@ -51,7 +51,6 @@ LL |     type A = Y;
 help: consider importing this struct
    |
 LL +     use Y;
-LL |     pub struct X;
    |
 
 error[E0412]: cannot find type `X` in this scope
@@ -63,7 +62,6 @@ LL | type A = X;
 help: consider importing this struct
    |
 LL + use m::X;
-LL | #[macro_use]
    |
 
 error: aborting due to 7 previous errors
diff --git a/tests/ui/resolve/crate-in-paths.stderr b/tests/ui/resolve/crate-in-paths.stderr
index 45ecf5a59adfe..07fb5dcc035c1 100644
--- a/tests/ui/resolve/crate-in-paths.stderr
+++ b/tests/ui/resolve/crate-in-paths.stderr
@@ -7,7 +7,6 @@ LL |     Foo;
 help: consider importing this unit struct
    |
 LL + use crate::bar::Foo;
-LL | mod bar {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/enums-are-namespaced-xc.stderr b/tests/ui/resolve/enums-are-namespaced-xc.stderr
index efebf15684b90..5af6cb04275b8 100644
--- a/tests/ui/resolve/enums-are-namespaced-xc.stderr
+++ b/tests/ui/resolve/enums-are-namespaced-xc.stderr
@@ -7,7 +7,6 @@ LL |     let _ = namespaced_enums::A;
 help: consider importing this unit variant
    |
 LL + use namespaced_enums::Foo::A;
-LL | extern crate namespaced_enums;
    |
 help: if you import `A`, refer to it directly
    |
@@ -24,7 +23,6 @@ LL |     let _ = namespaced_enums::B(10);
 help: consider importing this tuple variant
    |
 LL + use namespaced_enums::Foo::B;
-LL | extern crate namespaced_enums;
    |
 help: if you import `B`, refer to it directly
    |
@@ -41,7 +39,6 @@ LL |     let _ = namespaced_enums::C { a: 10 };
 help: consider importing this variant
    |
 LL + use namespaced_enums::Foo::C;
-LL | extern crate namespaced_enums;
    |
 help: if you import `C`, refer to it directly
    |
diff --git a/tests/ui/resolve/filter-intrinsics.stderr b/tests/ui/resolve/filter-intrinsics.stderr
index 3b4a09a25e7f1..cc1092dd0cfa8 100644
--- a/tests/ui/resolve/filter-intrinsics.stderr
+++ b/tests/ui/resolve/filter-intrinsics.stderr
@@ -7,7 +7,6 @@ LL |     let _ = size_of::<usize>();
 help: consider importing this function
    |
 LL + use std::mem::size_of;
-LL | fn main() {
    |
 
 error[E0425]: cannot find function `fabsf64` in this scope
@@ -19,7 +18,6 @@ LL |     let _ = fabsf64(1.0);
 help: consider importing this function
    |
 LL + use std::intrinsics::fabsf64;
-LL | fn main() {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/resolve/issue-102946.stderr b/tests/ui/resolve/issue-102946.stderr
index 7384384921407..b2cdcb25c3f96 100644
--- a/tests/ui/resolve/issue-102946.stderr
+++ b/tests/ui/resolve/issue-102946.stderr
@@ -7,7 +7,6 @@ LL | impl Error for str::Utf8Error {
 help: consider importing this trait
    |
 LL + use std::error::Error;
-LL | impl Error for str::Utf8Error {
    |
 
 error[E0223]: ambiguous associated type
diff --git a/tests/ui/resolve/issue-16058.stderr b/tests/ui/resolve/issue-16058.stderr
index 65dba047234a2..710002a154efd 100644
--- a/tests/ui/resolve/issue-16058.stderr
+++ b/tests/ui/resolve/issue-16058.stderr
@@ -7,13 +7,10 @@ LL |         Result {
 help: consider importing one of these items instead
    |
 LL + use std::fmt::Result;
-LL | pub struct GslResult {
    |
 LL + use std::io::Result;
-LL | pub struct GslResult {
    |
 LL + use std::thread::Result;
-LL | pub struct GslResult {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-17518.stderr b/tests/ui/resolve/issue-17518.stderr
index 19b59b841e042..492e3b34a1798 100644
--- a/tests/ui/resolve/issue-17518.stderr
+++ b/tests/ui/resolve/issue-17518.stderr
@@ -7,7 +7,6 @@ LL |     E { name: "foobar" };
 help: consider importing this variant
    |
 LL + use SomeEnum::E;
-LL | enum SomeEnum {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-1.stderr b/tests/ui/resolve/issue-21221-1.stderr
index 836ea564f4ee1..a38116cd7287a 100644
--- a/tests/ui/resolve/issue-21221-1.stderr
+++ b/tests/ui/resolve/issue-21221-1.stderr
@@ -7,13 +7,10 @@ LL | impl Mul for Foo {
 help: consider importing one of these items
    |
 LL + use mul1::Mul;
-LL | mod mul1 {
    |
 LL + use mul2::Mul;
-LL | mod mul1 {
    |
 LL + use std::ops::Mul;
-LL | mod mul1 {
    |
 
 error[E0412]: cannot find type `Mul` in this scope
@@ -25,13 +22,10 @@ LL | fn getMul() -> Mul {
 help: consider importing one of these items
    |
 LL + use mul1::Mul;
-LL | mod mul1 {
    |
 LL + use mul2::Mul;
-LL | mod mul1 {
    |
 LL + use std::ops::Mul;
-LL | mod mul1 {
    |
 
 error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
@@ -49,7 +43,6 @@ LL | impl Div for Foo {
 help: consider importing this trait
    |
 LL + use std::ops::Div;
-LL | mod mul1 {
    |
 
 error: aborting due to 4 previous errors
diff --git a/tests/ui/resolve/issue-21221-2.stderr b/tests/ui/resolve/issue-21221-2.stderr
index e88274e6c60b3..9beb626623e4e 100644
--- a/tests/ui/resolve/issue-21221-2.stderr
+++ b/tests/ui/resolve/issue-21221-2.stderr
@@ -7,10 +7,8 @@ LL | impl T for Foo { }
 help: consider importing one of these items
    |
 LL + use baz::T;
-LL | pub mod foo {
    |
 LL + use foo::bar::T;
-LL | pub mod foo {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-3.stderr b/tests/ui/resolve/issue-21221-3.stderr
index e02eaec05e3ec..0dabdfd9b3900 100644
--- a/tests/ui/resolve/issue-21221-3.stderr
+++ b/tests/ui/resolve/issue-21221-3.stderr
@@ -7,7 +7,6 @@ LL | impl OuterTrait for Foo {}
 help: consider importing this trait
    |
 LL + use issue_21221_3::outer::OuterTrait;
-LL | extern crate issue_21221_3;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-21221-4.stderr b/tests/ui/resolve/issue-21221-4.stderr
index e8c38ed6acf08..5af14b1b68d36 100644
--- a/tests/ui/resolve/issue-21221-4.stderr
+++ b/tests/ui/resolve/issue-21221-4.stderr
@@ -7,7 +7,6 @@ LL | impl T for Foo {}
 help: consider importing this trait
    |
 LL + use issue_21221_4::T;
-LL | extern crate issue_21221_4;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-2356.stderr b/tests/ui/resolve/issue-2356.stderr
index ed820f15c83e5..313b3e30dd956 100644
--- a/tests/ui/resolve/issue-2356.stderr
+++ b/tests/ui/resolve/issue-2356.stderr
@@ -11,7 +11,6 @@ LL |     Self::default();
 help: consider importing this function
    |
 LL + use std::default::default;
-LL | trait Groom {
    |
 
 error[E0425]: cannot find value `whiskers` in this scope
diff --git a/tests/ui/resolve/issue-26545.stderr b/tests/ui/resolve/issue-26545.stderr
index 2b98b5b8a7bf5..42a7531c5b940 100644
--- a/tests/ui/resolve/issue-26545.stderr
+++ b/tests/ui/resolve/issue-26545.stderr
@@ -7,7 +7,6 @@ LL |         B(());
 help: consider importing this tuple struct
    |
 LL +     use foo::B;
-LL |     fn foo() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-35675.stderr b/tests/ui/resolve/issue-35675.stderr
index d285614537158..44af65b0768a8 100644
--- a/tests/ui/resolve/issue-35675.stderr
+++ b/tests/ui/resolve/issue-35675.stderr
@@ -18,7 +18,6 @@ LL |     Apple(5)
 help: consider importing this tuple variant
    |
 LL + use Fruit::Apple;
-LL | enum Fruit {
    |
 
 error[E0573]: expected type, found variant `Fruit::Apple`
@@ -39,7 +38,6 @@ LL |     Apple(5)
 help: consider importing this tuple variant
    |
 LL + use Fruit::Apple;
-LL | enum Fruit {
    |
 
 error[E0573]: expected type, found variant `Ok`
diff --git a/tests/ui/resolve/issue-3907.stderr b/tests/ui/resolve/issue-3907.stderr
index 50ad668f8dbf6..70631a13cdf86 100644
--- a/tests/ui/resolve/issue-3907.stderr
+++ b/tests/ui/resolve/issue-3907.stderr
@@ -11,7 +11,6 @@ LL | trait Foo = dyn issue_3907::Foo;
 help: consider importing this trait instead
    |
 LL + use issue_3907::Foo;
-LL | extern crate issue_3907;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/issue-50599.stderr b/tests/ui/resolve/issue-50599.stderr
index 548d215b00acd..d7419b64facd2 100644
--- a/tests/ui/resolve/issue-50599.stderr
+++ b/tests/ui/resolve/issue-50599.stderr
@@ -7,10 +7,8 @@ LL |     const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize;
 help: consider importing one of these items
    |
 LL + use std::f32::consts::LOG10_2;
-LL | fn main() {
    |
 LL + use std::f64::consts::LOG10_2;
-LL | fn main() {
    |
 help: if you import `LOG10_2`, refer to it directly
    |
diff --git a/tests/ui/resolve/issue-73427.stderr b/tests/ui/resolve/issue-73427.stderr
index 5a663ae79bcb1..622de9b39bde7 100644
--- a/tests/ui/resolve/issue-73427.stderr
+++ b/tests/ui/resolve/issue-73427.stderr
@@ -108,10 +108,8 @@ LL |     (E::TupleWithFields(/* fields */)).foo();
 help: consider importing one of these items instead
    |
 LL + use std::f32::consts::E;
-LL | enum A {
    |
 LL + use std::f64::consts::E;
-LL | enum A {
    |
 
 error[E0532]: expected tuple struct or tuple variant, found enum `A`
diff --git a/tests/ui/resolve/issue-90113.stderr b/tests/ui/resolve/issue-90113.stderr
index a9d4b573f110b..5f55d9c241a58 100644
--- a/tests/ui/resolve/issue-90113.stderr
+++ b/tests/ui/resolve/issue-90113.stderr
@@ -7,7 +7,6 @@ LL |         Cons(..) => {}
 help: consider importing this tuple variant
    |
 LL + use list::List::Cons;
-LL | mod list {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/resolve/missing-in-namespace.stderr b/tests/ui/resolve/missing-in-namespace.stderr
index 66f40102a3ed3..7a7b749aebb7b 100644
--- a/tests/ui/resolve/missing-in-namespace.stderr
+++ b/tests/ui/resolve/missing-in-namespace.stderr
@@ -7,7 +7,6 @@ LL |     let _map = std::hahmap::HashMap::new();
 help: consider importing this struct
    |
 LL + use std::collections::HashMap;
-LL | fn main() {
    |
 help: if you import `HashMap`, refer to it directly
    |
diff --git a/tests/ui/resolve/no-implicit-prelude-nested.stderr b/tests/ui/resolve/no-implicit-prelude-nested.stderr
index 4df6c31d31644..49cf72bfee2d6 100644
--- a/tests/ui/resolve/no-implicit-prelude-nested.stderr
+++ b/tests/ui/resolve/no-implicit-prelude-nested.stderr
@@ -7,7 +7,6 @@ LL |         impl Add for Test {}
 help: consider importing this trait
    |
 LL +         use std::ops::Add;
-LL |         struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -19,7 +18,6 @@ LL |         impl Clone for Test {}
 help: consider importing this trait instead
    |
 LL +         use std::clone::Clone;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -31,7 +29,6 @@ LL |         impl Iterator for Test {}
 help: consider importing this trait
    |
 LL +         use std::iter::Iterator;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -43,7 +40,6 @@ LL |         impl ToString for Test {}
 help: consider importing this trait
    |
 LL +         use std::string::ToString;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -61,7 +57,6 @@ LL |             drop(2)
 help: consider importing this function
    |
 LL +         use std::mem::drop;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Add` in this scope
@@ -73,7 +68,6 @@ LL |     impl Add for Test {}
 help: consider importing this trait
    |
 LL +     use std::ops::Add;
-LL |     mod baz {
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -85,7 +79,6 @@ LL |     impl Clone for Test {}
 help: consider importing this trait instead
    |
 LL +     use std::clone::Clone;
-LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -97,7 +90,6 @@ LL |     impl Iterator for Test {}
 help: consider importing this trait
    |
 LL +     use std::iter::Iterator;
-LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -109,7 +101,6 @@ LL |     impl ToString for Test {}
 help: consider importing this trait
    |
 LL +     use std::string::ToString;
-LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -127,7 +118,6 @@ LL |         drop(2)
 help: consider importing this function
    |
 LL +     use std::mem::drop;
-LL |     mod baz {
    |
 
 error[E0405]: cannot find trait `Add` in this scope
@@ -139,7 +129,6 @@ LL |         impl Add for Test {}
 help: consider importing this trait
    |
 LL +         use std::ops::Add;
-LL |         struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -151,7 +140,6 @@ LL |         impl Clone for Test {}
 help: consider importing this trait instead
    |
 LL +         use std::clone::Clone;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -163,7 +151,6 @@ LL |         impl Iterator for Test {}
 help: consider importing this trait
    |
 LL +         use std::iter::Iterator;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -175,7 +162,6 @@ LL |         impl ToString for Test {}
 help: consider importing this trait
    |
 LL +         use std::string::ToString;
-LL |         struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -193,7 +179,6 @@ LL |             drop(2)
 help: consider importing this function
    |
 LL +         use std::mem::drop;
-LL |         struct Test;
    |
 
 error: aborting due to 18 previous errors
diff --git a/tests/ui/resolve/no-implicit-prelude.stderr b/tests/ui/resolve/no-implicit-prelude.stderr
index a8e5f1b69e230..5a759743f7258 100644
--- a/tests/ui/resolve/no-implicit-prelude.stderr
+++ b/tests/ui/resolve/no-implicit-prelude.stderr
@@ -7,7 +7,6 @@ LL | impl Add for Test {}
 help: consider importing this trait
    |
 LL + use std::ops::Add;
-LL | struct Test;
    |
 
 error[E0404]: expected trait, found derive macro `Clone`
@@ -19,7 +18,6 @@ LL | impl Clone for Test {}
 help: consider importing this trait instead
    |
 LL + use std::clone::Clone;
-LL | struct Test;
    |
 
 error[E0405]: cannot find trait `Iterator` in this scope
@@ -31,7 +29,6 @@ LL | impl Iterator for Test {}
 help: consider importing this trait
    |
 LL + use std::iter::Iterator;
-LL | struct Test;
    |
 
 error[E0405]: cannot find trait `ToString` in this scope
@@ -43,7 +40,6 @@ LL | impl ToString for Test {}
 help: consider importing this trait
    |
 LL + use std::string::ToString;
-LL | struct Test;
    |
 
 error[E0405]: cannot find trait `Writer` in this scope
@@ -61,7 +57,6 @@ LL |     drop(2)
 help: consider importing this function
    |
 LL + use std::mem::drop;
-LL | struct Test;
    |
 
 error: aborting due to 6 previous errors
diff --git a/tests/ui/resolve/privacy-enum-ctor.stderr b/tests/ui/resolve/privacy-enum-ctor.stderr
index 76dc25539d07d..0bb09090569cb 100644
--- a/tests/ui/resolve/privacy-enum-ctor.stderr
+++ b/tests/ui/resolve/privacy-enum-ctor.stderr
@@ -85,10 +85,8 @@ LL |     let _: E = m::f;
 help: consider importing one of these items instead
    |
 LL + use std::f32::consts::E;
-LL | use m::E; // OK, only the type is imported
    |
 LL + use std::f64::consts::E;
-LL | use m::E; // OK, only the type is imported
    |
 help: if you import `E`, refer to it directly
    |
@@ -124,10 +122,8 @@ LL |     let _: E = (E::Fn(/* fields */));
 help: consider importing one of these items instead
    |
 LL + use std::f32::consts::E;
-LL | use m::E; // OK, only the type is imported
    |
 LL + use std::f64::consts::E;
-LL | use m::E; // OK, only the type is imported
    |
 
 error[E0412]: cannot find type `Z` in this scope
diff --git a/tests/ui/resolve/resolve-primitive-fallback.stderr b/tests/ui/resolve/resolve-primitive-fallback.stderr
index 2227522d6eab6..e3a5d4edcf102 100644
--- a/tests/ui/resolve/resolve-primitive-fallback.stderr
+++ b/tests/ui/resolve/resolve-primitive-fallback.stderr
@@ -13,7 +13,6 @@ LL |     let _: ::u8;
 help: consider importing this builtin type
    |
 LL + use std::primitive::u8;
-LL | fn main() {
    |
 help: if you import `u8`, refer to it directly
    |
diff --git a/tests/ui/resolve/use_suggestion.stderr b/tests/ui/resolve/use_suggestion.stderr
index a30dbd954e12b..1155f5caa1739 100644
--- a/tests/ui/resolve/use_suggestion.stderr
+++ b/tests/ui/resolve/use_suggestion.stderr
@@ -7,7 +7,6 @@ LL |     let x1 = HashMap::new();
 help: consider importing this struct
    |
 LL + use std::collections::HashMap;
-LL | fn main() {
    |
 
 error[E0412]: cannot find type `HashMap` in this scope
@@ -19,7 +18,6 @@ LL |     let y1: HashMap;
 help: consider importing this struct
    |
 LL + use std::collections::HashMap;
-LL | fn main() {
    |
 
 error[E0412]: cannot find type `GooMap` in this scope
diff --git a/tests/ui/resolve/use_suggestion_placement.stderr b/tests/ui/resolve/use_suggestion_placement.stderr
index 9288530ad2e8c..3611f9ae6b4ed 100644
--- a/tests/ui/resolve/use_suggestion_placement.stderr
+++ b/tests/ui/resolve/use_suggestion_placement.stderr
@@ -7,7 +7,6 @@ LL |     type Bar = Path;
 help: consider importing this struct
    |
 LL +     use std::path::Path;
-LL |     #[derive(Debug)]
    |
 
 error[E0425]: cannot find value `A` in this scope
@@ -19,7 +18,6 @@ LL |     let _ = A;
 help: consider importing this constant
    |
 LL + use m::A;
-LL | macro_rules! y {
    |
 
 error[E0412]: cannot find type `HashMap` in this scope
@@ -31,7 +29,6 @@ LL |     type Dict<K, V> = HashMap<K, V>;
 help: consider importing this struct
    |
 LL + use std::collections::HashMap;
-LL | macro_rules! y {
    |
 
 error: aborting due to 3 previous errors
diff --git a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
index 5450ede822300..9933b92439c13 100644
--- a/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
+++ b/tests/ui/rust-2018/issue-52202-use-suggestions.stderr
@@ -7,16 +7,12 @@ LL |     let _d = Drain {};
 help: consider importing one of these items
    |
 LL + use crate::plumbing::Drain;
-LL | mod plumbing {
    |
 LL + use std::collections::binary_heap::Drain;
-LL | mod plumbing {
    |
 LL + use std::collections::hash_map::Drain;
-LL | mod plumbing {
    |
 LL + use std::collections::hash_set::Drain;
-LL | mod plumbing {
    |
      and 3 other candidates
 
diff --git a/tests/ui/rust-2018/trait-import-suggestions.stderr b/tests/ui/rust-2018/trait-import-suggestions.stderr
index 4be5c7b0d0c40..325c5976e7c89 100644
--- a/tests/ui/rust-2018/trait-import-suggestions.stderr
+++ b/tests/ui/rust-2018/trait-import-suggestions.stderr
@@ -11,7 +11,6 @@ LL |         x.foobar();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use crate::foo::foobar::Foobar;
-LL |     mod foobar {
    |
 
 error[E0599]: no method named `bar` found for type `u32` in the current scope
@@ -27,7 +26,6 @@ LL |     x.bar();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use crate::foo::Bar;
-LL | mod foo {
    |
 
 error[E0599]: no method named `baz` found for type `u32` in the current scope
@@ -46,7 +44,6 @@ LL |     let y = u32::from_str("33");
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use std::str::FromStr;
-LL | mod foo {
    |
 help: there is an associated function with a similar name
    |
diff --git a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
index e5e17f22c5f17..ac2baa3595bd3 100644
--- a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
+++ b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr
@@ -11,7 +11,6 @@ LL |     A::deserialize();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use <crate::A as issue_87932_a::Deserialize>::deserialize::_a::Deserialize;
-LL | pub struct A {}
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
index 34bf68e8913f6..9dfaf13e2ecdc 100644
--- a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
+++ b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr
@@ -9,10 +9,8 @@ LL |         let _: u32 = 3u8.try_into().unwrap();
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
 LL +     use crate::m::TryIntoU32;
-LL |     use crate::m::AnotherTrick as TryIntoU32;
    |
 LL +     use std::convert::TryInto;
-LL |     use crate::m::AnotherTrick as TryIntoU32;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/self/class-missing-self.stderr b/tests/ui/self/class-missing-self.stderr
index 2f35b30dbcb0c..3c37d8197432c 100644
--- a/tests/ui/self/class-missing-self.stderr
+++ b/tests/ui/self/class-missing-self.stderr
@@ -17,7 +17,6 @@ LL |       self.sleep();
 help: consider importing this function
    |
 LL + use std::thread::sleep;
-LL | struct Cat {
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr
index 6d7ab27f3e154..1af0400c88619 100644
--- a/tests/ui/shadowed/shadowed-trait-methods.stderr
+++ b/tests/ui/shadowed/shadowed-trait-methods.stderr
@@ -11,7 +11,6 @@ LL |     ().f()
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use foo::T;
-LL | mod foo {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
index 626cc67d9eb93..60433e1c28467 100644
--- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
+++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.stderr
@@ -16,7 +16,6 @@ LL |         interval: Duration,
 help: consider importing this struct
    |
 LL + use std::time::Duration;
-LL | fn main() {}
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/span/issue-35987.stderr b/tests/ui/span/issue-35987.stderr
index 0e64bcb010693..88c86d2a91b58 100644
--- a/tests/ui/span/issue-35987.stderr
+++ b/tests/ui/span/issue-35987.stderr
@@ -12,7 +12,6 @@ LL | impl<T: Clone, Add> Add for Foo<T> {
 help: consider importing this trait instead
    |
 LL + use std::ops::Add;
-LL | use std::ops::Add;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
index c87ff95255326..48ee44a74f2d3 100644
--- a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
+++ b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr
@@ -7,10 +7,8 @@ LL |     let _x = NonZeroU32::new(5).unwrap();
 help: consider importing one of these items
    |
 LL + use core::num::NonZeroU32;
-LL | fn main() {
    |
 LL + use std::num::NonZeroU32;
-LL | fn main() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
index 6eced1d416e48..85fbb8b88e81a 100644
--- a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
+++ b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr
@@ -11,10 +11,8 @@ LL |     banana::Chaenomeles.pick()
 help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
    |
 LL + use banana::Apple;
-LL | mod banana {
    |
 LL + use banana::Peach;
-LL | mod banana {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/import-trait-for-method-call.stderr b/tests/ui/suggestions/import-trait-for-method-call.stderr
index 464fe85ac175b..3f54daf136f6d 100644
--- a/tests/ui/suggestions/import-trait-for-method-call.stderr
+++ b/tests/ui/suggestions/import-trait-for-method-call.stderr
@@ -11,7 +11,6 @@ LL |     h.finish()
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use std::hash::Hasher;
-LL | use std::hash::BuildHasher;
    |
 
 error[E0599]: the method `as_ref` exists for reference `&dyn Bar`, but its trait bounds were not satisfied
diff --git a/tests/ui/suggestions/no-extern-crate-in-type.stderr b/tests/ui/suggestions/no-extern-crate-in-type.stderr
index d8e53229f49fc..68100e56cbc82 100644
--- a/tests/ui/suggestions/no-extern-crate-in-type.stderr
+++ b/tests/ui/suggestions/no-extern-crate-in-type.stderr
@@ -7,7 +7,6 @@ LL | type Output = Option<Foo>;
 help: consider importing this struct
    |
 LL + use foo::Foo;
-LL | extern crate foo;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/raw-name-use-suggestion.stderr b/tests/ui/suggestions/raw-name-use-suggestion.stderr
index 733af9079d598..fb070ffc33230 100644
--- a/tests/ui/suggestions/raw-name-use-suggestion.stderr
+++ b/tests/ui/suggestions/raw-name-use-suggestion.stderr
@@ -29,7 +29,6 @@ LL |     r#break();
 help: consider importing this function
    |
 LL + use foo::r#break;
-LL | mod foo {
    |
 
 error: aborting due to 3 previous errors
diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
index 525a5bc164de0..671f5efddd979 100644
--- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
+++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr
@@ -9,10 +9,8 @@ LL |     let _i: i16 = TryFrom::try_from(0_i32).unwrap();
 help: consider importing one of these items
    |
 LL + use core::convert::TryFrom;
-LL | fn test() {
    |
 LL + use std::convert::TryFrom;
-LL | fn test() {
    |
 
 error[E0433]: failed to resolve: use of undeclared type `TryInto`
@@ -26,10 +24,8 @@ LL |     let _i: i16 = TryInto::try_into(0_i32).unwrap();
 help: consider importing one of these items
    |
 LL + use core::convert::TryInto;
-LL | fn test() {
    |
 LL + use std::convert::TryInto;
-LL | fn test() {
    |
 
 error[E0433]: failed to resolve: use of undeclared type `FromIterator`
@@ -47,10 +43,8 @@ LL |     let _v: Vec<_> = IntoIterator::from_iter(&[1]);
 help: consider importing one of these items
    |
 LL + use core::iter::FromIterator;
-LL | fn test() {
    |
 LL + use std::iter::FromIterator;
-LL | fn test() {
    |
 
 error[E0599]: no method named `try_into` found for type `i32` in the current scope
@@ -67,7 +61,6 @@ LL |     let _i: i16 = 0_i32.try_into().unwrap();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use std::convert::TryInto;
-LL | fn test() {
    |
 
 error: aborting due to 4 previous errors
diff --git a/tests/ui/suggestions/use-placement-resolve.stderr b/tests/ui/suggestions/use-placement-resolve.stderr
index 16cbc9edcef79..77724e7e2a479 100644
--- a/tests/ui/suggestions/use-placement-resolve.stderr
+++ b/tests/ui/suggestions/use-placement-resolve.stderr
@@ -7,7 +7,6 @@ LL | fn foobar<T: Debug>(x: T) {}
 help: consider importing this trait instead
    |
 LL + use std::fmt::Debug;
-LL | fn main() {}
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/suggestions/use-placement-typeck.stderr b/tests/ui/suggestions/use-placement-typeck.stderr
index dc0586302f59b..e900e12b7df0f 100644
--- a/tests/ui/suggestions/use-placement-typeck.stderr
+++ b/tests/ui/suggestions/use-placement-typeck.stderr
@@ -14,7 +14,6 @@ LL |     pub struct S;
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use m::Foo;
-LL | fn main() {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/trait-bounds/impl-bound-with-references-error.stderr b/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
index cc3b887cf072e..b114d295d7816 100644
--- a/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
+++ b/tests/ui/trait-bounds/impl-bound-with-references-error.stderr
@@ -7,7 +7,6 @@ LL |     T: Into<Cow<'static, str>>,
 help: consider importing this enum
    |
 LL + use std::borrow::Cow;
-LL | pub enum LabelText {
    |
 
 error[E0119]: conflicting implementations of trait `From<LabelText>` for type `LabelText`
diff --git a/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr b/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
index 60a86cc8e41ea..4547e1c984c05 100644
--- a/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
+++ b/tests/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
@@ -7,7 +7,6 @@ LL |     pub struct A<H: A::Trait>(pub H);
 help: consider importing this trait
    |
 LL +     use A::Trait;
-LL |     pub struct A<H: A::Trait>(pub H);
    |
 help: if you import `Trait`, refer to it directly
    |
diff --git a/tests/ui/traits/issue-78372.stderr b/tests/ui/traits/issue-78372.stderr
index f9c2c0d6dec7d..ec692ff911df5 100644
--- a/tests/ui/traits/issue-78372.stderr
+++ b/tests/ui/traits/issue-78372.stderr
@@ -7,7 +7,6 @@ LL | struct Smaht<T, MISC>(PhantomData);
 help: consider importing this struct
    |
 LL + use std::marker::PhantomData;
-LL | use std::ops::DispatchFromDyn;
    |
 
 error[E0412]: cannot find type `U` in this scope
diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr
index f505f36aaeadf..f538131892546 100644
--- a/tests/ui/traits/item-privacy.stderr
+++ b/tests/ui/traits/item-privacy.stderr
@@ -30,7 +30,6 @@ LL |     S.b();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use method::B;
-LL | struct S;
    |
 
 error[E0624]: method `a` is private
@@ -71,7 +70,6 @@ LL |     S::b(&S);
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use method::B;
-LL | struct S;
    |
 
 error[E0624]: method `a` is private
@@ -112,7 +110,6 @@ LL |     S::B;
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use assoc_const::B;
-LL | struct S;
    |
 
 error[E0624]: associated constant `A` is private
diff --git a/tests/ui/traits/method-private.stderr b/tests/ui/traits/method-private.stderr
index 2b047df75a004..e11799308c5c7 100644
--- a/tests/ui/traits/method-private.stderr
+++ b/tests/ui/traits/method-private.stderr
@@ -11,7 +11,6 @@ LL |     foo.method();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use inner::Bar;
-LL | mod inner {
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr
index fa8a614362295..c072e6a08ba0b 100644
--- a/tests/ui/typeck/issue-43189.stderr
+++ b/tests/ui/typeck/issue-43189.stderr
@@ -13,7 +13,6 @@ LL |     fn a(&self) {}
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL + use xcrate_issue_43189_b::xcrate_issue_43189_a::A;
-LL | extern crate xcrate_issue_43189_b;
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/underscore-imports/shadow.stderr b/tests/ui/underscore-imports/shadow.stderr
index b0ecf129ca3d7..f2c19405bbb8b 100644
--- a/tests/ui/underscore-imports/shadow.stderr
+++ b/tests/ui/underscore-imports/shadow.stderr
@@ -8,7 +8,6 @@ LL |         x.deref();
 help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
 LL +     use std::ops::Deref;
-LL |     use crate::b::Shadow as _; // Only imports the struct
    |
 
 error: aborting due to previous error
diff --git a/tests/ui/unresolved/unresolved-candidates.stderr b/tests/ui/unresolved/unresolved-candidates.stderr
index 53f63c1c840c9..7ef2f6b1a2922 100644
--- a/tests/ui/unresolved/unresolved-candidates.stderr
+++ b/tests/ui/unresolved/unresolved-candidates.stderr
@@ -18,7 +18,6 @@ LL |     impl Trait for () {}
 help: consider importing this trait
    |
 LL +     use a::Trait;
-LL |     impl Trait for () {}
    |
 
 error: aborting due to 2 previous errors