-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Spurious dead code warning when item is only used in impls #18290
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
Comments
Updated code: const TLC: usize = 4;
trait Tr { fn doit(&self); }
impl Tr for [usize; TLC] {
fn doit(&self) { println!("called 4"); }
}
fn main() {
let s = [0,1,2,3];
s.doit(); // which .doit is called depends on architecture
} Still gives the warning. |
Not particularly related to constants: impls just aren't counted as uses for types they refer to. struct X;
struct Y;
struct Z;
trait Foo<T> {
type Ty;
fn foo() -> Self::Ty;
}
impl Foo<Y> for X {
type Ty = Z;
fn foo() -> Self::Ty { unimplemented!() }
}
fn main() {
X::foo();
} |
I hit another case with this just in the last few days using nightly via rustup; impls don't appear to be involved? const ACT_STRINGS: &'static [&'static str] = &["set name=foo value=foo"];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse() {
for astr in ACT_STRINGS.iter() {
println!("{}", astr);
}
}
}
Changing the I suspect my case is issue #33166 ? |
Triage:
|
|
It seems that if a
const
is only used inimpl
s, but not in actual code, then rustc emits a "constant item is never used" warning, as in the following code:Which prints (when compiled and then run):
The text was updated successfully, but these errors were encountered: