Skip to content

Commit 0c986b1

Browse files
authored
Rollup merge of rust-lang#128404 - compiler-errors:revert-dead-code-changes, r=pnkfelix
Revert recent changes to dead code analysis This is a revert to recent changes to dead code analysis, namely: * efdf219 Rollup merge of rust-lang#128104 - mu001999-contrib:fix/128053, r=petrochenkov * a70dc29 Rollup merge of rust-lang#127017 - mu001999-contrib:dead/enhance, r=pnkfelix * 31fe962 Rollup merge of rust-lang#127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix * 2724aea Rollup merge of rust-lang#126618 - mu001999-contrib:dead/enhance, r=pnkfelix * 977c5fd Rollup merge of rust-lang#126315 - mu001999-contrib:fix/126289, r=petrochenkov * 13314df Rollup merge of rust-lang#125572 - mu001999-contrib:dead/enhance, r=pnkfelix There is an additional change stacked on top, which suppresses false-negatives that were masked by this work. I believe the functions that are touched in that code are legitimately unused functions and the types are not reachable since this `AnonPipe` type is not publically reachable -- please correct me if I'm wrong cc `@NobodyXu` who added these in #rust-lang#127153. Some of these reverts (rust-lang#126315 and rust-lang#126618) are only included because it makes the revert apply cleanly, and I think these changes were only done to fix follow-ups from the other PRs? I apologize for the size of the PR and the churn that it has on the codebase (and for reverting `@mu001999's` work here), but I'm putting this PR up because I am concerned that we're making ad-hoc changes to fix bugs that are fallout of these PRs, and I'd like to see these changes reimplemented in a way that's more separable from the existing dead code pass. I am happy to review any code to reapply these changes in a more separable way. cc `@mu001999` r? `@pnkfelix` Fixes rust-lang#128272 Fixes rust-lang#126169
2 parents 4940bb2 + 72844ee commit 0c986b1

File tree

64 files changed

+172
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+172
-662
lines changed

compiler/rustc_passes/src/dead.rs

+71-143
Large diffs are not rendered by default.

library/core/src/default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ use crate::ascii::Char as AsciiChar;
103103
/// ```
104104
#[cfg_attr(not(test), rustc_diagnostic_item = "Default")]
105105
#[stable(feature = "rust1", since = "1.0.0")]
106+
#[cfg_attr(not(bootstrap), rustc_trivial_field_reads)]
106107
pub trait Default: Sized {
107108
/// Returns the "default value" for a type.
108109
///

library/std/src/sys/pal/unix/pipe.rs

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
4747
}
4848

4949
impl AnonPipe {
50+
#[allow(dead_code)]
51+
// FIXME: This function seems legitimately unused.
5052
pub fn try_clone(&self) -> io::Result<Self> {
5153
self.0.duplicate().map(Self)
5254
}
@@ -85,6 +87,8 @@ impl AnonPipe {
8587
self.0.is_write_vectored()
8688
}
8789

90+
#[allow(dead_code)]
91+
// FIXME: This function seems legitimately unused.
8892
pub fn as_file_desc(&self) -> &FileDesc {
8993
&self.0
9094
}

src/tools/rust-analyzer/crates/salsa/salsa-macros/src/database_storage.rs

+8
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,11 @@ impl Parse for QueryGroup {
241241
Ok(QueryGroup { group_path })
242242
}
243243
}
244+
245+
struct Nothing;
246+
247+
impl Parse for Nothing {
248+
fn parse(_input: ParseStream<'_>) -> syn::Result<Self> {
249+
Ok(Nothing)
250+
}
251+
}

tests/codegen-units/item-collection/generic-impl.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ impl<T> Struct<T> {
2222
}
2323
}
2424

25-
pub struct _LifeTimeOnly<'a> {
25+
pub struct LifeTimeOnly<'a> {
2626
_a: &'a u32,
2727
}
2828

29-
impl<'a> _LifeTimeOnly<'a> {
30-
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::foo
29+
impl<'a> LifeTimeOnly<'a> {
30+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
3131
pub fn foo(&self) {}
32-
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::bar
32+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
3333
pub fn bar(&'a self) {}
34-
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::baz
34+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::baz
3535
pub fn baz<'b>(&'b self) {}
3636

3737
pub fn non_instantiated<T>(&self) {}

tests/codegen-units/item-collection/overloaded-operators.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@
55

66
use std::ops::{Add, Deref, Index, IndexMut};
77

8-
pub struct _Indexable {
8+
pub struct Indexable {
99
data: [u8; 3],
1010
}
1111

12-
impl Index<usize> for _Indexable {
12+
impl Index<usize> for Indexable {
1313
type Output = u8;
1414

15-
//~ MONO_ITEM fn <_Indexable as std::ops::Index<usize>>::index
15+
//~ MONO_ITEM fn <Indexable as std::ops::Index<usize>>::index
1616
fn index(&self, index: usize) -> &Self::Output {
1717
if index >= 3 { &self.data[0] } else { &self.data[index] }
1818
}
1919
}
2020

21-
impl IndexMut<usize> for _Indexable {
22-
//~ MONO_ITEM fn <_Indexable as std::ops::IndexMut<usize>>::index_mut
21+
impl IndexMut<usize> for Indexable {
22+
//~ MONO_ITEM fn <Indexable as std::ops::IndexMut<usize>>::index_mut
2323
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
2424
if index >= 3 { &mut self.data[0] } else { &mut self.data[index] }
2525
}
2626
}
2727

28-
//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::eq
29-
//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::ne
28+
//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::eq
29+
//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::ne
3030
#[derive(PartialEq)]
31-
pub struct _Equatable(u32);
31+
pub struct Equatable(u32);
3232

33-
impl Add<u32> for _Equatable {
33+
impl Add<u32> for Equatable {
3434
type Output = u32;
3535

36-
//~ MONO_ITEM fn <_Equatable as std::ops::Add<u32>>::add
36+
//~ MONO_ITEM fn <Equatable as std::ops::Add<u32>>::add
3737
fn add(self, rhs: u32) -> u32 {
3838
self.0 + rhs
3939
}
4040
}
4141

42-
impl Deref for _Equatable {
42+
impl Deref for Equatable {
4343
type Target = u32;
4444

45-
//~ MONO_ITEM fn <_Equatable as std::ops::Deref>::deref
45+
//~ MONO_ITEM fn <Equatable as std::ops::Deref>::deref
4646
fn deref(&self) -> &Self::Target {
4747
&self.0
4848
}

tests/ui-fulldeps/deriving-global.rs

-3
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@ mod submod {
1717
// if any of these are implemented without global calls for any
1818
// function calls, then being in a submodule will (correctly)
1919
// cause errors about unrecognised module `std` (or `extra`)
20-
#[allow(dead_code)]
2120
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)]
2221
enum A {
2322
A1(usize),
2423
A2(isize),
2524
}
2625

27-
#[allow(dead_code)]
2826
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)]
2927
struct B {
3028
x: usize,
3129
y: isize,
3230
}
3331

34-
#[allow(dead_code)]
3532
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)]
3633
struct C(usize, isize);
3734
}

tests/ui-fulldeps/deriving-hygiene.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub const s: u8 = 1;
2020
pub const state: u8 = 1;
2121
pub const cmp: u8 = 1;
2222

23-
#[allow(dead_code)]
2423
#[derive(Ord, Eq, PartialOrd, PartialEq, Debug, Decodable, Encodable, Hash)]
2524
struct Foo {}
2625

tests/ui/coherence/re-rebalance-coherence.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
extern crate re_rebalance_coherence_lib as lib;
55
use lib::*;
66

7-
#[allow(dead_code)]
87
struct Oracle;
98
impl Backend for Oracle {}
109
impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}

tests/ui/const-generics/cross_crate_complex.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ async fn foo() {
1111
async_in_foo(async_out_foo::<4>().await).await;
1212
}
1313

14-
#[allow(dead_code)]
1514
struct Faz<const N: usize>;
1615

1716
impl<const N: usize> Foo<N> for Faz<N> {}

tests/ui/const-generics/defaults/repr-c-issue-82792.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
//@ run-pass
44

