Add special Skip
constructor
This commit is contained in:
parent
ab06037269
commit
4f7f06777b
3 changed files with 15 additions and 22 deletions
|
@ -688,6 +688,10 @@ pub enum Constructor<Cx: TypeCx> {
|
||||||
/// 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.
|
||||||
Missing,
|
Missing,
|
||||||
|
/// Fake extra constructor that indicates that we should skip the column entirely. This is used
|
||||||
|
/// when a private field is empty, so that we don't observe its emptiness. Only used for
|
||||||
|
/// specialization.
|
||||||
|
Skip,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Cx: TypeCx> Clone for Constructor<Cx> {
|
impl<Cx: TypeCx> Clone for Constructor<Cx> {
|
||||||
|
@ -709,6 +713,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
|
||||||
Constructor::NonExhaustive => Constructor::NonExhaustive,
|
Constructor::NonExhaustive => Constructor::NonExhaustive,
|
||||||
Constructor::Hidden => Constructor::Hidden,
|
Constructor::Hidden => Constructor::Hidden,
|
||||||
Constructor::Missing => Constructor::Missing,
|
Constructor::Missing => Constructor::Missing,
|
||||||
|
Constructor::Skip => Constructor::Skip,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,6 +768,8 @@ impl<Cx: TypeCx> Constructor<Cx> {
|
||||||
}
|
}
|
||||||
// Wildcards cover anything
|
// Wildcards cover anything
|
||||||
(_, Wildcard) => true,
|
(_, Wildcard) => true,
|
||||||
|
// `Skip` skips everything.
|
||||||
|
(Skip, _) => true,
|
||||||
// Only a wildcard pattern can match these special constructors.
|
// Only a wildcard pattern can match these special constructors.
|
||||||
(Missing { .. } | NonExhaustive | Hidden, _) => false,
|
(Missing { .. } | NonExhaustive | Hidden, _) => false,
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,8 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
|
||||||
match (&self.ctor, other_ctor) {
|
match (&self.ctor, other_ctor) {
|
||||||
// Return a wildcard for each field of `other_ctor`.
|
// Return a wildcard for each field of `other_ctor`.
|
||||||
(Wildcard, _) => wildcard_sub_tys(),
|
(Wildcard, _) => wildcard_sub_tys(),
|
||||||
|
// Skip this column.
|
||||||
|
(_, Skip) => smallvec![],
|
||||||
// The only non-trivial case: two slices of different arity. `other_slice` is
|
// The only non-trivial case: two slices of different arity. `other_slice` is
|
||||||
// guaranteed to have a larger arity, so we fill the middle part with enough
|
// guaranteed to have a larger arity, so we fill the middle part with enough
|
||||||
// wildcards to reach the length of the new, larger slice.
|
// wildcards to reach the length of the new, larger slice.
|
||||||
|
@ -192,7 +194,7 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Wildcard | Missing { .. } | NonExhaustive | Hidden => write!(f, "_ : {:?}", pat.ty()),
|
Wildcard | Missing | NonExhaustive | Hidden | Skip => write!(f, "_ : {:?}", pat.ty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,16 +249,8 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||||
}
|
}
|
||||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
|
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
|
||||||
},
|
},
|
||||||
Bool(..)
|
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||||
| IntRange(..)
|
| NonExhaustive | Hidden | Missing | Skip | Wildcard => &[],
|
||||||
| F32Range(..)
|
|
||||||
| F64Range(..)
|
|
||||||
| Str(..)
|
|
||||||
| Opaque(..)
|
|
||||||
| NonExhaustive
|
|
||||||
| Hidden
|
|
||||||
| Missing { .. }
|
|
||||||
| Wildcard => &[],
|
|
||||||
Or => {
|
Or => {
|
||||||
bug!("called `Fields::wildcards` on an `Or` ctor")
|
bug!("called `Fields::wildcards` on an `Or` ctor")
|
||||||
}
|
}
|
||||||
|
@ -288,16 +280,8 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||||
},
|
},
|
||||||
Ref => 1,
|
Ref => 1,
|
||||||
Slice(slice) => slice.arity(),
|
Slice(slice) => slice.arity(),
|
||||||
Bool(..)
|
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||||
| IntRange(..)
|
| NonExhaustive | Hidden | Missing | Skip | Wildcard => 0,
|
||||||
| F32Range(..)
|
|
||||||
| F64Range(..)
|
|
||||||
| Str(..)
|
|
||||||
| Opaque(..)
|
|
||||||
| NonExhaustive
|
|
||||||
| Hidden
|
|
||||||
| Missing { .. }
|
|
||||||
| Wildcard => 0,
|
|
||||||
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
|
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -838,7 +822,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Str(value) => PatKind::Constant { value },
|
&Str(value) => PatKind::Constant { value },
|
||||||
Wildcard | NonExhaustive | Hidden => PatKind::Wild,
|
Wildcard | NonExhaustive | Hidden | Skip => 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…
Add table
Add a link
Reference in a new issue