Closed
Description
This code (playground) causes a "variant is never constructed" lint, even though the variant is constructed in the FromStr
implementation:
use std::str::FromStr;
enum Foo {
A { inner: () },
B,
}
impl FromStr for Foo {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
match s {
"a" => Ok(Self::A { inner: () }),
"b" => Ok(Self::B),
_ => Err(()),
}
}
}
warning: variant is never constructed: `A`
--> src/lib.rs:4:5
|
4 | A { inner: () },
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
Changing Self
for the type name in from_str
for Foo
(playground) compiles with the "field is never used" lint I would expect from this code.
Tested on rustc 1.39.0-nightly (0b36e9dea 2019-09-09)
This issue has been assigned to @jakubadamw via this comment.