Propagate pattern errors via a new PatKind::Error
variant
Instead of via `Const::new_error`
This commit is contained in:
parent
e20cb77021
commit
aab3b9327e
12 changed files with 56 additions and 41 deletions
|
@ -814,7 +814,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
PatKind::Constant { .. } | PatKind::Range { .. } | PatKind::Wild => {}
|
||||
PatKind::Constant { .. }
|
||||
| PatKind::Range { .. }
|
||||
| PatKind::Wild
|
||||
| PatKind::Error(_) => {}
|
||||
|
||||
PatKind::Deref { ref subpattern } => {
|
||||
self.visit_primary_bindings(subpattern, pattern_user_ty.deref(), f);
|
||||
|
|
|
@ -168,7 +168,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
PatKind::Wild => {
|
||||
PatKind::Wild | PatKind::Error(_) => {
|
||||
// nothing left to do
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
| PatKind::Wild
|
||||
| PatKind::Binding { .. }
|
||||
| PatKind::Leaf { .. }
|
||||
| PatKind::Deref { .. } => self.error_simplifiable(match_pair),
|
||||
| PatKind::Deref { .. }
|
||||
| PatKind::Error(_) => self.error_simplifiable(match_pair),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
| PatKind::Binding { .. }
|
||||
| PatKind::AscribeUserType { .. }
|
||||
| PatKind::Leaf { .. }
|
||||
| PatKind::Deref { .. } => {
|
||||
| PatKind::Deref { .. }
|
||||
| PatKind::Error(_) => {
|
||||
// don't know how to add these patterns to a switch
|
||||
false
|
||||
}
|
||||
|
|
|
@ -224,7 +224,8 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
PatKind::Wild |
|
||||
// these just wrap other patterns
|
||||
PatKind::Or { .. } |
|
||||
PatKind::AscribeUserType { .. } => {}
|
||||
PatKind::AscribeUserType { .. } |
|
||||
PatKind::Error(_) => {}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ use rustc_hir::HirId;
|
|||
use rustc_middle::thir::visit::{self, Visitor};
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
|
||||
use rustc_session::lint::builtin::{
|
||||
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
|
||||
};
|
||||
|
@ -683,7 +683,7 @@ fn non_exhaustive_match<'p, 'tcx>(
|
|||
expr_span: Span,
|
||||
) -> ErrorGuaranteed {
|
||||
for &arm in arms {
|
||||
if let Err(err) = thir[arm].pattern.error_reported() {
|
||||
if let Err(err) = thir[arm].pattern.pat_error_reported() {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,9 +196,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
};
|
||||
// All branches above emitted an error. Don't print any more lints.
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
let kind = PatKind::Constant {
|
||||
value: mir::Const::Ty(ty::Const::new_error(self.tcx(), e, cv.ty())),
|
||||
};
|
||||
let kind = PatKind::Error(e);
|
||||
return Box::new(Pat { span: self.span, ty: cv.ty(), kind });
|
||||
} else if !self.saw_const_match_lint.get() {
|
||||
if let Some(mir_structural_match_violation) = mir_structural_match_violation {
|
||||
|
@ -351,7 +349,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
let e = tcx.sess.emit_err(InvalidPattern { span, non_sm_ty: ty });
|
||||
self.saw_const_match_error.set(Some(e));
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)) }
|
||||
PatKind::Error(e)
|
||||
}
|
||||
ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
|
||||
debug!("adt_def {:?} has !type_marked_structural for cv.ty: {:?}", adt_def, ty,);
|
||||
|
@ -359,7 +357,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
let e = tcx.sess.emit_err(err);
|
||||
self.saw_const_match_error.set(Some(e));
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)) }
|
||||
PatKind::Error(e)
|
||||
}
|
||||
ty::Adt(adt_def, args) if adt_def.is_enum() => {
|
||||
let (&variant_index, fields) = cv.unwrap_branch().split_first().unwrap();
|
||||
|
@ -434,17 +432,13 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
} else {
|
||||
if let Some(e) = self.saw_const_match_error.get() {
|
||||
// We already errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant {
|
||||
value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)),
|
||||
}
|
||||
PatKind::Error(e)
|
||||
} else {
|
||||
let err = TypeNotStructural { span, non_sm_ty: *pointee_ty };
|
||||
let e = tcx.sess.emit_err(err);
|
||||
self.saw_const_match_error.set(Some(e));
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant {
|
||||
value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)),
|
||||
}
|
||||
PatKind::Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -456,9 +450,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
let err = UnsizedPattern { span, non_sm_ty: *pointee_ty };
|
||||
let e = tcx.sess.emit_err(err);
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant {
|
||||
value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)),
|
||||
}
|
||||
PatKind::Error(e)
|
||||
} else {
|
||||
let old = self.behind_reference.replace(true);
|
||||
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
|
||||
|
@ -489,7 +481,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
let e = tcx.sess.emit_err(err);
|
||||
self.saw_const_match_error.set(Some(e));
|
||||
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
|
||||
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_error(tcx, e, ty)) }
|
||||
PatKind::Error(e)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1525,6 +1525,10 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
|
|||
let pats = expand_or_pat(pat);
|
||||
fields = Fields::from_iter(cx, pats.into_iter().map(mkpat));
|
||||
}
|
||||
PatKind::Error(_) => {
|
||||
ctor = Opaque;
|
||||
fields = Fields::empty();
|
||||
}
|
||||
}
|
||||
DeconstructedPat::new(ctor, fields, pat.ty, pat.span)
|
||||
}
|
||||
|
|
|
@ -791,6 +791,7 @@ impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> {
|
|||
fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
PatKind::Wild => PatKind::Wild,
|
||||
PatKind::Error(e) => PatKind::Error(e),
|
||||
PatKind::AscribeUserType {
|
||||
ref subpattern,
|
||||
ascription: Ascription { ref annotation, variance },
|
||||
|
|
|
@ -757,6 +757,9 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
|
|||
print_indented!(self, "]", depth_lvl + 2);
|
||||
print_indented!(self, "}", depth_lvl + 1);
|
||||
}
|
||||
PatKind::Error(_) => {
|
||||
print_indented!(self, "Error", depth_lvl + 1);
|
||||
}
|
||||
}
|
||||
|
||||
print_indented!(self, "}", depth_lvl);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue