Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ia0 opened this issue Aug 13, 2024 · 3 comments
Open

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

ia0 opened this issue Aug 13, 2024 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. F-min_exhaustive_patterns `#![feature(min_exhaustive_patterns)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ia0
Copy link
Contributor

ia0 commented Aug 13, 2024

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
@ia0 ia0 added the C-bug Category: This is a bug. label Aug 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 13, 2024
@ChayimFriedman2
Copy link
Contributor

The difference is not between the types, it's because for the tuple struct you have a reference, and it's the expected outcome. See #119612.

@rustbot label -C-bug +C-discussion

@rustbot rustbot added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. labels Aug 13, 2024
@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Aug 13, 2024

To wit, the example compiles successfully after removing the reference from Bar::bar's self parameter (playground):

 impl<B> Bar<B> {
-    pub fn bar(&self) -> ! {
-        match *self {}
+    pub fn bar(self) -> ! {
+        match self {}
     }
 }

@ia0
Copy link
Contributor Author

ia0 commented Aug 13, 2024

I've seen the limitation about reference, but my understanding of that limitation is when matching on a reference, which here I'm not. I'm explicitly matching on the value by derefencing manually. So maybe this is a bad interaction with match ergonomics hiding the dereference to the lint?

@jieyouxu jieyouxu added F-min_exhaustive_patterns `#![feature(min_exhaustive_patterns)]` A-diagnostics Area: Messages for errors, warnings, and lints T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. F-min_exhaustive_patterns `#![feature(min_exhaustive_patterns)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants