Skip to content

Commit 1ec73d7

Browse files
committed
Add Constructor::Never
1 parent 844f173 commit 1ec73d7

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
@@ -681,15 +681,19 @@ pub enum Constructor<Cx: TypeCx> {
681681
Or,
682682
/// Wildcard pattern.
683683
Wildcard,
684+
/// Never pattern. Only used in `WitnessPat`. An actual never pattern should be lowered as
685+
/// `Wildcard`.
686+
Never,
684687
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used
685-
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`.
688+
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`. Only
689+
/// used in `WitnessPat`.
686690
NonExhaustive,
687-
/// Fake extra constructor for variants that should not be mentioned in diagnostics.
688-
/// We use this for variants behind an unstable gate as well as
689-
/// `#[doc(hidden)]` ones.
691+
/// Fake extra constructor for variants that should not be mentioned in diagnostics. We use this
692+
/// for variants behind an unstable gate as well as `#[doc(hidden)]` ones. Only used in
693+
/// `WitnessPat`.
690694
Hidden,
691695
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
692-
/// top of the file.
696+
/// top of the file. Only used for specialization.
693697
Missing,
694698
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
695699
/// we skip the column entirely so we don't observe its emptiness. Only used for specialization.
@@ -711,6 +715,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
711715
Constructor::Str(value) => Constructor::Str(value.clone()),
712716
Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()),
713717
Constructor::Or => Constructor::Or,
718+
Constructor::Never => Constructor::Never,
714719
Constructor::Wildcard => Constructor::Wildcard,
715720
Constructor::NonExhaustive => Constructor::NonExhaustive,
716721
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
}
@@ -809,7 +809,8 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
809809
}
810810
}
811811
&Str(value) => PatKind::Constant { value },
812-
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
812+
Never if self.tcx.features().never_patterns => PatKind::Never,
813+
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
813814
Missing { .. } => bug!(
814815
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
815816
`Missing` should have been processed in `apply_constructors`"

0 commit comments

Comments
 (0)