Skip to content

nightly: false positive 'dead_code' warning when using trait for the supertrait bounds #121040

Closed
@pantos9000

Description

@pantos9000

Code

pub struct Foo;

#[cfg(test)]
mod tests_common {
    /// A marker trait that can be used to assert a type is `Send`.
    pub trait AssertSend: Send {}
}

#[cfg(test)]
mod tests {
    use super::*;

    use crate::tests_common::AssertSend;

    impl AssertSend for Foo {}
}

Current output

warning: trait `AssertSend` is never used
 --> src/lib.rs:5:15
  |
5 |     pub trait AssertSend: Send {}
  |               ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `test_trait_reproducer` (lib test) generated 1 warning

Desired output

no warning (like in stable)

Rationale and extra context

For the given code, the rust compiler emits a dead_code warning in nightly, but not in stable.

Usually the trait was supposed to be used for multiple modules to ensure Send on certain types. For the sake of simplicity, I put it in the same file. But the issue is also visible across different files.

Other cases

No response

Rust Version

stable version:
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

nightly version:
rustc 1.78.0-nightly (b381d3ab2 2024-02-12)
binary: rustc
commit-hash: b381d3ab27f788f990551100c4425bb782d26d76
commit-date: 2024-02-12
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions