Skip to content

Commit f5e7dbe

Browse files
committed
Add Constructor::Never
1 parent 333e493 commit f5e7dbe

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -678,15 +678,19 @@ pub enum Constructor<Cx: TypeCx> {
678678
Or,
679679
/// Wildcard pattern.
680680
Wildcard,
681+
/// Never pattern. Only used in `WitnessPat`. An actual never pattern should be lowered as
682+
/// `Wildcard`.
683+
Never,
681684
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used
682-
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`.
685+
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`. Only
686+
/// used in `WitnessPat`.
683687
NonExhaustive,
684-
/// Fake extra constructor for variants that should not be mentioned in diagnostics.
685-
/// We use this for variants behind an unstable gate as well as
686-
/// `#[doc(hidden)]` ones.
688+
/// Fake extra constructor for variants that should not be mentioned in diagnostics. We use this
689+
/// for variants behind an unstable gate as well as `#[doc(hidden)]` ones. Only used in
690+
/// `WitnessPat`.
687691
Hidden,
688692
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
689-
/// top of the file.
693+
/// top of the file. Only used for specialization.
690694
Missing,
691695
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
692696
/// we skip the column entirely so we don't observe its emptiness. Only used for specialization.
@@ -708,6 +712,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
708712
Constructor::Str(value) => Constructor::Str(value.clone()),
709713
Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()),
710714
Constructor::Or => Constructor::Or,
715+
Constructor::Never => Constructor::Never,
711716
Constructor::Wildcard => Constructor::Wildcard,
712717
Constructor::NonExhaustive => Constructor::NonExhaustive,
713718
Constructor::Hidden => Constructor::Hidden,

compiler/rustc_pattern_analysis/src/pat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
189189
}
190190
Ok(())
191191
}
192+
Never => write!(f, "!"),
192193
Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
193194
write!(f, "_ : {:?}", pat.ty())
194195
}

compiler/rustc_pattern_analysis/src/rustc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
251251
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
252252
},
253253
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
254-
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
254+
| Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
255255
Or => {
256256
bug!("called `Fields::wildcards` on an `Or` ctor")
257257
}
@@ -279,7 +279,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
279279
Ref => 1,
280280
Slice(slice) => slice.arity(),
281281
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
282-
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
282+
| Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
283283
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
284284
}
285285
}
@@ -807,7 +807,8 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
807807
}
808808
}
809809
&Str(value) => PatKind::Constant { value },
810-
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
810+
Never if self.tcx.features().never_patterns => PatKind::Never,
811+
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
811812
Missing { .. } => bug!(
812813
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
813814
`Missing` should have been processed in `apply_constructors`"

0 commit comments

Comments
 (0)