diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-03 22:25:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-03 22:25:15 +0100 |
| commit | ceeaa8a8520de5ec2bfb450988998e6289090a6f (patch) | |
| tree | b1120127ca9be8aaeee56cafb07795baef517f8c /compiler/rustc_pattern_analysis | |
| parent | f3ebf1e50fa266a1ace583826fa2b906f0965ff1 (diff) | |
| parent | ee2cddd8f2232aaac044c07b1a8ea1ceec083107 (diff) | |
| download | rust-ceeaa8a8520de5ec2bfb450988998e6289090a6f.tar.gz rust-ceeaa8a8520de5ec2bfb450988998e6289090a6f.zip | |
Rollup merge of #120517 - Nadrieril:lower-never-as-wildcard, r=compiler-errors
never patterns: It is correct to lower `!` to `_`.
This is just a comment update but a non-trivial one: it is correct to lower `!` patterns as `_`. The reasoning is that `!` matches all the possible values of the type, since the type is empty. Moreover, we do want to warn that the `Err` is redundant in:
```rust
match x {
!,
Err(!),
}
```
which is consistent with `!` behaving like a wildcard.
I did try to introduce `Constructor::Never` and it ended up needing to behave exactly like `Constructor::Wildcard`.
r? ```@compiler-errors```
Diffstat (limited to 'compiler/rustc_pattern_analysis')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index ec37e202118..15de3346a97 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -675,8 +675,9 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> { cx.pattern_arena.alloc_from_iter(pats.into_iter().map(|p| self.lower_pat(p))) } PatKind::Never => { - // FIXME(never_patterns): handle `!` in exhaustiveness. This is a sane default - // in the meantime. + // A never pattern matches all the values of its type (namely none). Moreover it + // must be compatible with other constructors, since we can use `!` on a type like + // `Result<!, !>` which has other constructors. Hence we lower it as a wildcard. ctor = Wildcard; fields = &[]; } |
