Skip to content

Spurious dead code warning when item is only used in impls #18290

Closed
@arielb1

Description

@arielb1

It seems that if a const is only used in impls, but not in actual code, then rustc emits a "constant item is never used" warning, as in the following code:

const TLC: uint = 4;
trait Tr { fn doit(&self); }
impl Tr for [uint, ..TLC] {
    fn doit(&self) { println!("called 4"); }
}

fn main() {
    let s = [0,1,2,3u];
    s.doit(); // which .doit is called depends on architecture
}

Which prints (when compiled and then run):

<anon>:1:1: 1:21 warning: constant item is never used: `TLC`, #[warn(dead_code)] on by default
<anon>:1 const TLC: uint = 4;
         ^~~~~~~~~~~~~~~~~~~~
called 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions