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

Do not complain about unused code when used in `impl` `Self` type #63317

Open
wants to merge 1 commit into
base: master
from

Conversation

@estebank
Copy link
Contributor

commented Aug 6, 2019

Fix #18290.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Aug 6, 2019

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2019


#![deny(dead_code)]

const TLC: usize = 4;

This comment has been minimized.

Copy link
@estebank

estebank Aug 6, 2019

Author Contributor

No complaint about TLC being unused

}

struct X;
struct Y;

This comment has been minimized.

Copy link
@estebank

estebank Aug 6, 2019

Author Contributor

No complaint about Y being unused

Bar(u8),
Void(Void),
Void(Void), //~ WARN never used

This comment has been minimized.

Copy link
@estebank

estebank Aug 6, 2019

Author Contributor

With this change we no longer complain about unused enums, only unused variants, which might not be what we want. This happens because we now explore enum variants' fields to figure out wether any given ADT is used, like Void in the example above. I believe this is better behavior, but now we don't get unused Foo warnings at all and can be quite annoying if a variant is never used but part of the usable API (but I guess that then it would be pub and shouldn't emit anything).

This comment has been minimized.

Copy link
@RalfJung

RalfJung Aug 10, 2019

Member

With this change we no longer complain about unused enums, only unused variants, which might not be what we want.

Seems like a regression to me. If an enum has no variants and is never used, it should still be warned about -- similar to a struct with no fields that is never used.

This comment has been minimized.

Copy link
@estebank

estebank Aug 12, 2019

Author Contributor

The individual variants are warned about but the enum itself isn't. I believe it should be possible to have both, but is that something we want or is it just too verbose?

This comment has been minimized.

Copy link
@RalfJung

RalfJung Aug 12, 2019

Member

If the enum has no variants, it's certainly not too verbose to warn at all at the enum itself.

}

fn main() {}
fn main() {
let x = Foo::Bar(42);

This comment has been minimized.

Copy link
@estebank

estebank Aug 6, 2019

Author Contributor

This is added to remove the warning for Foo::Bar, not Foo.

@@ -5,12 +5,15 @@
// when deriving Debug on an empty enum

#[derive(Debug)]
enum Void {} //~ WARN never used
enum Void {}

This comment has been minimized.

Copy link
@estebank

estebank Aug 6, 2019

Author Contributor

This test is to verify that this doesn't emit a warning due to derive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.