Skip to content

"variant is never constructed" lint appears to be incorrect? #64362

Closed
@iliana

Description

@iliana

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.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions