Skip to content

dead-code false positive on named structs with a never field #128053

Closed

Description

Code

#![feature(never_type)]

pub struct JustEmpty(!);

pub struct FancyEmpty {
    _empty: !,
}

Current output

warning: struct `FancyEmpty` is never constructed
 --> src/lib.rs:5:12
  |
5 | pub struct FancyEmpty {
  |            ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `playground` (lib) generated 1 warning

Desired output

Compiles without warnings.

Rationale and extra context

The struct is meant to not be constructible. Also the behavior is incoherent between tuple structs (correct behavior) and named structs (incorrect behavior).

Also, this is a regression, this didn't use to be the case.

Other cases

No response

Rust Version

rustc 1.82.0-nightly (92c6c0380 2024-07-21)
binary: rustc
commit-hash: 92c6c03805408a1a261b98013304e9bbf59ee428
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-inconsistentDiagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.Diagnostics: Inconsistency in formatting, grammar or style between diagnostic messages.F-never_type`#![feature(never_type)]``#![feature(never_type)]`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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions