Fold away AscribeUserType

This commit is contained in:
Nadrieril 2019-11-17 23:05:50 +00:00
parent 5510f5589e
commit e6e5513894

View File

@ -347,6 +347,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
) => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty), ) => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty),
(_, &PatKind::Binding { subpattern: Some(ref s), .. }) => s.fold_with(self), (_, &PatKind::Binding { subpattern: Some(ref s), .. }) => s.fold_with(self),
(_, &PatKind::AscribeUserType { subpattern: ref s, .. }) => s.fold_with(self),
_ => pat.super_fold_with(self), _ => pat.super_fold_with(self),
} }
} }
@ -1759,9 +1760,7 @@ fn pat_constructor<'tcx>(
pat: &Pat<'tcx>, pat: &Pat<'tcx>,
) -> Option<Constructor<'tcx>> { ) -> Option<Constructor<'tcx>> {
match *pat.kind { match *pat.kind {
PatKind::AscribeUserType { ref subpattern, .. } => { PatKind::AscribeUserType { .. } => bug!(), // Handled by `expand_pattern`
pat_constructor(tcx, param_env, subpattern)
}
PatKind::Binding { .. } | PatKind::Wild => None, PatKind::Binding { .. } | PatKind::Wild => None,
PatKind::Leaf { .. } | PatKind::Deref { .. } => Some(Single), PatKind::Leaf { .. } | PatKind::Deref { .. } => Some(Single),
PatKind::Variant { adt_def, variant_index, .. } => { PatKind::Variant { adt_def, variant_index, .. } => {
@ -2262,21 +2261,17 @@ fn patterns_for_variant<'p, 'a: 'p, 'tcx>(
/// fields filled with wild patterns. /// fields filled with wild patterns.
fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>( fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
cx: &mut MatchCheckCtxt<'a, 'tcx>, cx: &mut MatchCheckCtxt<'a, 'tcx>,
mut pat: &'q Pat<'tcx>, pat: &'q Pat<'tcx>,
constructor: &Constructor<'tcx>, constructor: &Constructor<'tcx>,
ctor_wild_subpatterns: &[&'p Pat<'tcx>], ctor_wild_subpatterns: &[&'p Pat<'tcx>],
) -> Option<PatStack<'p, 'tcx>> { ) -> Option<PatStack<'p, 'tcx>> {
while let PatKind::AscribeUserType { ref subpattern, .. } = *pat.kind {
pat = subpattern;
}
if let NonExhaustive = constructor { if let NonExhaustive = constructor {
// Only a wildcard pattern can match the special extra constructor // Only a wildcard pattern can match the special extra constructor
return if pat.is_wildcard() { Some(PatStack::default()) } else { None }; return if pat.is_wildcard() { Some(PatStack::default()) } else { None };
} }
let result = match *pat.kind { let result = match *pat.kind {
PatKind::AscribeUserType { .. } => bug!(), // Handled above PatKind::AscribeUserType { .. } => bug!(), // Handled by `expand_pattern`
PatKind::Binding { .. } | PatKind::Wild => { PatKind::Binding { .. } | PatKind::Wild => {
Some(PatStack::from_slice(ctor_wild_subpatterns)) Some(PatStack::from_slice(ctor_wild_subpatterns))