Skip to content
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

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

Closed
cristicbz opened this issue Jan 2, 2018 · 10 comments
Closed
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cristicbz
Copy link
Contributor

cristicbz commented Jan 2, 2018

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

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 6, 2018
@jsgf
Copy link
Contributor

jsgf commented May 1, 2018

This looks like a similar case: type aliases used for trait bounds on inherent impl are not considered used: playground

#![deny(warnings)]

type FooBar<F> = <F as Foo>::Bar;

trait Foo {
    type Bar;
}

struct Blop<F>(F);

impl<F: Foo> Blop<F>
where
    FooBar<F>: Clone,
{
}

impl Foo for () {
    type Bar = ();
}

fn main() {
    let _ = Blop(());
}

@shepmaster
Copy link
Member

Additional example:

type Inner = Box<i32>;
struct Wrapper(Inner);

fn main() {
    Wrapper(Box::new(42));
}
warning: type alias is never used: `Inner`
 --> src/main.rs:4:1
  |
4 | type Inner = Box<i32>;
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

Rust 1.32.0

@estebank estebank added C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Feb 20, 2019
@sanxiyn sanxiyn removed the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 12, 2019
@varkor varkor self-assigned this Mar 28, 2019
varkor added a commit to varkor/rust that referenced this issue Mar 28, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 29, 2019
@Elrendio
Copy link
Contributor

Hello,

I'm still having this issue on rustc 1.39.0 (4560ea7 2019-11-04), how can I know when this will be released ?

Thanks a lot !

@shepmaster
Copy link
Member

, how can I know when this will be released

Click on the PR that closed the issue:

image

Click on the commits:

image

Pick any of the commits, then look for the tagged version:

image

@shepmaster
Copy link
Member

I'm still having this issue

Please provide a minimized example that demonstrates the problem.

@Elrendio
Copy link
Contributor

Elrendio commented Nov 19, 2019

I'm still having this issue

Please provide a minimized example that demonstrates the problem.

Here's a link to the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=064177eade4f98748bacce0167eb354b

StructAlias is warned as never used yet used in the requirements of the AssociatedType of Trait2

@shepmaster
Copy link
Member

Further reduced:

trait Trait<S> {}

type Alias = ();

trait Trait2 {
    type Type: Trait<Alias>;
}
warning: type alias is never used: `Alias`
 --> src/lib.rs:3:1
  |
3 | type Alias = ();
  | ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

/cc @varkor — should we reopen or create a new issue?

@varkor
Copy link
Member

varkor commented Nov 19, 2019

This isn't the same as the original issue, so let's open a new one (there are already related issues, so it might be worth checking if this is already open elsewhere).

@Elrendio
Copy link
Contributor

This isn't the same as the original issue, so let's open a new one (there are already related issues, so it might be worth checking if this is already open elsewhere).

Do you think it's the same as #59333 ?

@varkor
Copy link
Member

varkor commented Nov 20, 2019

@Elrendio: that's the one I was thinking of, thanks. I've added your example there — I think they probably are the same bug (but if not, we can split out another issue then).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants