Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert recent changes to dead code analysis #128404

Merged
merged 9 commits into from
Aug 3, 2024
Merged
214 changes: 71 additions & 143 deletions compiler/rustc_passes/src/dead.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions library/core/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
10 changes: 5 additions & 5 deletions tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
24 changes: 12 additions & 12 deletions tests/codegen-units/item-collection/overloaded-operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion tests/ui/coherence/re-rebalance-coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/cross_crate_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/defaults/repr-c-issue-82792.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

//@ run-pass

#[allow(dead_code)]
#[repr(C)]
pub struct Loaf<T: Sized, const N: usize = 1> {
head: [T; N],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/issues/issue-86535-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/const-generics/issues/issue-86535.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::mem::MaybeUninit;

#[allow(dead_code)]
#[repr(transparent)]
pub struct MaybeUninitWrapper<const N: usize>(MaybeUninit<[u64; N]>);

Expand Down
4 changes: 0 additions & 4 deletions tests/ui/generic-associated-types/missing-bounds.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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> {
Expand All @@ -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> {
Expand All @@ -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> {
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/generic-associated-types/missing-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::ops::Add;

#[allow(dead_code)]
struct A<B>(B);

impl<B> Add for A<B> where B: Add {
Expand All @@ -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> {
Expand All @@ -24,7 +22,6 @@ impl<B: Add> Add for C<B> {
}
}

#[allow(dead_code)]
struct D<B>(B);

impl<B> Add for D<B> {
Expand All @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/generic-associated-types/missing-bounds.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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);
| ^
Expand All @@ -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
Expand All @@ -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);
| ^
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
| ^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/extra-impl-in-trait-impl.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
Original file line number Diff line number Diff line change
@@ -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 {
| ^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/issues/issue-5708.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)> ,
}
Expand Down
Loading
Loading