5-
#[allow(dead_code)]
65
#[repr(C)]
76
pub struct Loaf<T: Sized, const N: usize = 1> {
87
head: [T; N],

tests/ui/const-generics/generic_const_exprs/associated-consts.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ impl BlockCipher for BarCipher {
1616
const BLOCK_SIZE: usize = 32;
1717
}
1818

19-
#[allow(dead_code)]
20-
pub struct Block<C>(C);
19+
pub struct Block<C>(#[allow(dead_code)] C);
2120

2221
pub fn test<C: BlockCipher, const M: usize>()
2322
where

tests/ui/const-generics/issues/issue-86535-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub trait Foo {
99
[(); Self::ASSOC_C]:;
1010
}
1111

12-
#[allow(dead_code)]
1312
struct Bar<const N: &'static ()>;
1413
impl<const N: &'static ()> Foo for Bar<N> {
1514
const ASSOC_C: usize = 3;

tests/ui/const-generics/issues/issue-86535.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
33
#![allow(incomplete_features, unused_variables)]
44

5-
#[allow(dead_code)]
65
struct F<const S: &'static str>;
76
impl<const S: &'static str> X for F<{ S }> {
87
const W: usize = 3;

tests/ui/const-generics/transparent-maybeunit-array-wrapper.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use std::mem::MaybeUninit;
88

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

tests/ui/generic-associated-types/missing-bounds.fixed

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::ops::Add;
44

5-
#[allow(dead_code)]
65
struct A<B>(B);
76

87
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> {
1312
}
1413
}
1514

16-
#[allow(dead_code)]
1715
struct C<B>(B);
1816

1917
impl<B: Add<Output = B>> Add for C<B> {
@@ -24,7 +22,6 @@ impl<B: Add<Output = B>> Add for C<B> {
2422
}
2523
}
2624

27-
#[allow(dead_code)]
2825
struct D<B>(B);
2926

3027
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> {
3532
}
3633
}
3734

38-
#[allow(dead_code)]
3935
struct E<B>(B);
4036

