Skip to content

Commit 4c2b4ca

Browse files
committed
Auto merge of #140106 - dianne:deref-pat-usefulness, r=Nadrieril
allow deref patterns to participate in exhaustiveness analysis Per [this proposal](https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Exhaustiveness), this PR allows deref patterns to participate in exhaustiveness analysis. Currently all deref patterns enforce `DerefPure` bounds on their scrutinees, so this assumes all patterns it's analyzing are well-behaved. This also doesn't support [mixed exhaustiveness](https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Mixed-exhaustiveness), and instead emits an error if deref patterns are used together with normal constructors. I think mixed exhaustiveness would be nice to have (especially if we eventually want to support arbitrary `Deref` impls[^1]), but it'd require more work to get reasonable diagnostics[^2]. Tracking issue for deref patterns: #87121 r? `@Nadrieril` [^1]: Regardless of whether we support limited exhaustiveness checking for untrusted `Deref` or always require other arms to be exhaustive, I think it'd be useful to allow mixed matching for user-defined smart pointers. And it'd be strange if it worked there but not for `Cow`. [^2]: I think listing out witnesses of non-exhaustiveness can be confusing when they're not necessarily disjoint, and when you only need to cover some of them, so we'd probably want special formatting and/or explanatory subdiagnostics. And if it's implemented similarly to unions, we'd probably also want some way of merging witnesses; the way witnesses for unions can appear duplicated is pretty unfortunate. I'm not sure yet how the diagnostics should look, especially for deeply nested patterns.
2 parents cdc27d1 + eb446f9 commit 4c2b4ca

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ impl<'db> MatchCheckCtx<'db> {
301301
// ignore this issue.
302302
Ref => PatKind::Deref { subpattern: subpatterns.next().unwrap() },
303303
Slice(_) => unimplemented!(),
304+
DerefPattern(_) => unimplemented!(),
304305
&Str(void) => match void {},
305306
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
306307
Never => PatKind::Never,
@@ -351,6 +352,7 @@ impl PatCx for MatchCheckCtx<'_> {
351352
},
352353
Ref => 1,
353354
Slice(..) => unimplemented!(),
355+
DerefPattern(..) => unimplemented!(),
354356
Never | Bool(..) | IntRange(..) | F16Range(..) | F32Range(..) | F64Range(..)
355357
| F128Range(..) | Str(..) | Opaque(..) | NonExhaustive | PrivateUninhabited
356358
| Hidden | Missing | Wildcard => 0,
@@ -411,6 +413,7 @@ impl PatCx for MatchCheckCtx<'_> {
411413
}
412414
},
413415
Slice(_) => unreachable!("Found a `Slice` constructor in match checking"),
416+
DerefPattern(_) => unreachable!("Found a `DerefPattern` constructor in match checking"),
414417
Never | Bool(..) | IntRange(..) | F16Range(..) | F32Range(..) | F64Range(..)
415418
| F128Range(..) | Str(..) | Opaque(..) | NonExhaustive | PrivateUninhabited
416419
| Hidden | Missing | Wildcard => {

0 commit comments

Comments
 (0)