Skip to content

Spurious dead_code warning when type is only used in path #23808

Description

@apasel422

foo.rs:

trait Bar {
    fn bar() {}
}

enum Foo {}

impl Bar for Foo {}

fn main() {
    Foo::bar();
}

Warning:

> rustc --version
rustc 1.0.0-nightly (199bdcfef 2015-03-26) (built 2015-03-27)
> rustc foo.rs 
foo.rs:5:1: 5:12 warning: enum is never used: `Foo`, #[warn(dead_code)] on by default
foo.rs:5 enum Foo {}
         ^~~~~~~~~~~

Activity

  1. TimNN commented on Aug 5, 2015

    @TimNN
    Contributor

    By the way, the warning goes away if you explicitly specify the trait who's static method you are calling, like so:

    <Foo as Bar>::bar();
  2. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-dead_codeLint: dead_codeT-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