-
Notifications
You must be signed in to change notification settings - Fork 13k
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
False positive on dead_code lint #68408
Comments
Something small-ish-er: #![deny(dead_code)]
enum X {
A,
B { y: () },
}
impl X {
fn test(&mut self) {
*self = Self::B { y: () };
}
}
fn main() {
let mut x = X::A;
x.test();
} If we replace
which is indeed correct |
This is probably the most telling example: #![deny(clippy::use_self)]
#![deny(dead_code)]
#[derive(Debug)]
enum X {
A { _a: () },
B { _b: () },
}
impl X {
fn a() -> X {
X::A { _a: () }
}
fn b() -> Self {
Self::B { _b: () }
}
}
pub fn main() {
println!("{:?}", X::a());
println!("{:?}", X::b());
} This doesn't compile (dead_code), and doesn't lint with clippy (clippy::use_self, likely due to rust-lang/rust-clippy#3410). The dead_code problem doesn't manifest if |
It looks like the erroneous warning arises only for struct-like enum variants that are created only by referencing via // struct-like variant, referred to using Self
#[derive(Debug)]
enum E {
A { x: () },
}
impl E {
fn mk_e() -> Self {
Self::A { x: () }
}
}
// struct-like variant, referred to using type name
#[derive(Debug)]
enum F {
B { x: () },
}
impl F {
fn mk_f() -> Self {
F::B { x: () }
}
}
// tuple variant, referred to using Self
#[derive(Debug)]
enum G {
C(()),
}
impl G {
fn mk_g() -> Self {
Self::C(())
}
}
fn main() {
dbg!(E::mk_e());
dbg!(F::mk_f());
dbg!(G::mk_g());
}
|
These seem to have been fixed. The above playground link has no warnings. |
searched nightlies: from nightly-2020-01-26 to nightly-2020-08-03 bisected with cargo-bisect-rustc v0.5.2Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --access github --regress success How is that related? 😅 But nevertheless: @rustbot modify labels: E-needs-test |
@hellow554 That bisection may be because of a bug in cargo-bisect-rustc that was fixed in the latest release; see rust-lang/cargo-bisect-rustc#98. |
…rrors Add regression test for rust-lang#68408 Closes rust-lang#68408
Rollup of 7 pull requests Successful merges: - rust-lang#96543 (Remove hacks in `make_token_stream`.) - rust-lang#96887 (rustdoc: correct path to type alias methods) - rust-lang#96896 (Add regression test for rust-lang#68408) - rust-lang#96900 (Fix js error) - rust-lang#96903 (Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes) - rust-lang#96916 (simplify length count) - rust-lang#96925 (Fix issue rust-lang#95151) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I'm sure that there is a more concise way to generate this error, but this produces a
dead_code
lint warning:(Playground)
This code instantiates
X::B
, but thedead_code
lint disagrees:The text was updated successfully, but these errors were encountered: