Add Constructor::Never
This commit is contained in:
parent
844f173b5c
commit
1ec73d70fa
@ -681,15 +681,19 @@ pub enum Constructor<Cx: TypeCx> {
|
|||||||
Or,
|
Or,
|
||||||
/// Wildcard pattern.
|
/// Wildcard pattern.
|
||||||
Wildcard,
|
Wildcard,
|
||||||
|
/// Never pattern. Only used in `WitnessPat`. An actual never pattern should be lowered as
|
||||||
|
/// `Wildcard`.
|
||||||
|
Never,
|
||||||
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used
|
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used
|
||||||
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`.
|
/// for those types for which we cannot list constructors explicitly, like `f64` and `str`. Only
|
||||||
|
/// used in `WitnessPat`.
|
||||||
NonExhaustive,
|
NonExhaustive,
|
||||||
/// Fake extra constructor for variants that should not be mentioned in diagnostics.
|
/// Fake extra constructor for variants that should not be mentioned in diagnostics. We use this
|
||||||
/// We use this for variants behind an unstable gate as well as
|
/// for variants behind an unstable gate as well as `#[doc(hidden)]` ones. Only used in
|
||||||
/// `#[doc(hidden)]` ones.
|
/// `WitnessPat`.
|
||||||
Hidden,
|
Hidden,
|
||||||
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
|
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
|
||||||
/// top of the file.
|
/// top of the file. Only used for specialization.
|
||||||
Missing,
|
Missing,
|
||||||
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
|
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
|
||||||
/// we skip the column entirely so we don't observe its emptiness. Only used for specialization.
|
/// 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> {
|
|||||||
Constructor::Str(value) => Constructor::Str(value.clone()),
|
Constructor::Str(value) => Constructor::Str(value.clone()),
|
||||||
Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()),
|
Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()),
|
||||||
Constructor::Or => Constructor::Or,
|
Constructor::Or => Constructor::Or,
|
||||||
|
Constructor::Never => Constructor::Never,
|
||||||
Constructor::Wildcard => Constructor::Wildcard,
|
Constructor::Wildcard => Constructor::Wildcard,
|
||||||
Constructor::NonExhaustive => Constructor::NonExhaustive,
|
Constructor::NonExhaustive => Constructor::NonExhaustive,
|
||||||
Constructor::Hidden => Constructor::Hidden,
|
Constructor::Hidden => Constructor::Hidden,
|
||||||
|
@ -189,6 +189,7 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Never => write!(f, "!"),
|
||||||
Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
|
Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
|
||||||
write!(f, "_ : {:?}", pat.ty())
|
write!(f, "_ : {:?}", pat.ty())
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
|||||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
|
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
|
||||||
},
|
},
|
||||||
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||||
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
|
| Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
|
||||||
Or => {
|
Or => {
|
||||||
bug!("called `Fields::wildcards` on an `Or` ctor")
|
bug!("called `Fields::wildcards` on an `Or` ctor")
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
|||||||
Ref => 1,
|
Ref => 1,
|
||||||
Slice(slice) => slice.arity(),
|
Slice(slice) => slice.arity(),
|
||||||
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||||
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
|
| Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
|
||||||
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
|
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -809,7 +809,8 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Str(value) => PatKind::Constant { value },
|
&Str(value) => PatKind::Constant { value },
|
||||||
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
|
Never if self.tcx.features().never_patterns => PatKind::Never,
|
||||||
|
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
|
||||||
Missing { .. } => bug!(
|
Missing { .. } => bug!(
|
||||||
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
|
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
|
||||||
`Missing` should have been processed in `apply_constructors`"
|
`Missing` should have been processed in `apply_constructors`"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user