Skip to content

Wrong unused warning for type alias #59333

Open
@therustmonk

Description

@therustmonk

This code:

struct Runner;

type RuntimeImpl = Runner;

trait Runtime {
    fn run(&mut self);
}

impl Runtime for &mut RuntimeImpl {
    fn run(&mut self) { }    
}

fn main() {
    let mut runner = Runner;
    (&mut runner).run();
}

takes the warning:

   Compiling playground v0.0.1 (/playground)
warning: type alias is never used: `RuntimeImpl`
 --> src/main.rs:3:1
  |
3 | type RuntimeImpl = Runner;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

But removing this alias introduces a compilation error 🤔

The link to the nightly playground example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=22a044608f4d67680bcf1cc7fd23a381

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.T-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