Skip to content

Unused warning for type alias doesn't take into account inherent impls. #47131

Closed
@cristicbz

Description

@cristicbz

The following code (playground):

pub struct GenericFoo<T>(T);

type Foo = GenericFoo<u32>;

impl Foo {
    fn bar(self) -> u8 {
        0
    }
}

fn main() {    
    println!("{}", GenericFoo(0).bar());
}

results in the warning:

warning: type alias is never used: `Foo`
 --> src/main.rs:3:1
  |
3 | type Foo = GenericFoo<u32>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

This is incorrect, since the Foo impl uses it (and it can be unwieldy to write it out otherwise).

Metadata

Metadata

Assignees

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