Open
Description
In the following snippet, CONST
gets a dead_code
warning. However, CONST
is most definitely used and the trait is also pub, so this warning seems incorrect.
Removing CONST
causes the crate to no longer compile, and removing the impl would be a breaking change.
Adding any function (i.e. fn method();
) to the trait and implementing it removes the warning as well. However, for marker traits this is not an option. It also clearly demonstrates that CONST
is considered to be used despite being unaffected by fn method()
.
Rust version: rustc 1.80.0 (0514789 2024-07-21)
This code compiles without warnings on 1.79.0 (rustc 1.79.0 (129f3b9 2024-06-10))
pub struct Value<const NUMBER: u8> {}
pub trait Trait {}
const CONST: u8 = 11;
impl Trait for Value<CONST> {}
Warning:
warning: constant `CONST` is never used
--> lib.rs:5:7
|
5 | const CONST: u8 = 11;
| ^^^^^
|
= note: `#[warn(dead_code)]` on by default
Adding method()
removes the warning:
pub struct Value<const NUMBER: u8> {}
pub trait Trait {
fn method();
}
const CONST: u8 = 11;
impl Trait for Value<CONST> {
fn method() {}
}