-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
ztlpn, quadruple-output, Lonami, attila-lin, nikonthethird and 5 more
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
tuftool: Work around dead code linting bug
hellow554 commentedon Sep 11, 2019
This is correct. Your snippet is treated as a library, where the enum
Foo
is not reachable, because it is not public.If you write
pub enum Foo
the error will go away.Behavoir inteded and therefore this can be closed.
jakubadamw commentedon Sep 11, 2019
The bug is that it doesn't trigger for
B
.If the lint triggered for all variants, then it would just say:
ztlpn commentedon Sep 11, 2019
The problem seems to manifest itself when variants with named fields are constructed using
Self::
.Here is a minimal example (playground):
jakubadamw commentedon Sep 11, 2019
@rustbot claim
Self::
variant paths #64424Rollup merge of rust-lang#64424 - jakubadamw:issue-64362, r=estebank
tuftool: Work around dead code linting bug
tuftool: Work around dead code linting bug
tuftool: Work around dead code linting bug
tuftool: Work around dead code linting bug
hjmallon commentedon Dec 4, 2019
Here is a slightly altered playground to illlustrate further.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=3658bbcaddc011fee8744d027a2086ad
Work-around rust-lang/rust#64362
Self::
variant paths (resolved conflict) #69377Self::
variant paths #71026Rollup merge of rust-lang#71026 - seiyab:issue-64362-adhoc, r=varkor