about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_passes/src/dead.rs214
-rw-r--r--library/core/src/default.rs1
-rw-r--r--library/std/src/sys/pal/unix/pipe.rs4
-rw-r--r--src/bootstrap/src/core/build_steps/check.rs4
-rw-r--r--tests/codegen-units/item-collection/generic-impl.rs10
-rw-r--r--tests/codegen-units/item-collection/overloaded-operators.rs24
-rw-r--r--tests/ui/coherence/re-rebalance-coherence.rs1
-rw-r--r--tests/ui/const-generics/cross_crate_complex.rs1
-rw-r--r--tests/ui/const-generics/defaults/repr-c-issue-82792.rs1
-rw-r--r--tests/ui/const-generics/generic_const_exprs/associated-consts.rs3
-rw-r--r--tests/ui/const-generics/issues/issue-86535-2.rs1
-rw-r--r--tests/ui/const-generics/issues/issue-86535.rs1
-rw-r--r--tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs1
-rw-r--r--tests/ui/generic-associated-types/missing-bounds.fixed4
-rw-r--r--tests/ui/generic-associated-types/missing-bounds.rs4
-rw-r--r--tests/ui/generic-associated-types/missing-bounds.stderr18
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.fixed2
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.rs2
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.stderr8
-rw-r--r--tests/ui/issues/issue-5708.rs1
-rw-r--r--tests/ui/lint/dead-code/allow-unconstructed-pub-struct.rs33
-rw-r--r--tests/ui/lint/dead-code/issue-59003.rs2
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-1.rs5
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-1.stderr26
-rw-r--r--tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs37
-rw-r--r--tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr20
-rw-r--r--tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs32
-rw-r--r--tests/ui/lint/dead-code/unconstructible-pub-struct.rs35
-rw-r--r--tests/ui/lint/dead-code/unconstructible-pub-struct.stderr14
-rw-r--r--tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs36
-rw-r--r--tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr20
-rw-r--r--tests/ui/lint/dead-code/unused-assoc-const.rs20
-rw-r--r--tests/ui/lint/dead-code/unused-assoc-const.stderr16
-rw-r--r--tests/ui/lint/dead-code/unused-impl-for-non-adts.rs45
-rw-r--r--tests/ui/lint/dead-code/unused-impl-for-non-adts.stderr20
-rw-r--r--tests/ui/lint/dead-code/unused-pub-struct.rs48
-rw-r--r--tests/ui/lint/dead-code/unused-pub-struct.stderr14
-rw-r--r--tests/ui/lint/dead-code/unused-struct-derive-default.rs1
-rw-r--r--tests/ui/lint/dead-code/unused-struct-derive-default.stderr1
-rw-r--r--tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs11
-rw-r--r--tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr20
-rw-r--r--tests/ui/parser/issues/issue-105366.fixed1
-rw-r--r--tests/ui/parser/issues/issue-105366.rs1
-rw-r--r--tests/ui/parser/issues/issue-105366.stderr2
-rw-r--r--tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.fixed3
-rw-r--r--tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.rs3
-rw-r--r--tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.stderr10
-rw-r--r--tests/ui/pattern/issue-22546.rs2
-rw-r--r--tests/ui/pattern/issue-22546.stderr10
-rw-r--r--tests/ui/pub/pub-ident-struct-4.fixed3
-rw-r--r--tests/ui/pub/pub-ident-struct-4.rs3
-rw-r--r--tests/ui/pub/pub-ident-struct-4.stderr6
-rw-r--r--tests/ui/regions/regions-issue-21422.rs1
-rw-r--r--tests/ui/structs-enums/newtype-struct-with-dtor.rs2
-rw-r--r--tests/ui/structs-enums/uninstantiable-struct.rs3
-rw-r--r--tests/ui/suggestions/derive-clone-for-eq.fixed1
-rw-r--r--tests/ui/suggestions/derive-clone-for-eq.rs1
-rw-r--r--tests/ui/suggestions/derive-clone-for-eq.stderr4
-rw-r--r--tests/ui/suggestions/option-content-move.fixed2
-rw-r--r--tests/ui/suggestions/option-content-move.rs2
-rw-r--r--tests/ui/suggestions/option-content-move.stderr4
-rw-r--r--tests/ui/traits/object/generics.rs1
62 files changed, 164 insertions, 662 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index 8a931fc4158..7ae5c904004 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -17,7 +17,7 @@ use rustc_hir::{Node, PatKind, TyKind};
 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::middle::privacy::Level;
 use rustc_middle::query::Providers;
-use rustc_middle::ty::{self, AssocItemContainer, TyCtxt};
+use rustc_middle::ty::{self, TyCtxt};
 use rustc_middle::{bug, span_bug};
 use rustc_session::lint;
 use rustc_session::lint::builtin::DEAD_CODE;
@@ -44,79 +44,16 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
     )
 }
 
