Skip to content

type alias Plus2 is never used #127911

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

Closed
IceTDrinker opened this issue Jul 18, 2024 · 10 comments · Fixed by #141407
Closed

type alias Plus2 is never used #127911

IceTDrinker opened this issue Jul 18, 2024 · 10 comments · Fixed by #141407
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example L-dead_code Lint: dead_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@IceTDrinker
Copy link

IceTDrinker commented Jul 18, 2024

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 zama-ai/concrete-fft@aeb75d4

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

@IceTDrinker IceTDrinker added the C-bug Category: This is a bug. label Jul 18, 2024
@Alexendoo
Copy link
Member

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

@IceTDrinker
Copy link
Author

checking

@IceTDrinker
Copy link
Author

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

@Alexendoo Alexendoo transferred this issue from rust-lang/rust-clippy Jul 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 18, 2024
@tgross35 tgross35 added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example L-dead_code Lint: dead_code and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 18, 2024
@tgross35
Copy link
Contributor

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

@IceTDrinker
Copy link
Author

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

@tgross35
Copy link
Contributor

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

@mu001999
Copy link
Contributor

mu001999 commented Jul 18, 2024

Regression in rust-lang-ci@4cfe57a
The PR introducing the regression in this rollup is #122382: Detect unused structs which implement private traits


I will have a look

@lqd
Copy link
Member

lqd commented Jul 18, 2024

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
Copy link
Contributor

@rustbot claim

@mu001999
Copy link
Contributor

mu001999 commented Jul 20, 2024

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();
}

@bors bors closed this as completed in 896be66 May 30, 2025
rust-timer added a commit that referenced this issue May 30, 2025
Rollup merge of #141407 - mu001999-contrib:dead-code/refactor, r=petrochenkov

Refactor the two-phase check for impls and impl items

Refactor the two-phase dead code check to make the logic clearer and simpler:
1. adding assoc fn and impl into `unsolved_items` directly during the initial construction of the worklist
2. converge the logic of checking whether assoc fn and impl are used to `item_should_be_checked`, and the item is considered used only when its corresponding trait and Self adt are used

This PR only refactors as much as possible to avoid affecting the original functions. However, due to the adjustment of the order of checks, the test results are slightly different, but overall, there is no regression problem

Fixes #127911
Fixes #128839

Extracted from #128637.
r? petrochenkov

try-job: dist-aarch64-linux
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 31, 2025
…ochenkov

Refactor the two-phase check for impls and impl items

Refactor the two-phase dead code check to make the logic clearer and simpler:
1. adding assoc fn and impl into `unsolved_items` directly during the initial construction of the worklist
2. converge the logic of checking whether assoc fn and impl are used to `item_should_be_checked`, and the item is considered used only when its corresponding trait and Self adt are used

This PR only refactors as much as possible to avoid affecting the original functions. However, due to the adjustment of the order of checks, the test results are slightly different, but overall, there is no regression problem

Fixes rust-lang/rust#127911
Fixes rust-lang/rust#128839

Extracted from rust-lang/rust#128637.
r? petrochenkov

try-job: dist-aarch64-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example L-dead_code Lint: dead_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants