rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.68k stars 12.49k forks source link

type alias `Plus2` is never used #127911

Open IceTDrinker opened 1 month ago

IceTDrinker commented 1 month ago

Summary

Some type is flagged by Clippy as never used, though it is used in an internal trait implementation

Lint Name

dead_code

Reproducer

I tried this code:

clone https://github.com/zama-ai/concrete-fft/commit/aeb75d4b7c5cc6b3031bf5b9f4730961f3132fe5

run pre commit checks, runs a clippy check: make pcc

faulty clippy invokation:

RUSTFLAGS="-C target-cpu=native" cargo "+nightly-2024-07-18" clippy --all-targets \
        --features=serde -- --no-deps -D warnings

I saw this happen:

error: type alias `Plus2` is never used
  --> src/nat.rs:26:10
   |
26 | pub type Plus2<N> = Successor<Plus1<N>>;
   |          ^^^^^
   |
   = note: `-D dead-code` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(dead_code)]`

error: type alias `Plus3` is never used
  --> src/nat.rs:27:10
   |
27 | pub type Plus3<N> = Successor<Plus2<N>>;
   |          ^^^^^

error: type alias `Plus4` is never used
  --> src/nat.rs:28:10
   |
28 | pub type Plus4<N> = Successor<Plus3<N>>;
   |          ^^^^^

error: could not compile `concrete-fft` (lib) due to 3 previous errors

I expected to see this happen:

No warning/error for these types as they are used in e.g. https://github.com/zama-ai/concrete-fft/blob/aeb75d4b7c5cc6b3031bf5b9f4730961f3132fe5/src/dit16.rs#L823

Version

rustc 1.81.0-nightly (fcc325f1b 2024-07-17)
binary: rustc
commit-hash: fcc325f1bc477975e2ce5ba534fe4c77ff8a8536
commit-date: 2024-07-17
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Additional Labels

No response

Alexendoo commented 1 month ago

dead_code comes from rustc, does cargo +nightly-2024-07-18 check --all-targets --features serde exhibit the same behaviour?

IceTDrinker commented 1 month ago

checking

IceTDrinker commented 1 month ago

warnings are popping up as well, so wrong repo I guess ? is there a way to transfer this issue to rustc ?

tgross35 commented 1 month ago

This will need a smaller reproduction. Any chance you could try extracting the relevant code out?

IceTDrinker commented 1 month ago

I don't really have time currently I'm afraid :/ otherwise I could offer an automated bisect on that

tgross35 commented 1 month ago

No worries, somebody will chase it down at some point :)

mu001999 commented 1 month ago

Regression in https://github.com/rust-lang-ci/rust/commit/4cfe57a6518913330a52c45021aa3ab26ac53558 The PR introducing the regression in this rollup is #122382: Detect unused structs which implement private traits


I will have a look

lqd commented 1 month ago

There are also similar older versions of this issue, like the following (playground). That's been warning since 1.57:

use std::mem;

#[repr(transparent)]
pub struct X<T: ?Sized> {
    pub inner: T,
}

pub struct Y {}

impl Drop for Y {
    fn drop(&mut self) {
        type A = Vec<u8>;
        const _: () = assert!(mem::size_of::<X<A>>() == mem::size_of::<A>());
    }
}

Note that this is not a reduction of the OP and not necessarily a duplicate, but was encountered in real world code.

mu001999 commented 1 month ago

@rustbot claim

mu001999 commented 1 month ago

Reduced (play):

struct T<X>(X);

type A<X> = T<X>;

trait Tr {
    fn foo();
}

impl<X> Tr for T<A<X>> {
    fn foo() {}
}

fn main() {
   T::<T<()>>::foo();
}