-struct Publicness {
-    ty_is_public: bool,
-    ty_and_all_fields_are_public: bool,
-}
-
-impl Publicness {
-    fn new(ty_is_public: bool, ty_and_all_fields_are_public: bool) -> Self {
-        Self { ty_is_public, ty_and_all_fields_are_public }
-    }
-}
-
-fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
-    match ty.kind {
-        TyKind::Path(hir::QPath::Resolved(_, path)) => {
-            if let Res::Def(def_kind, def_id) = path.res
-                && let Some(local_def_id) = def_id.as_local()
-            {
-                Some((local_def_id, def_kind))
-            } else {
-                None
-            }
-        }
-        TyKind::Slice(ty) | TyKind::Array(ty, _) => adt_of(ty),
-        TyKind::Ptr(ty) | TyKind::Ref(_, ty) => adt_of(ty.ty),
-        _ => None,
-    }
-}
-
-fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
-    let adt_def = tcx.adt_def(id);
-
-    // skip types contain fields of unit and never type,
-    // it's usually intentional to make the type not constructible
-    let not_require_constructor = adt_def.all_fields().any(|field| {
-        let field_type = tcx.type_of(field.did).instantiate_identity();
-        field_type.is_unit() || field_type.is_never()
-    });
-
-    not_require_constructor
-        || adt_def.all_fields().all(|field| {
-            let field_type = tcx.type_of(field.did).instantiate_identity();
-            // skip fields of PhantomData,
-            // cause it's a common way to check things like well-formedness
-            if field_type.is_phantom_data() {
-                return true;
-            }
-
-            field.vis.is_public()
-        })
-}
-
-/// check struct and its fields are public or not,
-/// for enum and union, just check they are public,
-/// and doesn't solve types like &T for now, just skip them
-fn ty_ref_to_pub_struct(tcx: TyCtxt<'_>, ty: &hir::Ty<'_>) -> Publicness {
-    if let Some((def_id, def_kind)) = adt_of(ty) {
-        return match def_kind {
-            DefKind::Enum | DefKind::Union => {
-                let ty_is_public = tcx.visibility(def_id).is_public();
-                Publicness::new(ty_is_public, ty_is_public)
-            }
-            DefKind::Struct => {
-                let ty_is_public = tcx.visibility(def_id).is_public();
-                Publicness::new(
-                    ty_is_public,
-                    ty_is_public && struct_all_fields_are_public(tcx, def_id),
-                )
-            }
-            _ => Publicness::new(true, true),
-        };
+fn ty_ref_to_pub_struct(tcx: TyCtxt<'_>, ty: &hir::Ty<'_>) -> bool {
+    if let TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
+        && let Res::Def(def_kind, def_id) = path.res
+        && def_id.is_local()
+        && matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
+    {
+        tcx.visibility(def_id).is_public()
+    } else {
+        true
     }
-
-    Publicness::new(true, true)
 }
 
 /// Determine if a work from the worklist is coming from a `#[allow]`
@@ -172,10 +109,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
 
     fn handle_res(&mut self, res: Res) {
         match res {
-            Res::Def(
-                DefKind::Const | DefKind::AssocConst | DefKind::AssocTy | DefKind::TyAlias,
-                def_id,
-            ) => {
+            Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias, def_id) => {
                 self.check_def_id(def_id);
             }
             _ if self.in_pat => {}
@@ -294,10 +228,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
         pats: &[hir::PatField<'_>],
     ) {
         let variant = match self.typeck_results().node_type(lhs.hir_id).kind() {
-            ty::Adt(adt, _) => {
-                self.check_def_id(adt.did());
-                adt.variant_of_res(res)
-            }
+            ty::Adt(adt, _) => adt.variant_of_res(res),
             _ => span_bug!(lhs.span, "non-ADT in struct pattern"),
         };
         for pat in pats {
@@ -317,10 +248,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
         dotdot: hir::DotDotPos,
     ) {
         let variant = match self.typeck_results().node_type(lhs.hir_id).kind() {
-            ty::Adt(adt, _) => {
-                self.check_def_id(adt.did());
-                adt.variant_of_res(res)
-            }
+            ty::Adt(adt, _) => adt.variant_of_res(res),
             _ => {
                 self.tcx.dcx().span_delayed_bug(lhs.span, "non-ADT in tuple struct pattern");
                 return;
@@ -425,6 +353,31 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
                 return false;
             }
 
+            // don't ignore impls for Enums and pub Structs whose methods don't have self receiver,
+            // cause external crate may call such methods to construct values of these types
+            if let Some(local_impl_of) = impl_of.as_local()
+                && let Some(local_def_id) = def_id.as_local()
+                && let Some(fn_sig) =
+                    self.tcx.hir().fn_sig_by_hir_id(self.tcx.local_def_id_to_hir_id(local_def_id))
+                && matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None)
+                && let TyKind::Path(hir::QPath::Resolved(_, path)) =
+                    self.tcx.hir().expect_item(local_impl_of).expect_impl().self_ty.kind
+                && let Res::Def(def_kind, did) = path.res
+            {
+                match def_kind {
+                    // for example, #[derive(Default)] pub struct T(i32);
+                    // external crate can call T::default() to construct T,
+                    // so that don't ignore impl Default for pub Enum and Structs
+                    DefKind::Struct | DefKind::Union if self.tcx.visibility(did).is_public() => {
+                        return false;
+                    }
+                    // don't ignore impl Default for Enums,
+                    // cause we don't know which variant is constructed
+                    DefKind::Enum => return false,
+                    _ => (),
+                };
+            }
+
             if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of)
                 && self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads)
             {
@@ -467,7 +420,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
                     intravisit::walk_item(self, item)
                 }
                 hir::ItemKind::ForeignMod { .. } => {}
-                hir::ItemKind::Trait(_, _, _, _, trait_item_refs) => {
+                hir::ItemKind::Trait(..) => {
                     for impl_def_id in self.tcx.all_impls(item.owner_id.to_def_id()) {
                         if let Some(local_def_id) = impl_def_id.as_local()
                             && let ItemKind::Impl(impl_ref) =
@@ -480,12 +433,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
                             intravisit::walk_path(self, impl_ref.of_trait.unwrap().path);
                         }
                     }
-                    // mark assoc ty live if the trait is live
-                    for trait_item in trait_item_refs {
-                        if let hir::AssocItemKind::Type = trait_item.kind {
-                            self.check_def_id(trait_item.id.owner_id.to_def_id());
-                        }
-                    }
+
                     intravisit::walk_item(self, item)
                 }
                 _ => intravisit::walk_item(self, item),
@@ -502,12 +450,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
                             && let ItemKind::Impl(impl_ref) =
                                 self.tcx.hir().expect_item(local_impl_id).kind
                         {
-                            if !ty_ref_to_pub_struct(self.tcx, impl_ref.self_ty)
-                                .ty_and_all_fields_are_public
+                            if !matches!(trait_item.kind, hir::TraitItemKind::Type(..))
+                                && !ty_ref_to_pub_struct(self.tcx, impl_ref.self_ty)
                             {
-                                // skip impl-items of non pure pub ty,
-                                // cause we don't know the ty is constructed or not,
-                                // check these later in `solve_rest_impl_items`
+                                // skip methods of private ty,
+                                // they would be solved in `solve_rest_impl_items`
                                 continue;
                             }
 
@@ -582,25 +529,28 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
     }
 
     fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool {
-        if let Some((local_def_id, def_kind)) =
-            adt_of(self.tcx.hir().item(impl_id).expect_impl().self_ty)
+        if let TyKind::Path(hir::QPath::Resolved(_, path)) =
+            self.tcx.hir().item(impl_id).expect_impl().self_ty.kind
+            && let Res::Def(def_kind, def_id) = path.res
+            && let Some(local_def_id) = def_id.as_local()
             && matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
         {
+            if self.tcx.visibility(impl_item_id).is_public() {
+                // for the public method, we don't know the trait item is used or not,
+                // so we mark the method live if the self is used
+                return self.live_symbols.contains(&local_def_id);
+            }
+
             if let Some(trait_item_id) = self.tcx.associated_item(impl_item_id).trait_item_def_id
                 && let Some(local_id) = trait_item_id.as_local()
             {
-                // for the local impl item, we can know the trait item is used or not,
+                // for the private method, we can know the trait item is used or not,
                 // so we mark the method live if the self is used and the trait item is used
-                self.live_symbols.contains(&local_id) && self.live_symbols.contains(&local_def_id)
-            } else {
-                // for the foreign method and inherent pub method,
-                // we don't know the trait item or the method is used or not,
-                // so we mark the method live if the self is used
-                self.live_symbols.contains(&local_def_id)
+                return self.live_symbols.contains(&local_id)
+                    && self.live_symbols.contains(&local_def_id);
             }
-        } else {
-            false
         }
+        false
     }
 }
 
@@ -686,9 +636,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
                 self.handle_field_pattern_match(pat, res, fields);
             }
             PatKind::Path(ref qpath) => {
-                if let ty::Adt(adt, _) = self.typeck_results().node_type(pat.hir_id).kind() {
-                    self.check_def_id(adt.did());
-                }
                 let res = self.typeck_results().qpath_res(qpath, pat.hir_id);
                 self.handle_res(res);
             }
@@ -825,9 +772,7 @@ fn check_item<'tcx>(
                 .iter()
                 .filter_map(|def_id| def_id.as_local());
 
-            let self_ty = tcx.hir().item(id).expect_impl().self_ty;
-            let Publicness { ty_is_public, ty_and_all_fields_are_public } =
-                ty_ref_to_pub_struct(tcx, self_ty);
+            let ty_is_pub = ty_ref_to_pub_struct(tcx, tcx.hir().item(id).expect_impl().self_ty);
 
             // And we access the Map here to get HirId from LocalDefId
             for local_def_id in local_def_ids {
@@ -843,19 +788,18 @@ fn check_item<'tcx>(
                 // for trait impl blocks,
                 // mark the method live if the self_ty is public,
                 // or the method is public and may construct self
-                if tcx.visibility(local_def_id).is_public()
-                    && (ty_and_all_fields_are_public || (ty_is_public && may_construct_self))
+                if of_trait
+                    && (!matches!(tcx.def_kind(local_def_id), DefKind::AssocFn)
+                        || tcx.visibility(local_def_id).is_public()
+                            && (ty_is_pub || may_construct_self))
                 {
-                    // if the impl item is public,
-                    // and the ty may be constructed or can be constructed in foreign crates,
-                    // mark the impl item live
                     worklist.push((local_def_id, ComesFromAllowExpect::No));
                 } else if let Some(comes_from_allow) =
                     has_allow_dead_code_or_lang_attr(tcx, local_def_id)
                 {
                     worklist.push((local_def_id, comes_from_allow));
-                } else if of_trait || tcx.visibility(local_def_id).is_public() && ty_is_public {
-                    // private impl items of traits || public impl items not constructs self
+                } else if of_trait {
+                    // private method || public method not constructs self
                     unsolved_impl_items.push((id, local_def_id));
                 }
             }
@@ -881,13 +825,10 @@ fn check_trait_item(
     worklist: &mut Vec<(LocalDefId, ComesFromAllowExpect)>,
     id: hir::TraitItemId,
 ) {
-    use hir::TraitItemKind::{Const, Fn, Type};
-    if matches!(
-        tcx.def_kind(id.owner_id),
-        DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn
-    ) {
+    use hir::TraitItemKind::{Const, Fn};
+    if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
         let trait_item = tcx.hir().trait_item(id);
-        if matches!(trait_item.kind, Const(_, Some(_)) | Type(_, Some(_)) | Fn(..))
+        if matches!(trait_item.kind, Const(_, Some(_)) | Fn(..))
             && let Some(comes_from_allow) =
                 has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)
         {
@@ -925,14 +866,6 @@ fn create_and_seed_worklist(
             effective_vis
                 .is_public_at_level(Level::Reachable)
                 .then_some(id)
-                .filter(|&id|
-                    // checks impls, impl-items and pub structs with all public fields later
-                    match tcx.def_kind(id) {
-                        DefKind::Impl { .. } => false,
-                        DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
-                        DefKind::Struct => struct_all_fields_are_public(tcx, id) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
-                        _ => true
-                    })
                 .map(|id| (id, ComesFromAllowExpect::No))
         })
         // Seed entry point
@@ -1216,7 +1149,6 @@ impl<'tcx> DeadVisitor<'tcx> {
         }
         match self.tcx.def_kind(def_id) {
             DefKind::AssocConst
-            | DefKind::AssocTy
             | DefKind::AssocFn
             | DefKind::Fn
             | DefKind::Static { .. }
@@ -1258,14 +1190,10 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
             || (def_kind == DefKind::Trait && live_symbols.contains(&item.owner_id.def_id))
         {
             for &def_id in tcx.associated_item_def_ids(item.owner_id.def_id) {
-                // We have diagnosed unused assocs in traits
+                // We have diagnosed unused methods in traits
                 if matches!(def_kind, DefKind::Impl { of_trait: true })
-                    && matches!(tcx.def_kind(def_id), DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn)
-                    // skip unused public inherent methods,
-                    // cause we have diagnosed unconstructed struct
-                    || matches!(def_kind, DefKind::Impl { of_trait: false })
-                        && tcx.visibility(def_id).is_public()
-                        && ty_ref_to_pub_struct(tcx, tcx.hir().item(item).expect_impl().self_ty).ty_is_public
+                    && tcx.def_kind(def_id) == DefKind::AssocFn
+                    || def_kind == DefKind::Trait && tcx.def_kind(def_id) != DefKind::AssocFn
                 {
                     continue;
                 }
diff --git a/library/core/src/default.rs b/library/core/src/default.rs
index 4524b352ec8..5cacedcb241 100644
--- a/library/core/src/default.rs
+++ b/library/core/src/default.rs
@@ -103,6 +103,7 @@ use crate::ascii::Char as AsciiChar;
 /// ```
 #[cfg_attr(not(test), rustc_diagnostic_item = "Default")]
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg_attr(not(bootstrap), rustc_trivial_field_reads)]
 pub trait Default: Sized {
     /// Returns the "default value" for a type.
     ///
diff --git a/library/std/src/sys/pal/unix/pipe.rs b/library/std/src/sys/pal/unix/pipe.rs
index 8762af614f1..f0ebc767bad 100644
--- a/library/std/src/sys/pal/unix/pipe.rs
+++ b/library/std/src/sys/pal/unix/pipe.rs
@@ -47,6 +47,8 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
 }
 
 impl AnonPipe {
+    #[allow(dead_code)]
+    // FIXME: This function seems legitimately unused.
     pub fn try_clone(&self) -> io::Result<Self> {
         self.0.duplicate().map(Self)
     }
@@ -85,6 +87,8 @@ impl AnonPipe {
         self.0.is_write_vectored()
     }
 
+    #[allow(dead_code)]
+    // FIXME: This function seems legitimately unused.
     pub fn as_file_desc(&self) -> &FileDesc {
         &self.0
     }
diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs
index 8b71300cf85..7f7faf077d0 100644
--- a/src/bootstrap/src/core/build_steps/check.rs
+++ b/src/bootstrap/src/core/build_steps/check.rs
@@ -31,10 +31,6 @@ pub struct Std {
 }
 
 impl Std {
-    pub fn new(target: TargetSelection) -> Self {
-        Self::new_with_build_kind(target, None)
-    }
-
     pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
         Self { target, crates: vec![], override_build_kind: kind }
     }
diff --git a/tests/codegen-units/item-collection/generic-impl.rs b/tests/codegen-units/item-collection/generic-impl.rs
index b4cd99272b1..23d09e0d8af 100644
--- a/tests/codegen-units/item-collection/generic-impl.rs
+++ b/tests/codegen-units/item-collection/generic-impl.rs
@@ -22,16 +22,16 @@ impl<T> Struct<T> {
     }
 }
 
-pub struct _LifeTimeOnly<'a> {
+pub struct LifeTimeOnly<'a> {
     _a: &'a u32,
 }
 
-impl<'a> _LifeTimeOnly<'a> {
-    //~ MONO_ITEM fn _LifeTimeOnly::<'_>::foo
+impl<'a> LifeTimeOnly<'a> {
+    //~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
     pub fn foo(&self) {}
-    //~ MONO_ITEM fn _LifeTimeOnly::<'_>::bar
+    //~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
     pub fn bar(&'a self) {}
-    //~ MONO_ITEM fn _LifeTimeOnly::<'_>::baz
+    //~ MONO_ITEM fn LifeTimeOnly::<'_>::baz
     pub fn baz<'b>(&'b self) {}
 
     pub fn non_instantiated<T>(&self) {}
diff --git a/tests/codegen-units/item-collection/overloaded-operators.rs b/tests/codegen-units/item-collection/overloaded-operators.rs
index e00e22dbab9..69b55695d3d 100644
--- a/tests/codegen-units/item-collection/overloaded-operators.rs
+++ b/tests/codegen-units/item-collection/overloaded-operators.rs
@@ -5,44 +5,44 @@
 
 use std::ops::{Add, Deref, Index, IndexMut};
 
-pub struct _Indexable {
+pub struct Indexable {
     data: [u8; 3],
 }
 
-impl Index<usize> for _Indexable {
+impl Index<usize> for Indexable {
     type Output = u8;
 
-    //~ MONO_ITEM fn <_Indexable as std::ops::Index<usize>>::index
+    //~ MONO_ITEM fn <Indexable as std::ops::Index<usize>>::index
     fn index(&self, index: usize) -> &Self::Output {
         if index >= 3 { &self.data[0] } else { &self.data[index] }
     }
 }
 
-impl IndexMut<usize> for _Indexable {
-    //~ MONO_ITEM fn <_Indexable as std::ops::IndexMut<usize>>::index_mut
+impl IndexMut<usize> for Indexable {
+    //~ MONO_ITEM fn <Indexable as std::ops::IndexMut<usize>>::index_mut
     fn index_mut(&mut self, index: usize) -> &mut Self::Output {
         if index >= 3 { &mut self.data[0] } else { &mut self.data[index] }
     }
 }
 
-//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::eq
-//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::ne
+//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::eq
+//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::ne
 #[derive(PartialEq)]
-pub struct _Equatable(u32);
+pub struct Equatable(u32);
 
-impl Add<u32> for _Equatable {
+impl Add<u32> for Equatable {
     type Output = u32;
 
-    //~ MONO_ITEM fn <_Equatable as std::ops::Add<u32>>::add
+    //~ MONO_ITEM fn <Equatable as std::ops::Add<u32>>::add
     fn add(self, rhs: u32) -> u32 {
         self.0 + rhs
     }
 }
 
-impl Deref for _Equatable {
+impl Deref for Equatable {
     type Target = u32;
 
-    //~ MONO_ITEM fn <_Equatable as std::ops::Deref>::deref
+    //~ MONO_ITEM fn <Equatable as std::ops::Deref>::deref
     fn deref(&self) -> &Self::Target {
         &self.0
     }
diff --git a/tests/ui/coherence/re-rebalance-coherence.rs b/tests/ui/coherence/re-rebalance-coherence.rs
index 5383a634617..9c176d5b1b1 100644
--- a/tests/ui/coherence/re-rebalance-coherence.rs
+++ b/tests/ui/coherence/re-rebalance-coherence.rs
@@ -4,7 +4,6 @@
 extern crate re_rebalance_coherence_lib as lib;
 use lib::*;
 
-#[allow(dead_code)]
 struct Oracle;
 impl Backend for Oracle {}
 impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
diff --git a/tests/ui/const-generics/cross_crate_complex.rs b/tests/ui/const-generics/cross_crate_complex.rs
index b44d889f5e9..d13b69aa0cf 100644
--- a/tests/ui/const-generics/cross_crate_complex.rs
+++ b/tests/ui/const-generics/cross_crate_complex.rs
@@ -11,7 +11,6 @@ async fn foo() {
     async_in_foo(async_out_foo::<4>().await).await;
 }
 
-#[allow(dead_code)]
 struct Faz<const N: usize>;
 
 impl<const N: usize> Foo<N> for Faz<N> {}
diff --git a/tests/ui/const-generics/defaults/repr-c-issue-82792.rs b/tests/ui/const-generics/defaults/repr-c-issue-82792.rs
index 4bf2fa761ea..c23187598bc 100644
--- a/tests/ui/const-generics/defaults/repr-c-issue-82792.rs
+++ b/tests/ui/const-generics/defaults/repr-c-issue-82792.rs
@@ -2,7 +2,6 @@
 
 //@ run-pass
 
-#[allow(dead_code)]
 #[repr(C)]
 pub struct Loaf<T: Sized, const N: usize = 1> {
     head: [T; N],
diff --git a/tests/ui/const-generics/generic_const_exprs/associated-consts.rs b/tests/ui/const-generics/generic_const_exprs/associated-consts.rs
index 50a6102c605..5d2198f50ad 100644
--- a/tests/ui/const-generics/generic_const_exprs/associated-consts.rs
+++ b/tests/ui/const-generics/generic_const_exprs/associated-consts.rs
@@ -16,8 +16,7 @@ impl BlockCipher for BarCipher {
     const BLOCK_SIZE: usize = 32;
 }
 
-#[allow(dead_code)]
-pub struct Block<C>(C);
+pub struct Block<C>(#[allow(dead_code)] C);
 
 pub fn test<C: BlockCipher, const M: usize>()
 where
diff --git a/tests/ui/const-generics/issues/issue-86535-2.rs b/tests/ui/const-generics/issues/issue-86535-2.rs
index ab68c6b78df..8d064f3eeb1 100644
--- a/tests/ui/const-generics/issues/issue-86535-2.rs
+++ b/tests/ui/const-generics/issues/issue-86535-2.rs
@@ -9,7 +9,6 @@ pub trait Foo {
         [(); Self::ASSOC_C]:;
 }
 
-#[allow(dead_code)]
 struct Bar<const N: &'static ()>;
 impl<const N: &'static ()> Foo for Bar<N> {
     const ASSOC_C: usize = 3;
diff --git a/tests/ui/const-generics/issues/issue-86535.rs b/tests/ui/const-generics/issues/issue-86535.rs
index 9aaf7ddc9e8..62454f4a388 100644
--- a/tests/ui/const-generics/issues/issue-86535.rs
+++ b/tests/ui/const-generics/issues/issue-86535.rs
@@ -2,7 +2,6 @@
 #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
 #![allow(incomplete_features, unused_variables)]
 
-#[allow(dead_code)]
 struct F<const S: &'static str>;
 impl<const S: &'static str> X for F<{ S }> {
     const W: usize = 3;
diff --git a/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs b/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs
index 35c41ae4615..419d605d0c8 100644
--- a/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs
+++ b/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs
@@ -6,7 +6,6 @@
 
 use std::mem::MaybeUninit;
 
-#[allow(dead_code)]
 #[repr(transparent)]
 pub struct MaybeUninitWrapper<const N: usize>(MaybeUninit<[u64; N]>);
 
diff --git a/tests/ui/generic-associated-types/missing-bounds.fixed b/tests/ui/generic-associated-types/missing-bounds.fixed
index ff69016d862..703d3c1e0fb 100644
--- a/tests/ui/generic-associated-types/missing-bounds.fixed
+++ b/tests/ui/generic-associated-types/missing-bounds.fixed
@@ -2,7 +2,6 @@
 
 use std::ops::Add;
 
-#[allow(dead_code)]
 struct A<B>(B);
 
 impl<B> Add for A<B> where B: Add<Output = B> {
@@ -13,7 +12,6 @@ impl<B> Add for A<B> where B: Add<Output = B> {
     }
 }
 
-#[allow(dead_code)]
 struct C<B>(B);
 
 impl<B: Add<Output = B>> Add for C<B> {
@@ -24,7 +22,6 @@ impl<B: Add<Output = B>> Add for C<B> {
     }
 }
 
-#[allow(dead_code)]
 struct D<B>(B);
 
 impl<B: std::ops::Add<Output = B>> Add for D<B> {
@@ -35,7 +32,6 @@ impl<B: std::ops::Add<Output = B>> Add for D<B> {
     }
 }
 
-#[allow(dead_code)]
 struct E<B>(B);
 
 impl<B: Add<Output = B>> Add for E<B> where B: Add<Output = B> {
diff --git a/tests/ui/generic-associated-types/missing-bounds.rs b/tests/ui/generic-associated-types/missing-bounds.rs
index 1f83356c2fa..f40b4228873 100644
--- a/tests/ui/generic-associated-types/missing-bounds.rs
+++ b/tests/ui/generic-associated-types/missing-bounds.rs
@@ -2,7 +2,6 @@
 
 use std::ops::Add;
 
-#[allow(dead_code)]
 struct A<B>(B);
 
 impl<B> Add for A<B> where B: Add {
@@ -13,7 +12,6 @@ impl<B> Add for A<B> where B: Add {
     }
 }
 
-#[allow(dead_code)]
 struct C<B>(B);
 
 impl<B: Add> Add for C<B> {
@@ -24,7 +22,6 @@ impl<B: Add> Add for C<B> {
     }
 }
 
-#[allow(dead_code)]
 struct D<B>(B);
 
 impl<B> Add for D<B> {
@@ -35,7 +32,6 @@ impl<B> Add for D<B> {
     }
 }
 
-#[allow(dead_code)]
 struct E<B>(B);
 
 impl<B: Add> Add for E<B> where <B as Add>::Output = B {
diff --git a/tests/ui/generic-associated-types/missing-bounds.stderr b/tests/ui/generic-associated-types/missing-bounds.stderr
index 0f0dc24c06c..1d7d80d1b07 100644
--- a/tests/ui/generic-associated-types/missing-bounds.stderr
+++ b/tests/ui/generic-associated-types/missing-bounds.stderr
@@ -1,5 +1,5 @@
 error: equality constraints are not yet supported in `where` clauses
-  --> $DIR/missing-bounds.rs:41:33
+  --> $DIR/missing-bounds.rs:37:33
    |
 LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
    |                                 ^^^^^^^^^^^^^^^^^^^^^^ not supported
@@ -11,7 +11,7 @@ LL | impl<B: Add> Add for E<B> where B: Add<Output = B> {
    |                                 ~~~~~~~~~~~~~~~~~~
 
 error[E0308]: mismatched types
-  --> $DIR/missing-bounds.rs:12:11
+  --> $DIR/missing-bounds.rs:11:11
    |
 LL | impl<B> Add for A<B> where B: Add {
    |      - expected this type parameter
@@ -24,14 +24,14 @@ LL |         A(self.0 + rhs.0)
    = note: expected type parameter `B`
              found associated type `<B as Add>::Output`
 help: the type constructed contains `<B as Add>::Output` due to the type of the argument passed
-  --> $DIR/missing-bounds.rs:12:9
+  --> $DIR/missing-bounds.rs:11:9
    |
 LL |         A(self.0 + rhs.0)
    |         ^^--------------^
    |           |
    |           this argument influences the type of `A`
 note: tuple struct defined here
-  --> $DIR/missing-bounds.rs:6:8
+  --> $DIR/missing-bounds.rs:5:8
    |
 LL | struct A<B>(B);
    |        ^
@@ -41,7 +41,7 @@ LL | impl<B> Add for A<B> where B: Add<Output = B> {
    |                                  ++++++++++++
 
 error[E0308]: mismatched types
-  --> $DIR/missing-bounds.rs:23:14
+  --> $DIR/missing-bounds.rs:21:14
    |
 LL | impl<B: Add> Add for C<B> {
    |      - expected this type parameter
@@ -54,7 +54,7 @@ LL |         Self(self.0 + rhs.0)
    = note: expected type parameter `B`
              found associated type `<B as Add>::Output`
 note: tuple struct defined here
-  --> $DIR/missing-bounds.rs:17:8
+  --> $DIR/missing-bounds.rs:15:8
    |
 LL | struct C<B>(B);
    |        ^
@@ -64,7 +64,7 @@ LL | impl<B: Add<Output = B>> Add for C<B> {
    |            ++++++++++++
 
 error[E0369]: cannot add `B` to `B`
-  --> $DIR/missing-bounds.rs:34:21
+  --> $DIR/missing-bounds.rs:31:21
    |
 LL |         Self(self.0 + rhs.0)
    |              ------ ^ ----- B
@@ -77,7 +77,7 @@ LL | impl<B: std::ops::Add<Output = B>> Add for D<B> {
    |       +++++++++++++++++++++++++++
 
 error[E0308]: mismatched types
-  --> $DIR/missing-bounds.rs:46:14
+  --> $DIR/missing-bounds.rs:42:14
    |
 LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
    |      - expected this type parameter
@@ -90,7 +90,7 @@ LL |         Self(self.0 + rhs.0)
    = note: expected type parameter `B`
              found associated type `<B as Add>::Output`
 note: tuple struct defined here
-  --> $DIR/missing-bounds.rs:39:8
+  --> $DIR/missing-bounds.rs:35:8
    |
 LL | struct E<B>(B);
    |        ^
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
index 3c4499f0173..886fc1d0058 100644
--- a/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
@@ -1,8 +1,6 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
 struct S<T>(T);
-#[allow(dead_code)]
 struct S2;
 
 impl<T: Default> Default for S<T> {
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.rs b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs
index ac078329524..f3271993867 100644
--- a/tests/ui/impl-trait/extra-impl-in-trait-impl.rs
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs
@@ -1,8 +1,6 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
 struct S<T>(T);
-#[allow(dead_code)]
 struct S2;
 
 impl<T: Default> impl Default for S<T> {
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
index 91c7da5a04f..5aafc8b64d4 100644
--- a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
@@ -1,23 +1,23 @@
 error: unexpected `impl` keyword
-  --> $DIR/extra-impl-in-trait-impl.rs:8:18
+  --> $DIR/extra-impl-in-trait-impl.rs:6:18
    |
 LL | impl<T: Default> impl Default for S<T> {
    |                  ^^^^^ help: remove the extra `impl`
    |
 note: this is parsed as an `impl Trait` type, but a trait is expected at this position
-  --> $DIR/extra-impl-in-trait-impl.rs:8:18
+  --> $DIR/extra-impl-in-trait-impl.rs:6:18
    |
 LL | impl<T: Default> impl Default for S<T> {
    |                  ^^^^^^^^^^^^
 
 error: unexpected `impl` keyword
-  --> $DIR/extra-impl-in-trait-impl.rs:14:6
+  --> $DIR/extra-impl-in-trait-impl.rs:12:6
    |
 LL | impl impl Default for S2 {
    |      ^^^^^ help: remove the extra `impl`
    |
 note: this is parsed as an `impl Trait` type, but a trait is expected at this position
-  --> $DIR/extra-impl-in-trait-impl.rs:14:6
+  --> $DIR/extra-impl-in-trait-impl.rs:12:6
    |
 LL | impl impl Default for S2 {
    |      ^^^^^^^^^^^^
diff --git a/tests/ui/issues/issue-5708.rs b/tests/ui/issues/issue-5708.rs
index 89ea9fbdcd8..ce9ef78ffcd 100644
--- a/tests/ui/issues/issue-5708.rs
+++ b/tests/ui/issues/issue-5708.rs
@@ -44,7 +44,6 @@ pub trait MyTrait<T> {
     fn dummy(&self, t: T) -> T { panic!() }
 }
 
-#[allow(dead_code)]
 pub struct MyContainer<'a, T:'a> {
     foos: Vec<&'a (dyn MyTrait<T>+'a)> ,
 }
diff --git a/tests/ui/lint/dead-code/allow-unconstructed-pub-struct.rs b/tests/ui/lint/dead-code/allow-unconstructed-pub-struct.rs
deleted file mode 100644
index 8cd1524045b..00000000000
--- a/tests/ui/lint/dead-code/allow-unconstructed-pub-struct.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-//@ check-pass
-
-mod ffi {
-    use super::*;
-
-    extern "C" {
-        pub fn DomPromise_AddRef(promise: *const Promise);
-        pub fn DomPromise_Release(promise: *const Promise);
-    }
-}
-
-#[repr(C)]
-#[allow(unused)]
-pub struct Promise {
-    private: [u8; 0],
-    __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>,
-}
-
-pub unsafe trait RefCounted {
-    unsafe fn addref(&self);
-    unsafe fn release(&self);
-}
-
-unsafe impl RefCounted for Promise {
-    unsafe fn addref(&self) {
-        ffi::DomPromise_AddRef(self)
-    }
-    unsafe fn release(&self) {
-        ffi::DomPromise_Release(self)
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/issue-59003.rs b/tests/ui/lint/dead-code/issue-59003.rs
index 319cf2db149..e3dcaca5778 100644
--- a/tests/ui/lint/dead-code/issue-59003.rs
+++ b/tests/ui/lint/dead-code/issue-59003.rs
@@ -4,8 +4,8 @@
 
 #![deny(dead_code)]
 
-#[allow(dead_code)]
 struct Foo {
+    #[allow(dead_code)]
     inner: u32,
 }
 
diff --git a/tests/ui/lint/dead-code/lint-dead-code-1.rs b/tests/ui/lint/dead-code/lint-dead-code-1.rs
index 3386dfa4747..ddcafedf7bc 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-1.rs
+++ b/tests/ui/lint/dead-code/lint-dead-code-1.rs
@@ -46,10 +46,11 @@ struct SemiUsedStruct;
 impl SemiUsedStruct {
     fn la_la_la() {}
 }
-struct StructUsedAsField; //~ ERROR struct `StructUsedAsField` is never constructed
+struct StructUsedAsField;
 pub struct StructUsedInEnum;
 struct StructUsedInGeneric;
-pub struct PubStruct2 { //~ ERROR struct `PubStruct2` is never constructed
+pub struct PubStruct2 {
+    #[allow(dead_code)]
     struct_used_as_field: *const StructUsedAsField
 }
 
diff --git a/tests/ui/lint/dead-code/lint-dead-code-1.stderr b/tests/ui/lint/dead-code/lint-dead-code-1.stderr
index b0163df8855..eb728b5b930 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-1.stderr
+++ b/tests/ui/lint/dead-code/lint-dead-code-1.stderr
@@ -22,26 +22,14 @@ error: struct `PrivStruct` is never constructed
 LL | struct PrivStruct;
    |        ^^^^^^^^^^
 
-error: struct `StructUsedAsField` is never constructed
-  --> $DIR/lint-dead-code-1.rs:49:8
-   |
-LL | struct StructUsedAsField;
-   |        ^^^^^^^^^^^^^^^^^
-
-error: struct `PubStruct2` is never constructed
-  --> $DIR/lint-dead-code-1.rs:52:12
-   |
-LL | pub struct PubStruct2 {
-   |            ^^^^^^^^^^
-
 error: enum `priv_enum` is never used
-  --> $DIR/lint-dead-code-1.rs:63:6
+  --> $DIR/lint-dead-code-1.rs:64:6
    |
 LL | enum priv_enum { foo2, bar2 }
    |      ^^^^^^^^^
 
 error: variant `bar3` is never constructed
-  --> $DIR/lint-dead-code-1.rs:66:5
+  --> $DIR/lint-dead-code-1.rs:67:5
    |
 LL | enum used_enum {
    |      --------- variant in this enum
@@ -50,25 +38,25 @@ LL |     bar3
    |     ^^^^
 
 error: function `priv_fn` is never used
-  --> $DIR/lint-dead-code-1.rs:87:4
+  --> $DIR/lint-dead-code-1.rs:88:4
    |
 LL | fn priv_fn() {
    |    ^^^^^^^
 
 error: function `foo` is never used
-  --> $DIR/lint-dead-code-1.rs:92:4
+  --> $DIR/lint-dead-code-1.rs:93:4
    |
 LL | fn foo() {
    |    ^^^
 
 error: function `bar` is never used
-  --> $DIR/lint-dead-code-1.rs:97:4
+  --> $DIR/lint-dead-code-1.rs:98:4
    |
 LL | fn bar() {
    |    ^^^
 
 error: function `baz` is never used
-  --> $DIR/lint-dead-code-1.rs:101:4
+  --> $DIR/lint-dead-code-1.rs:102:4
    |
 LL | fn baz() -> impl Copy {
    |    ^^^
@@ -79,5 +67,5 @@ error: struct `Bar` is never constructed
 LL |     pub struct Bar;
    |                ^^^
 
-error: aborting due to 12 previous errors
+error: aborting due to 10 previous errors
 
diff --git a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs
deleted file mode 100644
index 25777438456..00000000000
--- a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-#![deny(dead_code)]
-
-struct Foo(u8); //~ ERROR struct `Foo` is never constructed
-
-enum Bar { //~ ERROR enum `Bar` is never used
-    Var1(u8),
-    Var2(u8),
-}
-
-pub trait Tr1 {
-    fn f1() -> Self;
-}
-
-impl Tr1 for Foo {
-    fn f1() -> Foo {
-        let f = Foo(0);
-        let Foo(tag) = f;
-        Foo(tag)
-    }
-}
-
-impl Tr1 for Bar {
-    fn f1() -> Bar {
-        let b = Bar::Var1(0);
-        let b = if let Bar::Var1(_) = b {
-            Bar::Var1(0)
-        } else {
-            Bar::Var2(0)
-        };
-        match b {
-            Bar::Var1(_) => Bar::Var2(0),
-            Bar::Var2(_) => Bar::Var1(0),
-        }
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr b/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr
deleted file mode 100644
index 7c1a4b45977..00000000000
--- a/tests/ui/lint/dead-code/lint-unused-adt-appeared-in-pattern.stderr
+++ /dev/null
@@ -1,20 +0,0 @@
-error: struct `Foo` is never constructed
-  --> $DIR/lint-unused-adt-appeared-in-pattern.rs:3:8
-   |
-LL | struct Foo(u8);
-   |        ^^^
-   |
-note: the lint level is defined here
-  --> $DIR/lint-unused-adt-appeared-in-pattern.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: enum `Bar` is never used
-  --> $DIR/lint-unused-adt-appeared-in-pattern.rs:5:6
-   |
-LL | enum Bar {
-   |      ^^^
-
-error: aborting due to 2 previous errors
-
diff --git a/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs b/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs
deleted file mode 100644
index 43a2e431904..00000000000
--- a/tests/ui/lint/dead-code/not-lint-used-adt-appeared-in-pattern.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-//@ check-pass
-
-#![deny(dead_code)]
-
-#[repr(u8)]
-#[derive(Copy, Clone, Debug)]
-pub enum RecordField {
-    Target = 1,
-    Level,
-    Module,
-    File,
-    Line,
-    NumArgs,
-}
-
-unsafe trait Pod {}
-
-#[repr(transparent)]
-struct RecordFieldWrapper(RecordField);
-
-unsafe impl Pod for RecordFieldWrapper {}
-
-fn try_read<T: Pod>(buf: &[u8]) -> T {
-    unsafe { std::ptr::read_unaligned(buf.as_ptr() as *const T) }
-}
-
-pub fn foo(buf: &[u8]) -> RecordField {
-    let RecordFieldWrapper(tag) = try_read(buf);
-    tag
-}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/unconstructible-pub-struct.rs b/tests/ui/lint/dead-code/unconstructible-pub-struct.rs
deleted file mode 100644
index 2202cbb6730..00000000000
--- a/tests/ui/lint/dead-code/unconstructible-pub-struct.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-#![feature(never_type)]
-#![deny(dead_code)]
-
-pub struct T1(!);
-pub struct T2(());
-pub struct T3<X>(std::marker::PhantomData<X>);
-
-pub struct T4 {
-    _x: !,
-}
-
-pub struct T5<X> {
-    _x: !,
-    _y: X,
-}
-
-pub struct T6 {
-    _x: (),
-}
-
-pub struct T7<X> {
-    _x: (),
-    _y: X,
-}
-
-pub struct T8<X> {
-    _x: std::marker::PhantomData<X>,
-}
-
-pub struct T9<X> { //~ ERROR struct `T9` is never constructed
-    _x: std::marker::PhantomData<X>,
-    _y: i32,
-}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/unconstructible-pub-struct.stderr b/tests/ui/lint/dead-code/unconstructible-pub-struct.stderr
deleted file mode 100644
index a3dde042bbe..00000000000
--- a/tests/ui/lint/dead-code/unconstructible-pub-struct.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-error: struct `T9` is never constructed
-  --> $DIR/unconstructible-pub-struct.rs:30:12
-   |
-LL | pub struct T9<X> {
-   |            ^^
-   |
-note: the lint level is defined here
-  --> $DIR/unconstructible-pub-struct.rs:2:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs
index 658cc3d6c61..5b755d62a05 100644
--- a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs
+++ b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.rs
@@ -1,9 +1,8 @@
 #![deny(dead_code)]
 
 struct T1; //~ ERROR struct `T1` is never constructed
-struct T2; //~ ERROR struct `T2` is never constructed
-pub struct T3(i32); //~ ERROR struct `T3` is never constructed
-pub struct T4(i32); //~ ERROR field `0` is never read
+pub struct T2(i32); //~ ERROR field `0` is never read
+struct T3;
 
 trait Trait1 { //~ ERROR trait `Trait1` is never used
     const UNUSED: i32;
@@ -12,13 +11,13 @@ trait Trait1 { //~ ERROR trait `Trait1` is never used
 }
 
 pub trait Trait2 {
-    const MAY_USED: i32;
-    fn may_used(&self) {}
+    const USED: i32;
+    fn used(&self) {}
 }
 
 pub trait Trait3 {
-    const MAY_USED: i32;
-    fn may_used() -> Self;
+    const USED: i32;
+    fn construct_self() -> Self;
 }
 
 impl Trait1 for T1 {
@@ -31,34 +30,23 @@ impl Trait1 for T1 {
 impl Trait1 for T2 {
     const UNUSED: i32 = 0;
     fn construct_self() -> Self {
-        Self
+        T2(0)
     }
 }
 
 impl Trait2 for T1 {
-    const MAY_USED: i32 = 0;
+    const USED: i32 = 0;
 }
 
 impl Trait2 for T2 {
-    const MAY_USED: i32 = 0;
-}
-
-impl Trait2 for T3 {
-    const MAY_USED: i32 = 0;
+    const USED: i32 = 0;
 }
 
-impl Trait3 for T2 {
-    const MAY_USED: i32 = 0;
-    fn may_used() -> Self {
+impl Trait3 for T3 {
+    const USED: i32 = 0;
+    fn construct_self() -> Self {
         Self
     }
 }
 
-impl Trait3 for T4 {
-    const MAY_USED: i32 = 0;
-    fn may_used() -> Self {
-        T4(0)
-    }
-}
-
 fn main() {}
diff --git a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr
index 08c7a5cb4b0..2441a3f868d 100644
--- a/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr
+++ b/tests/ui/lint/dead-code/unused-adt-impl-pub-trait-with-assoc-const.stderr
@@ -10,22 +10,10 @@ note: the lint level is defined here
 LL | #![deny(dead_code)]
    |         ^^^^^^^^^
 
-error: struct `T2` is never constructed
-  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:8
-   |
-LL | struct T2;
-   |        ^^
-
-error: struct `T3` is never constructed
-  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:5:12
-   |
-LL | pub struct T3(i32);
-   |            ^^
-
 error: field `0` is never read
-  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:6:15
+  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:4:15
    |
-LL | pub struct T4(i32);
+LL | pub struct T2(i32);
    |            -- ^^^
    |            |
    |            field in this struct
@@ -33,10 +21,10 @@ LL | pub struct T4(i32);
    = help: consider removing this field
 
 error: trait `Trait1` is never used
-  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:8:7
+  --> $DIR/unused-adt-impl-pub-trait-with-assoc-const.rs:7:7
    |
 LL | trait Trait1 {
    |       ^^^^^^
 
-error: aborting due to 5 previous errors
+error: aborting due to 3 previous errors
 
diff --git a/tests/ui/lint/dead-code/unused-assoc-const.rs b/tests/ui/lint/dead-code/unused-assoc-const.rs
deleted file mode 100644
index 36e8315ad36..00000000000
--- a/tests/ui/lint/dead-code/unused-assoc-const.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-#![deny(dead_code)]
-
-trait Trait {
-    const UNUSED_CONST: i32; //~ ERROR associated constant `UNUSED_CONST` is never used
-    const USED_CONST: i32;
-
-    fn foo(&self) {}
-}
-
-pub struct T(());
-
-impl Trait for T {
-    const UNUSED_CONST: i32 = 0;
-    const USED_CONST: i32 = 1;
-}
-
-fn main() {
-    T(()).foo();
-    T::USED_CONST;
-}
diff --git a/tests/ui/lint/dead-code/unused-assoc-const.stderr b/tests/ui/lint/dead-code/unused-assoc-const.stderr
deleted file mode 100644
index 78296d70663..00000000000
--- a/tests/ui/lint/dead-code/unused-assoc-const.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error: associated constant `UNUSED_CONST` is never used
-  --> $DIR/unused-assoc-const.rs:4:11
-   |
-LL | trait Trait {
-   |       ----- associated constant in this trait
-LL |     const UNUSED_CONST: i32;
-   |           ^^^^^^^^^^^^
-   |
-note: the lint level is defined here
-  --> $DIR/unused-assoc-const.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/lint/dead-code/unused-impl-for-non-adts.rs b/tests/ui/lint/dead-code/unused-impl-for-non-adts.rs
deleted file mode 100644
index 46065dcee81..00000000000
--- a/tests/ui/lint/dead-code/unused-impl-for-non-adts.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-#![deny(dead_code)]
-
-struct Foo; //~ ERROR struct `Foo` is never constructed
-
-trait Trait { //~ ERROR trait `Trait` is never used
-    fn foo(&self) {}
-}
-
-impl Trait for Foo {}
-
-impl Trait for [Foo] {}
-impl<const N: usize> Trait for [Foo; N] {}
-
-impl Trait for *const Foo {}
-impl Trait for *mut Foo {}
-
-impl Trait for &Foo {}
-impl Trait for &&Foo {}
-impl Trait for &mut Foo {}
-
-impl Trait for [&Foo] {}
-impl Trait for &[Foo] {}
-impl Trait for &*const Foo {}
-
-pub trait Trait2 {
-    fn foo(&self) {}
-}
-
-impl Trait2 for Foo {}
-
-impl Trait2 for [Foo] {}
-impl<const N: usize> Trait2 for [Foo; N] {}
-
-impl Trait2 for *const Foo {}
-impl Trait2 for *mut Foo {}
-
-impl Trait2 for &Foo {}
-impl Trait2 for &&Foo {}
-impl Trait2 for &mut Foo {}
-
-impl Trait2 for [&Foo] {}
-impl Trait2 for &[Foo] {}
-impl Trait2 for &*const Foo {}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/unused-impl-for-non-adts.stderr b/tests/ui/lint/dead-code/unused-impl-for-non-adts.stderr
deleted file mode 100644
index e61fc403e81..00000000000
--- a/tests/ui/lint/dead-code/unused-impl-for-non-adts.stderr
+++ /dev/null
@@ -1,20 +0,0 @@
-error: struct `Foo` is never constructed
-  --> $DIR/unused-impl-for-non-adts.rs:3:8
-   |
-LL | struct Foo;
-   |        ^^^
-   |
-note: the lint level is defined here
-  --> $DIR/unused-impl-for-non-adts.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: trait `Trait` is never used
-  --> $DIR/unused-impl-for-non-adts.rs:5:7
-   |
-LL | trait Trait {
-   |       ^^^^^
-
-error: aborting due to 2 previous errors
-
diff --git a/tests/ui/lint/dead-code/unused-pub-struct.rs b/tests/ui/lint/dead-code/unused-pub-struct.rs
deleted file mode 100644
index aaf4dd612de..00000000000
--- a/tests/ui/lint/dead-code/unused-pub-struct.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-#![deny(dead_code)]
-
-pub struct NotLint1(());
-pub struct NotLint2(std::marker::PhantomData<i32>);
-
-pub struct NeverConstructed(i32); //~ ERROR struct `NeverConstructed` is never constructed
-
-impl NeverConstructed {
-    pub fn not_construct_self(&self) {}
-}
-
-impl Clone for NeverConstructed {
-    fn clone(&self) -> NeverConstructed {
-        NeverConstructed(0)
-    }
-}
-
-pub trait Trait {
-    fn not_construct_self(&self);
-}
-
-impl Trait for NeverConstructed {
-    fn not_construct_self(&self) {
-        self.0;
-    }
-}
-
-pub struct Constructed(i32);
-
-impl Constructed {
-    pub fn construct_self() -> Self {
-        Constructed(0)
-    }
-}
-
-impl Clone for Constructed {
-    fn clone(&self) -> Constructed {
-        Constructed(0)
-    }
-}
-
-impl Trait for Constructed {
-    fn not_construct_self(&self) {
-        self.0;
-    }
-}
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/unused-pub-struct.stderr b/tests/ui/lint/dead-code/unused-pub-struct.stderr
deleted file mode 100644
index 3667ddb97bd..00000000000
--- a/tests/ui/lint/dead-code/unused-pub-struct.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-error: struct `NeverConstructed` is never constructed
-  --> $DIR/unused-pub-struct.rs:6:12
-   |
-LL | pub struct NeverConstructed(i32);
-   |            ^^^^^^^^^^^^^^^^
-   |
-note: the lint level is defined here
-  --> $DIR/unused-pub-struct.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/lint/dead-code/unused-struct-derive-default.rs b/tests/ui/lint/dead-code/unused-struct-derive-default.rs
index f20b7cb66ee..330ad32dd57 100644
--- a/tests/ui/lint/dead-code/unused-struct-derive-default.rs
+++ b/tests/ui/lint/dead-code/unused-struct-derive-default.rs
@@ -22,5 +22,4 @@ pub struct T2 {
 
 fn main() {
     let _x: Used = Default::default();
-    let _e: E = Default::default();
 }
diff --git a/tests/ui/lint/dead-code/unused-struct-derive-default.stderr b/tests/ui/lint/dead-code/unused-struct-derive-default.stderr
index 7422f9a39f3..bbb0bd7be70 100644
--- a/tests/ui/lint/dead-code/unused-struct-derive-default.stderr
+++ b/tests/ui/lint/dead-code/unused-struct-derive-default.stderr
@@ -4,6 +4,7 @@ error: struct `T` is never constructed
 LL | struct T;
    |        ^
    |
+   = note: `T` has a derived impl for the trait `Default`, but this is intentionally ignored during dead code analysis
 note: the lint level is defined here
   --> $DIR/unused-struct-derive-default.rs:1:9
    |
diff --git a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs
deleted file mode 100644
index e8116d83ebf..00000000000
--- a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-#![deny(dead_code)]
-
-struct T1; //~ ERROR struct `T1` is never constructed
-
-trait Foo { type Unused; } //~ ERROR trait `Foo` is never used
-impl Foo for T1 { type Unused = Self; }
-
-pub trait Bar { type Used; }
-impl Bar for T1 { type Used = Self; }
-
-fn main() {}
diff --git a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr
deleted file mode 100644
index ab73c640634..00000000000
--- a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr
+++ /dev/null
@@ -1,20 +0,0 @@
-error: struct `T1` is never constructed
-  --> $DIR/unused-trait-with-assoc-ty.rs:3:8
-   |
-LL | struct T1;
-   |        ^^
-   |
-note: the lint level is defined here
-  --> $DIR/unused-trait-with-assoc-ty.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: trait `Foo` is never used
-  --> $DIR/unused-trait-with-assoc-ty.rs:5:7
-   |
-LL | trait Foo { type Unused; }
-   |       ^^^
-
-error: aborting due to 2 previous errors
-
diff --git a/tests/ui/parser/issues/issue-105366.fixed b/tests/ui/parser/issues/issue-105366.fixed
index 95419dc07f2..7157b647524 100644
--- a/tests/ui/parser/issues/issue-105366.fixed
+++ b/tests/ui/parser/issues/issue-105366.fixed
@@ -1,6 +1,5 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
 struct Foo;
 
 impl From<i32> for Foo {
diff --git a/tests/ui/parser/issues/issue-105366.rs b/tests/ui/parser/issues/issue-105366.rs
index 3278b737991..dc3cb8b343d 100644
--- a/tests/ui/parser/issues/issue-105366.rs
+++ b/tests/ui/parser/issues/issue-105366.rs
@@ -1,6 +1,5 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
 struct Foo;
 
 fn From<i32> for Foo {
diff --git a/tests/ui/parser/issues/issue-105366.stderr b/tests/ui/parser/issues/issue-105366.stderr
index 195305a2ec8..18c04dfaf20 100644
--- a/tests/ui/parser/issues/issue-105366.stderr
+++ b/tests/ui/parser/issues/issue-105366.stderr
@@ -1,5 +1,5 @@
 error: you might have meant to write `impl` instead of `fn`
-  --> $DIR/issue-105366.rs:6:1
+  --> $DIR/issue-105366.rs:5:1
    |
 LL | fn From<i32> for Foo {
    | ^^
diff --git a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.fixed b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.fixed
index e9c89807fa5..a851300a982 100644
--- a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.fixed
+++ b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.fixed
@@ -1,8 +1,7 @@
 // Regression test for issues #100790 and #106439.
 //@ run-rustfix
 
-#[allow(dead_code)]
-pub struct Example(usize)
+pub struct Example(#[allow(dead_code)] usize)
 where
     (): Sized;
 //~^^^ ERROR where clauses are not allowed before tuple struct bodies
diff --git a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.rs b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.rs
index 3bd0f51ec2c..10f435859f1 100644
--- a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.rs
+++ b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.rs
@@ -1,11 +1,10 @@
 // Regression test for issues #100790 and #106439.
 //@ run-rustfix
 
-#[allow(dead_code)]
 pub struct Example
 where
     (): Sized,
-(usize);
+(#[allow(dead_code)] usize);
 //~^^^ ERROR where clauses are not allowed before tuple struct bodies
 
 struct _Demo
diff --git a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.stderr b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.stderr
index 77eafa6bea3..ddbf237e866 100644
--- a/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.stderr
+++ b/tests/ui/parser/recover/recover-where-clause-before-tuple-struct-body-0.stderr
@@ -1,23 +1,23 @@
 error: where clauses are not allowed before tuple struct bodies
-  --> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:6:1
+  --> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:5:1
    |
 LL |   pub struct Example
    |              ------- while parsing this tuple struct
 LL | / where
 LL | |     (): Sized,
    | |______________^ unexpected where clause
-LL |   (usize);
-   |   ------- the struct body
+LL |   (#[allow(dead_code)] usize);
+   |   --------------------------- the struct body
    |
 help: move the body before the where clause
    |
-LL ~ pub struct Example(usize)
+LL ~ pub struct Example(#[allow(dead_code)] usize)
 LL | where
 LL ~     (): Sized;
    |
 
 error: where clauses are not allowed before tuple struct bodies
-  --> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:12:1
+  --> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:11:1
    |
 LL |   struct _Demo
    |          ----- while parsing this tuple struct
diff --git a/tests/ui/pattern/issue-22546.rs b/tests/ui/pattern/issue-22546.rs
index d5c5b68be78..fd1d5fb6c47 100644
--- a/tests/ui/pattern/issue-22546.rs
+++ b/tests/ui/pattern/issue-22546.rs
@@ -15,7 +15,7 @@ impl<T: ::std::fmt::Display> Foo<T> {
     }
 }
 
-trait Tr {
+trait Tr { //~ WARN trait `Tr` is never used
     type U;
 }
 
diff --git a/tests/ui/pattern/issue-22546.stderr b/tests/ui/pattern/issue-22546.stderr
new file mode 100644
index 00000000000..e067a95e422
--- /dev/null
+++ b/tests/ui/pattern/issue-22546.stderr
@@ -0,0 +1,10 @@
+warning: trait `Tr` is never used
+  --> $DIR/issue-22546.rs:18:7
+   |
+LL | trait Tr {
+   |       ^^
+   |
+   = note: `#[warn(dead_code)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/pub/pub-ident-struct-4.fixed b/tests/ui/pub/pub-ident-struct-4.fixed
index a62ece43ece..5fedbb72437 100644
--- a/tests/ui/pub/pub-ident-struct-4.fixed
+++ b/tests/ui/pub/pub-ident-struct-4.fixed
@@ -1,7 +1,6 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
-pub struct T(String);
+pub struct T(#[allow(dead_code)] String);
 //~^ ERROR missing `struct` for struct definition
 
 fn main() {}
diff --git a/tests/ui/pub/pub-ident-struct-4.rs b/tests/ui/pub/pub-ident-struct-4.rs
index 0d56a31beaf..5c721c25a78 100644
--- a/tests/ui/pub/pub-ident-struct-4.rs
+++ b/tests/ui/pub/pub-ident-struct-4.rs
@@ -1,7 +1,6 @@
 //@ run-rustfix
 
-#[allow(dead_code)]
-pub T(String);
+pub T(#[allow(dead_code)] String);
 //~^ ERROR missing `struct` for struct definition
 
 fn main() {}
diff --git a/tests/ui/pub/pub-ident-struct-4.stderr b/tests/ui/pub/pub-ident-struct-4.stderr
index d3072464e05..04965a1a737 100644
--- a/tests/ui/pub/pub-ident-struct-4.stderr
+++ b/tests/ui/pub/pub-ident-struct-4.stderr
@@ -1,12 +1,12 @@
 error: missing `struct` for struct definition
-  --> $DIR/pub-ident-struct-4.rs:4:1
+  --> $DIR/pub-ident-struct-4.rs:3:1
    |
-LL | pub T(String);
+LL | pub T(#[allow(dead_code)] String);
    | ^^^^^
    |
 help: add `struct` here to parse `T` as a struct
    |
-LL | pub struct T(String);
+LL | pub struct T(#[allow(dead_code)] String);
    |     ++++++
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/regions/regions-issue-21422.rs b/tests/ui/regions/regions-issue-21422.rs
index 67852a6f5de..54beed9b3ac 100644
--- a/tests/ui/regions/regions-issue-21422.rs
+++ b/tests/ui/regions/regions-issue-21422.rs
@@ -5,7 +5,6 @@
 
 //@ pretty-expanded FIXME #23616
 
-#[allow(dead_code)]
 pub struct P<'a> {
     _ptr: *const &'a u8,
 }
diff --git a/tests/ui/structs-enums/newtype-struct-with-dtor.rs b/tests/ui/structs-enums/newtype-struct-with-dtor.rs
index 16439a7fedd..19672e41c9a 100644
--- a/tests/ui/structs-enums/newtype-struct-with-dtor.rs
+++ b/tests/ui/structs-enums/newtype-struct-with-dtor.rs
@@ -3,10 +3,8 @@
 #![allow(unused_variables)]
 //@ pretty-expanded FIXME #23616
 
-#[allow(dead_code)]
 pub struct Fd(u32);
 
-#[allow(dead_code)]
 fn foo(a: u32) {}
 
 impl Drop for Fd {
diff --git a/tests/ui/structs-enums/uninstantiable-struct.rs b/tests/ui/structs-enums/uninstantiable-struct.rs
index 1074dbcd6e6..97bc7d8414e 100644
--- a/tests/ui/structs-enums/uninstantiable-struct.rs
+++ b/tests/ui/structs-enums/uninstantiable-struct.rs
@@ -1,5 +1,4 @@
 //@ run-pass
-#[allow(dead_code)]
-pub struct Z(&'static Z);
+pub struct Z(#[allow(dead_code)] &'static Z);
 
 pub fn main() {}
diff --git a/tests/ui/suggestions/derive-clone-for-eq.fixed b/tests/ui/suggestions/derive-clone-for-eq.fixed
index cf800c6e47d..4dc362f9478 100644
--- a/tests/ui/suggestions/derive-clone-for-eq.fixed
+++ b/tests/ui/suggestions/derive-clone-for-eq.fixed
@@ -1,7 +1,6 @@
 //@ run-rustfix
 // https://github.com/rust-lang/rust/issues/79076
 
-#[allow(dead_code)]
 #[derive(Clone, Eq)] //~ ERROR [E0277]
 pub struct Struct<T: std::clone::Clone>(T);
 
diff --git a/tests/ui/suggestions/derive-clone-for-eq.rs b/tests/ui/suggestions/derive-clone-for-eq.rs
index 84736426bac..b3635000f16 100644
--- a/tests/ui/suggestions/derive-clone-for-eq.rs
+++ b/tests/ui/suggestions/derive-clone-for-eq.rs
@@ -1,7 +1,6 @@
 //@ run-rustfix
 // https://github.com/rust-lang/rust/issues/79076
 
-#[allow(dead_code)]
 #[derive(Clone, Eq)] //~ ERROR [E0277]
 pub struct Struct<T>(T);
 
diff --git a/tests/ui/suggestions/derive-clone-for-eq.stderr b/tests/ui/suggestions/derive-clone-for-eq.stderr
index 54670fbffcf..6fae6e1316d 100644
--- a/tests/ui/suggestions/derive-clone-for-eq.stderr
+++ b/tests/ui/suggestions/derive-clone-for-eq.stderr
@@ -1,11 +1,11 @@
 error[E0277]: the trait bound `T: Clone` is not satisfied
-  --> $DIR/derive-clone-for-eq.rs:5:17
+  --> $DIR/derive-clone-for-eq.rs:4:17
    |
 LL | #[derive(Clone, Eq)]
    |                 ^^ the trait `Clone` is not implemented for `T`, which is required by `Struct<T>: PartialEq`
    |
 note: required for `Struct<T>` to implement `PartialEq`
-  --> $DIR/derive-clone-for-eq.rs:8:19
+  --> $DIR/derive-clone-for-eq.rs:7:19
    |
 LL | impl<T: Clone, U> PartialEq<U> for Struct<T>
    |         -----     ^^^^^^^^^^^^     ^^^^^^^^^
diff --git a/tests/ui/suggestions/option-content-move.fixed b/tests/ui/suggestions/option-content-move.fixed
index ef07d55871e..4a5a9483c20 100644
--- a/tests/ui/suggestions/option-content-move.fixed
+++ b/tests/ui/suggestions/option-content-move.fixed
@@ -1,5 +1,4 @@
 //@ run-rustfix
-#[allow(dead_code)]
 pub struct LipogramCorpora {
     selections: Vec<(char, Option<String>)>,
 }
@@ -18,7 +17,6 @@ impl LipogramCorpora {
     }
 }
 
-#[allow(dead_code)]
 pub struct LipogramCorpora2 {
     selections: Vec<(char, Result<String, String>)>,
 }
diff --git a/tests/ui/suggestions/option-content-move.rs b/tests/ui/suggestions/option-content-move.rs
index 5be6358fd6a..90d05c74399 100644
--- a/tests/ui/suggestions/option-content-move.rs
+++ b/tests/ui/suggestions/option-content-move.rs
@@ -1,5 +1,4 @@
 //@ run-rustfix
-#[allow(dead_code)]
 pub struct LipogramCorpora {
     selections: Vec<(char, Option<String>)>,
 }
@@ -18,7 +17,6 @@ impl LipogramCorpora {
     }
 }
 
-#[allow(dead_code)]
 pub struct LipogramCorpora2 {
     selections: Vec<(char, Result<String, String>)>,
 }
diff --git a/tests/ui/suggestions/option-content-move.stderr b/tests/ui/suggestions/option-content-move.stderr
index b4ec5b180d2..a382a04344a 100644
--- a/tests/ui/suggestions/option-content-move.stderr
+++ b/tests/ui/suggestions/option-content-move.stderr
@@ -1,5 +1,5 @@
 error[E0507]: cannot move out of `selection.1` which is behind a shared reference
-  --> $DIR/option-content-move.rs:11:20
+  --> $DIR/option-content-move.rs:10:20
    |
 LL |                 if selection.1.unwrap().contains(selection.0) {
    |                    ^^^^^^^^^^^ -------- `selection.1` moved due to this method call
@@ -19,7 +19,7 @@ LL |                 if selection.1.clone().unwrap().contains(selection.0) {
    |                               ++++++++
 
 error[E0507]: cannot move out of `selection.1` which is behind a shared reference
-  --> $DIR/option-content-move.rs:30:20
+  --> $DIR/option-content-move.rs:28:20
    |
 LL |                 if selection.1.unwrap().contains(selection.0) {
    |                    ^^^^^^^^^^^ -------- `selection.1` moved due to this method call
diff --git a/tests/ui/traits/object/generics.rs b/tests/ui/traits/object/generics.rs
index 0ae562c0d30..462b0bc5bb7 100644
--- a/tests/ui/traits/object/generics.rs
+++ b/tests/ui/traits/object/generics.rs
@@ -7,7 +7,6 @@ pub trait Trait2<A> {
     fn doit(&self) -> A;
 }
 
-#[allow(dead_code)]
 pub struct Impl<A1, A2, A3> {
     m1: marker::PhantomData<(A1,A2,A3)>,
     /*