4137
impl<B: Add<Output = B>> Add for E<B> where B: Add<Output = B> {

tests/ui/generic-associated-types/missing-bounds.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::ops::Add;
44

5-
#[allow(dead_code)]
65
struct A<B>(B);
76

87
impl<B> Add for A<B> where B: Add {
@@ -13,7 +12,6 @@ impl<B> Add for A<B> where B: Add {
1312
}
1413
}
1514

16-
#[allow(dead_code)]
1715
struct C<B>(B);
1816

1917
impl<B: Add> Add for C<B> {
@@ -24,7 +22,6 @@ impl<B: Add> Add for C<B> {
2422
}
2523
}
2624

27-
#[allow(dead_code)]
2825
struct D<B>(B);
2926

3027
impl<B> Add for D<B> {
@@ -35,7 +32,6 @@ impl<B> Add for D<B> {
3532
}
3633
}
3734

38-
#[allow(dead_code)]
3935
struct E<B>(B);
4036

4137
impl<B: Add> Add for E<B> where <B as Add>::Output = B {

tests/ui/generic-associated-types/missing-bounds.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: equality constraints are not yet supported in `where` clauses
2-
--> $DIR/missing-bounds.rs:41:33
2+
--> $DIR/missing-bounds.rs:37:33
33
|
44
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
55
| ^^^^^^^^^^^^^^^^^^^^^^ not supported
@@ -11,7 +11,7 @@ LL | impl<B: Add> Add for E<B> where B: Add<Output = B> {
1111
| ~~~~~~~~~~~~~~~~~~
1212

1313
error[E0308]: mismatched types
14-
--> $DIR/missing-bounds.rs:12:11
14+
--> $DIR/missing-bounds.rs:11:11
1515
|
1616
LL | impl<B> Add for A<B> where B: Add {
1717
| - expected this type parameter
@@ -24,14 +24,14 @@ LL | A(self.0 + rhs.0)
2424
= note: expected type parameter `B`
2525
found associated type `<B as Add>::Output`
2626
help: the type constructed contains `<B as Add>::Output` due to the type of the argument passed
27-
--> $DIR/missing-bounds.rs:12:9
27+
--> $DIR/missing-bounds.rs:11:9
2828
|
2929
LL | A(self.0 + rhs.0)
3030
| ^^--------------^
3131
| |
3232
| this argument influences the type of `A`
3333
note: tuple struct defined here
34-
--> $DIR/missing-bounds.rs:6:8
34+
--> $DIR/missing-bounds.rs:5:8
3535
|
3636
LL | struct A<B>(B);
3737
| ^
@@ -41,7 +41,7 @@ LL | impl<B> Add for A<B> where B: Add<Output = B> {
4141
| ++++++++++++
4242

4343
error[E0308]: mismatched types
44-
--> $DIR/missing-bounds.rs:23:14
44+
--> $DIR/missing-bounds.rs:21:14
4545
|
4646
LL | impl<B: Add> Add for C<B> {
4747
| - expected this type parameter
@@ -54,7 +54,7 @@ LL | Self(self.0 + rhs.0)
5454
= note: expected type parameter `B`
5555
found associated type `<B as Add>::Output`
5656
note: tuple struct defined here
57-
--> $DIR/missing-bounds.rs:17:8
57+
--> $DIR/missing-bounds.rs:15:8
5858
|
5959
LL | struct C<B>(B);
6060
| ^
@@ -64,7 +64,7 @@ LL | impl<B: Add<Output = B>> Add for C<B> {
6464
| ++++++++++++
6565

6666
error[E0369]: cannot add `B` to `B`
67-
--> $DIR/missing-bounds.rs:34:21
67+
--> $DIR/missing-bounds.rs:31:21
6868
|
6969
LL | Self(self.0 + rhs.0)
7070
| ------ ^ ----- B
@@ -77,7 +77,7 @@ LL | impl<B: std::ops::Add<Output = B>> Add for D<B> {
7777
| +++++++++++++++++++++++++++
7878

7979
error[E0308]: mismatched types
80-
--> $DIR/missing-bounds.rs:46:14
80+
--> $DIR/missing-bounds.rs:42:14
8181
|
8282
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
8383
| - expected this type parameter
@@ -90,7 +90,7 @@ LL | Self(self.0 + rhs.0)
9090
= note: expected type parameter `B`
9191
found associated type `<B as Add>::Output`
9292
note: tuple struct defined here
93-
--> $DIR/missing-bounds.rs:39:8
93+
--> $DIR/missing-bounds.rs:35:8
9494
|
9595
LL | struct E<B>(B);
9696
| ^

tests/ui/impl-trait/extra-impl-in-trait-impl.fixed

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ run-rustfix
22

3-
#[allow(dead_code)]
43
struct S<T>(T);
5-
#[allow(dead_code)]
64
struct S2;
75

86
impl<T: Default> Default for S<T> {

tests/ui/impl-trait/extra-impl-in-trait-impl.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ run-rustfix
22

3-
#[allow(dead_code)]
43
struct S<T>(T);
5-
#[allow(dead_code)]
64
struct S2;
75

86
impl<T: Default> impl Default for S<T> {

tests/ui/impl-trait/extra-impl-in-trait-impl.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: unexpected `impl` keyword
2-
--> $DIR/extra-impl-in-trait-impl.rs:8:18
2+
--> $DIR/extra-impl-in-trait-impl.rs:6:18
33
|
44
LL | impl<T: Default> impl Default for S<T> {
55
| ^^^^^ help: remove the extra `impl`
66
|
77
note: this is parsed as an `impl Trait` type, but a trait is expected at this position
8-
--> $DIR/extra-impl-in-trait-impl.rs:8:18
8+
--> $DIR/extra-impl-in-trait-impl.rs:6:18
99
|
1010
LL | impl<T: Default> impl Default for S<T> {
1111
| ^^^^^^^^^^^^
1212

1313
error: unexpected `impl` keyword
14-
--> $DIR/extra-impl-in-trait-impl.rs:14:6
14+
--> $DIR/extra-impl-in-trait-impl.rs:12:6
1515
|
1616
LL | impl impl Default for S2 {
1717
| ^^^^^ help: remove the extra `impl`
1818
|
1919
note: this is parsed as an `impl Trait` type, but a trait is expected at this position
20-
--> $DIR/extra-impl-in-trait-impl.rs:14:6
20+
--> $DIR/extra-impl-in-trait-impl.rs:12:6
2121
|
2222
LL | impl impl Default for S2 {
2323
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)