Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Warning about "type alias never used", but alias is used for impl block #43123

Closed
RalfJung opened this issue Jul 8, 2017 · 5 comments
Closed
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@RalfJung
Copy link
Member

RalfJung commented Jul 8, 2017

The following code

enum MyOption<T> { None, Some(T) }
use MyOption::*;

type MyType = MyOption<i32>;

impl MyType {
    fn foo(self) -> Self {
        None
    }
}

fn main() {
    Some(3).foo();
}

issues a warning in current stable and nightly:

rustc 1.18.0 (03fc9d622 2017-06-06)
warning: type alias is never used: `MyType`
 --> <anon>:4:1
  |
4 | type MyType = MyOption<i32>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

However, the type alias is actually used -- if I remove it, the code stops compiling because the impl block references the alias. Hence, there should be no warning.

@durka
Copy link
Contributor

durka commented Jul 8, 2017

Nothing is public so I believe this is intentional. I complained about a similar case in the past, with enum variants used in private functions, and was told the dead_code lint is not supposed to be a general-purpose "you may delete this code" (what is it for then? I don't know).

@durka
Copy link
Contributor

durka commented Jul 8, 2017

However, a duplicate is #39531.

@RalfJung
Copy link
Member Author

RalfJung commented Jul 8, 2017

I don't think that's a duplicate... in #39531, the functions indeed don't get used, to if you remove all of what "dead code" complains about, the resulting program still works.

Here, I would need to refactor to make the lint go away. That seems silly.

It not being public can't be the point either. Just adding a let _x : MyType; somewhere makes the warning go away, and still nothing is public.

@cramertj
Copy link
Member

cramertj commented Jul 19, 2017

As I initially reported in #43328, struct definitions also aren't considered when determining if a type alias is used.

@Mark-Simulacrum
Copy link
Member

Closing in favor of #18290.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

5 participants