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

dead_code warning when private trait is only used as type bound in another trait #128839

Open
eduardosm opened this issue Aug 8, 2024 · 1 comment · May be fixed by #128637
Open

dead_code warning when private trait is only used as type bound in another trait #128839

eduardosm opened this issue Aug 8, 2024 · 1 comment · May be fixed by #128637
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eduardosm
Copy link
Contributor

Code

trait UInt: Copy + From<u8> {}

impl UInt for u16 {}

trait Int: Copy {
    type Unsigned: UInt;

    fn as_unsigned(self) -> Self::Unsigned;
}

impl Int for i16 {
    type Unsigned = u16;

    fn as_unsigned(self) -> u16 {
        self as _
    }
}

fn priv_func<T: Int>(x: u8, y: T) -> (T::Unsigned, T::Unsigned) {
    (T::Unsigned::from(x), y.as_unsigned())
}

pub fn pub_func(x: u8, y: i16) -> (u16, u16) {
    priv_func(x, y)
}

Current output

warning: trait `UInt` is never used
 --> src/lib.rs:1:7
  |
1 | trait UInt: Copy + From<u8> {}
  |       ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

Desired output

<empty>

Rationale and extra context

The false positive happens when a private trait is only used as type bound in another trait.

Other cases

No response

Rust Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

Anything else?

No response

@eduardosm eduardosm added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 8, 2024
@compiler-errors
Copy link
Member

This uncovers a regression from 1.78 in #118257, since we backported recent changes to dead code analysis. cc @mu001999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants