-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
#[feature(exhaustive_patterns)] thinks irrefutable pattern is refutable when enum contains struct with private fields. #104034
Copy link
Copy link
Closed
Labels
A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-exhaustive_patterns`#![feature(exhaustive_patterns)]``#![feature(exhaustive_patterns)]`F-never_type`#![feature(never_type)]``#![feature(never_type)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.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.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Metadata
Metadata
Assignees
Labels
A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-exhaustive_patterns`#![feature(exhaustive_patterns)]``#![feature(exhaustive_patterns)]`F-never_type`#![feature(never_type)]``#![feature(never_type)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.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.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The following code compiles on nightly (playground):
But if the wrapper type is moved into a module to make the field private, then it does not: (playground):
Making the field
pubmakes it compile again.Is this expected? I suppose I could understand if it is; the private fields could change to make
Wrapper<!>actually be constructable and therefore make the pattern refutable. But if that's the case, then I think the compiler should point this out, likenote: the pattern is currently irrefutable, but the type contains private fields which may change in the future to make the pattern refutable.If indeed this is expected, is there any way for me as a library author to somehow convince the compiler that I will never change the fields to make the type constructable? I want users of my library to be able to elide match arms when I give them an
Either<A, !>.@rustbot label +T-compiler +F-never_type +D-confusing +requires-nightly +S-bug-has-mcve