Skip to content

Inconsistency between tuples and struct-tuples with min-exhaustive-patterns #129043

Open
@ia0

Description

@ia0

I tried this code:

#![feature(min_exhaustive_patterns)]
#![feature(never_type)]

use std::marker::PhantomData;

pub fn foo<B>(x: (!, PhantomData<B>)) -> ! {
    match x {}
}

pub struct Bar<B>(!, PhantomData<B>);
impl<B> Bar<B> {
    pub fn bar(&self) -> ! {
        match *self {}
    }
}

I expected to see this happen: No errors (because Bar<B> is empty the same way foo's parameter is).

Instead, this happened: non-exhaustive patterns: type Bar<B> is non-empty.

Note that the tracking issue #119612 mentions "a struct with a visible field of empty type", so I also tried to make the first field pub ! to see, but it's the same behavior. Note that I consider the field visible in the scope it is used, which matches with the fact that adding pub did not fix the issue. The issue seems thus to be a difference between struct-tuple and tuple.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (f8060d282 2024-07-30)
binary: rustc
commit-hash: f8060d282d42770fadd73905e3eefb85660d3278
commit-date: 2024-07-30
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-discussionCategory: Discussion or questions that doesn't represent real issues.F-min_exhaustive_patterns`#![feature(min_exhaustive_patterns)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions