diff --git a/RELEASES.md b/RELEASES.md
index 0ecd472efb6e2..a8616ec39f7c6 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,4 +1,12 @@
-Version 1.80 (2024-07-25)
+Version 1.80.1 (2024-08-08)
+===========================
+
+
+
+- [Fix miscompilation in the jump threading MIR optimization when comparing floats](https://github.com/rust-lang/rust/pull/128271)
+- [Revert changes to the `dead_code` lint from 1.80.0](https://github.com/rust-lang/rust/pull/128618)
+
+Version 1.80.0 (2024-07-25)
==========================
diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs
index 23cc0c46e7397..279fd614918e2 100644
--- a/compiler/rustc_mir_transform/src/jump_threading.rs
+++ b/compiler/rustc_mir_transform/src/jump_threading.rs
@@ -494,6 +494,13 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
BinOp::Ne => ScalarInt::FALSE,
_ => return None,
};
+ if value.const_.ty().is_floating_point() {
+ // Floating point equality does not follow bit-patterns.
+ // -0.0 and NaN both have special rules for equality,
+ // and therefore we cannot use integer comparisons for them.
+ // Avoid handling them, though this could be extended in the future.
+ return None;
+ }
let value = value.const_.normalize(self.tcx, self.param_env).try_to_scalar_int()?;
let conds = conditions.map(self.arena, |c| Condition {
value,
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index d849305d99636..ddc50e2b811a2 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -15,7 +15,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,63 +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 struct_all_fields_are_public(tcx: TyCtxt<'_>, id: DefId) -> bool {
- // treat PhantomData and positional ZST as public,
- // we don't want to lint types which only have them,
- // cause it's a common way to use such types to check things like well-formedness
- tcx.adt_def(id).all_fields().all(|field| {
- let field_type = tcx.type_of(field.did).instantiate_identity();
- if field_type.is_phantom_data() {
- return true;
- }
- let is_positional = field.name.as_str().starts_with(|c: char| c.is_ascii_digit());
- if is_positional
- && tcx
- .layout_of(tcx.param_env(field.did).and(field_type))
- .map_or(true, |layout| layout.is_zst())
- {
- 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 {
+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)
{
- 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),
- };
+ tcx.visibility(def_id).is_public()
+ } else {
+ true
}
-
- Publicness::new(true, true)
}
/// Determine if a work from the worklist is coming from the a `#[allow]`
@@ -474,11 +427,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
{
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..))
&& !ty_ref_to_pub_struct(self.tcx, impl_ref.self_ty)
- .ty_and_all_fields_are_public
{
- // 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;
}
@@ -559,21 +510,22 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
&& 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
}
}
@@ -795,9 +747,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 {
@@ -813,20 +763,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 of_trait && matches!(tcx.def_kind(local_def_id), DefKind::AssocTy)
- || tcx.visibility(local_def_id).is_public()
- && (ty_and_all_fields_are_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));
}
}
@@ -893,14 +841,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::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
- DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
- _ => true
- })
.map(|id| (id, ComesFromAllowExpect::No))
})
// Seed entry point
@@ -1173,15 +1113,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 assoc consts and fns 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::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
- || def_kind == DefKind::Trait && tcx.def_kind(def_id) == DefKind::AssocTy
+ && tcx.def_kind(def_id) == DefKind::AssocFn
+ || def_kind == DefKind::Trait && tcx.def_kind(def_id) != DefKind::AssocFn
{
continue;
}
diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml
index 8c84e721f5de5..c59eb03a5c486 100644
--- a/src/ci/github-actions/jobs.yml
+++ b/src/ci/github-actions/jobs.yml
@@ -33,7 +33,7 @@ runners:
<<: *base-job
- &job-aarch64-linux
- os: [ self-hosted, ARM64, linux ]
+ os: ubuntu-22.04-arm64-8core-32gb
envs:
env-x86_64-apple-tests: &env-x86_64-apple-tests
diff --git a/src/version b/src/version
index aaceec04e0401..97e98527c3a98 100644
--- a/src/version
+++ b/src/version
@@ -1 +1 @@
-1.80.0
+1.80.1
diff --git a/tests/codegen-units/item-collection/generic-impl.rs b/tests/codegen-units/item-collection/generic-impl.rs
index b4cd99272b152..23d09e0d8af3e 100644
--- a/tests/codegen-units/item-collection/generic-impl.rs
+++ b/tests/codegen-units/item-collection/generic-impl.rs
@@ -22,16 +22,16 @@ impl Struct {
}
}
-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(&self) {}
diff --git a/tests/codegen-units/item-collection/overloaded-operators.rs b/tests/codegen-units/item-collection/overloaded-operators.rs
index e00e22dbab996..69b55695d3d30 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 for _Indexable {
+impl Index for Indexable {
type Output = u8;
- //~ MONO_ITEM fn <_Indexable as std::ops::Index>::index
+ //~ MONO_ITEM fn >::index
fn index(&self, index: usize) -> &Self::Output {
if index >= 3 { &self.data[0] } else { &self.data[index] }
}
}
-impl IndexMut for _Indexable {
- //~ MONO_ITEM fn <_Indexable as std::ops::IndexMut>::index_mut
+impl IndexMut for Indexable {
+ //~ MONO_ITEM fn >::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 ::eq
+//~ MONO_ITEM fn ::ne
#[derive(PartialEq)]
-pub struct _Equatable(u32);
+pub struct Equatable(u32);
-impl Add for _Equatable {
+impl Add for Equatable {
type Output = u32;
- //~ MONO_ITEM fn <_Equatable as std::ops::Add>::add
+ //~ MONO_ITEM fn >::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 ::deref
fn deref(&self) -> &Self::Target {
&self.0
}
diff --git a/tests/mir-opt/jump_threading.floats.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.floats.JumpThreading.panic-abort.diff
new file mode 100644
index 0000000000000..6ca37e96d297b
--- /dev/null
+++ b/tests/mir-opt/jump_threading.floats.JumpThreading.panic-abort.diff
@@ -0,0 +1,59 @@
+- // MIR for `floats` before JumpThreading
++ // MIR for `floats` after JumpThreading
+
+ fn floats() -> u32 {
+ let mut _0: u32;
+ let _1: f64;
+ let mut _2: bool;
+ let mut _3: bool;
+ let mut _4: f64;
+ scope 1 {
+ debug x => _1;
+ }
+
+ bb0: {
+ StorageLive(_1);
+ StorageLive(_2);
+ _2 = const true;
+- switchInt(move _2) -> [0: bb2, otherwise: bb1];
++ goto -> bb1;
+ }
+
+ bb1: {
+ _1 = const -0f64;
+ goto -> bb3;
+ }
+
+ bb2: {
+ _1 = const 1f64;
+ goto -> bb3;
+ }
+
+ bb3: {
+ StorageDead(_2);
+ StorageLive(_3);
+ StorageLive(_4);
+ _4 = _1;
+ _3 = Eq(move _4, const 0f64);
+ switchInt(move _3) -> [0: bb5, otherwise: bb4];
+ }
+
+ bb4: {
+ StorageDead(_4);
+ _0 = const 0_u32;
+ goto -> bb6;
+ }
+
+ bb5: {
+ StorageDead(_4);
+ _0 = const 1_u32;
+ goto -> bb6;
+ }
+
+ bb6: {
+ StorageDead(_3);
+ StorageDead(_1);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/jump_threading.floats.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.floats.JumpThreading.panic-unwind.diff
new file mode 100644
index 0000000000000..6ca37e96d297b
--- /dev/null
+++ b/tests/mir-opt/jump_threading.floats.JumpThreading.panic-unwind.diff
@@ -0,0 +1,59 @@
+- // MIR for `floats` before JumpThreading
++ // MIR for `floats` after JumpThreading
+
+ fn floats() -> u32 {
+ let mut _0: u32;
+ let _1: f64;
+ let mut _2: bool;
+ let mut _3: bool;
+ let mut _4: f64;
+ scope 1 {
+ debug x => _1;
+ }
+
+ bb0: {
+ StorageLive(_1);
+ StorageLive(_2);
+ _2 = const true;
+- switchInt(move _2) -> [0: bb2, otherwise: bb1];
++ goto -> bb1;
+ }
+
+ bb1: {
+ _1 = const -0f64;
+ goto -> bb3;
+ }
+
+ bb2: {
+ _1 = const 1f64;
+ goto -> bb3;
+ }
+
+ bb3: {
+ StorageDead(_2);
+ StorageLive(_3);
+ StorageLive(_4);
+ _4 = _1;
+ _3 = Eq(move _4, const 0f64);
+ switchInt(move _3) -> [0: bb5, otherwise: bb4];
+ }
+
+ bb4: {
+ StorageDead(_4);
+ _0 = const 0_u32;
+ goto -> bb6;
+ }
+
+ bb5: {
+ StorageDead(_4);
+ _0 = const 1_u32;
+ goto -> bb6;
+ }
+
+ bb6: {
+ StorageDead(_3);
+ StorageDead(_1);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs
index b4c133716800c..002200e6fb4a1 100644
--- a/tests/mir-opt/jump_threading.rs
+++ b/tests/mir-opt/jump_threading.rs
@@ -506,6 +506,16 @@ fn assume(a: u8, b: bool) -> u8 {
}
}
+fn floats() -> u32 {
+ // CHECK-LABEL: fn floats(
+ // CHECK: switchInt(
+
+ // Test for issue #128243, where float equality was assumed to be bitwise.
+ // When adding float support, it must be ensured that this continues working properly.
+ let x = if true { -0.0 } else { 1.0 };
+ if x == 0.0 { 0 } else { 1 }
+}
+
fn main() {
// CHECK-LABEL: fn main(
too_complex(Ok(0));
@@ -520,6 +530,7 @@ fn main() {
disappearing_bb(7);
aggregate(7);
assume(7, false);
+ floats();
}
// EMIT_MIR jump_threading.too_complex.JumpThreading.diff
@@ -534,3 +545,4 @@ fn main() {
// EMIT_MIR jump_threading.disappearing_bb.JumpThreading.diff
// EMIT_MIR jump_threading.aggregate.JumpThreading.diff
// EMIT_MIR jump_threading.assume.JumpThreading.diff
+// EMIT_MIR jump_threading.floats.JumpThreading.diff
diff --git a/tests/ui/coherence/re-rebalance-coherence.rs b/tests/ui/coherence/re-rebalance-coherence.rs
index 5383a634617f4..9c176d5b1b12b 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 for BatchInsert<'a, T, Tab> {}
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 4bf2fa761eae8..c23187598bceb 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 {
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 50a6102c605a9..5d2198f50ad92 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);
+pub struct Block(#[allow(dead_code)] C);
pub fn test()
where
diff --git a/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs b/tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs
index 35c41ae461520..419d605d0c875 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(MaybeUninit<[u64; N]>);
diff --git a/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.rs b/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.rs
index 885dacc727af6..6ab1fb7b039bd 100644
--- a/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.rs
+++ b/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.rs
@@ -1,9 +1,9 @@
#![forbid(dead_code)]
#[derive(Debug)]
-pub struct Whatever { //~ ERROR struct `Whatever` is never constructed
+pub struct Whatever {
pub field0: (),
- field1: (),
+ field1: (), //~ ERROR fields `field1`, `field2`, `field3`, and `field4` are never read
field2: (),
field3: (),
field4: (),
diff --git a/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr b/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
index e10d28ad03a4e..e9b757b6bae72 100644
--- a/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
+++ b/tests/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
@@ -1,9 +1,19 @@
-error: struct `Whatever` is never constructed
- --> $DIR/clone-debug-dead-code-in-the-same-struct.rs:4:12
+error: fields `field1`, `field2`, `field3`, and `field4` are never read
+ --> $DIR/clone-debug-dead-code-in-the-same-struct.rs:6:5
|
LL | pub struct Whatever {
- | ^^^^^^^^
+ | -------- fields in this struct
+LL | pub field0: (),
+LL | field1: (),
+ | ^^^^^^
+LL | field2: (),
+ | ^^^^^^
+LL | field3: (),
+ | ^^^^^^
+LL | field4: (),
+ | ^^^^^^
|
+ = note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
note: the lint level is defined here
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:1:11
|
diff --git a/tests/ui/issues/issue-5708.rs b/tests/ui/issues/issue-5708.rs
index 89ea9fbdcd8fe..ce9ef78ffcd9c 100644
--- a/tests/ui/issues/issue-5708.rs
+++ b/tests/ui/issues/issue-5708.rs
@@ -44,7 +44,6 @@ pub trait MyTrait {
fn dummy(&self, t: T) -> T { panic!() }
}
-#[allow(dead_code)]
pub struct MyContainer<'a, T:'a> {
foos: Vec<&'a (dyn MyTrait+'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 8cd1524045b15..0000000000000
--- 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>,
-}
-
-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/lint-dead-code-1.rs b/tests/ui/lint/dead-code/lint-dead-code-1.rs
index 3386dfa47470f..ddcafedf7bc5f 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 b0163df8855cd..eb728b5b93055 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/unused-assoc-const.rs b/tests/ui/lint/dead-code/unused-assoc-const.rs
deleted file mode 100644
index 36e8315ad3605..0000000000000
--- 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 78296d706638b..0000000000000
--- 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-pub-struct.rs b/tests/ui/lint/dead-code/unused-pub-struct.rs
deleted file mode 100644
index aaf4dd612de4d..0000000000000
--- 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);
-
-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 3667ddb97bd3e..0000000000000
--- 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/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 e9c89807fa566..a851300a9828e 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 3bd0f51ec2cbe..10f435859f15a 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 77eafa6bea336..ddbf237e8662b 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/pub/pub-ident-struct-4.fixed b/tests/ui/pub/pub-ident-struct-4.fixed
index a62ece43eced3..5fedbb7243749 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 0d56a31beaf1c..5c721c25a7815 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 ec1367832113b..5fbb02c8673ce 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:4
+ --> $DIR/pub-ident-struct-4.rs:3:4
|
-LL | pub T(String);
+LL | pub T(#[allow(dead_code)] String);
| ^
|
help: add `struct` here to parse `T` as a public 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 67852a6f5de0d..54beed9b3ac2b 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 16439a7fedd3e..19672e41c9a30 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 1074dbcd6e6b5..97bc7d8414e7f 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 cf800c6e47d87..4dc362f947875 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);
diff --git a/tests/ui/suggestions/derive-clone-for-eq.rs b/tests/ui/suggestions/derive-clone-for-eq.rs
index 84736426bac0d..b3635000f1658 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);
diff --git a/tests/ui/suggestions/derive-clone-for-eq.stderr b/tests/ui/suggestions/derive-clone-for-eq.stderr
index 54670fbffcfb9..6fae6e1316df0 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: PartialEq`
|
note: required for `Struct` to implement `PartialEq`
- --> $DIR/derive-clone-for-eq.rs:8:19
+ --> $DIR/derive-clone-for-eq.rs:7:19
|
LL | impl PartialEq for Struct
| ----- ^^^^^^^^^^^^ ^^^^^^^^^
diff --git a/tests/ui/suggestions/option-content-move.fixed b/tests/ui/suggestions/option-content-move.fixed
index ef07d55871e7e..4a5a9483c20c8 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)>,
}
@@ -18,7 +17,6 @@ impl LipogramCorpora {
}
}
-#[allow(dead_code)]
pub struct LipogramCorpora2 {
selections: Vec<(char, Result)>,
}
diff --git a/tests/ui/suggestions/option-content-move.rs b/tests/ui/suggestions/option-content-move.rs
index 5be6358fd6a57..90d05c7439970 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)>,
}
@@ -18,7 +17,6 @@ impl LipogramCorpora {
}
}
-#[allow(dead_code)]
pub struct LipogramCorpora2 {
selections: Vec<(char, Result)>,
}
diff --git a/tests/ui/suggestions/option-content-move.stderr b/tests/ui/suggestions/option-content-move.stderr
index b4ec5b180d210..a382a04344aeb 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 0ae562c0d30a0..462b0bc5bb77f 100644
--- a/tests/ui/traits/object/generics.rs
+++ b/tests/ui/traits/object/generics.rs
@@ -7,7 +7,6 @@ pub trait Trait2 {
fn doit(&self) -> A;
}
-#[allow(dead_code)]
pub struct Impl {
m1: marker::PhantomData<(A1,A2,A3)>,
/*