Avoid emitting the non_exhaustive error if other errors already occurred
This commit is contained in:
parent
d1fd11f3f9
commit
e83467c3b8
@ -581,13 +581,13 @@ pub enum BindingMode {
|
||||
ByRef(BorrowKind),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
pub struct FieldPat<'tcx> {
|
||||
pub field: FieldIdx,
|
||||
pub pattern: Box<Pat<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
pub struct Pat<'tcx> {
|
||||
pub ty: Ty<'tcx>,
|
||||
pub span: Span,
|
||||
@ -664,7 +664,7 @@ impl<'tcx> IntoDiagnosticArg for Pat<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
pub struct Ascription<'tcx> {
|
||||
pub annotation: CanonicalUserTypeAnnotation<'tcx>,
|
||||
/// Variance to use when relating the `user_ty` to the **type of the value being
|
||||
@ -688,7 +688,7 @@ pub struct Ascription<'tcx> {
|
||||
pub variance: ty::Variance,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||
pub enum PatKind<'tcx> {
|
||||
/// A wildcard pattern: `_`.
|
||||
Wild,
|
||||
@ -702,7 +702,9 @@ pub enum PatKind<'tcx> {
|
||||
Binding {
|
||||
mutability: Mutability,
|
||||
name: Symbol,
|
||||
#[type_visitable(ignore)]
|
||||
mode: BindingMode,
|
||||
#[type_visitable(ignore)]
|
||||
var: LocalVarId,
|
||||
ty: Ty<'tcx>,
|
||||
subpattern: Option<Box<Pat<'tcx>>>,
|
||||
@ -771,10 +773,11 @@ pub enum PatKind<'tcx> {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, HashStable)]
|
||||
#[derive(Clone, Debug, PartialEq, HashStable, TypeVisitable)]
|
||||
pub struct PatRange<'tcx> {
|
||||
pub lo: mir::Const<'tcx>,
|
||||
pub hi: mir::Const<'tcx>,
|
||||
#[type_visitable(ignore)]
|
||||
pub end: RangeEnd,
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_session::lint::builtin::{
|
||||
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
|
||||
};
|
||||
@ -682,6 +682,12 @@ fn non_exhaustive_match<'p, 'tcx>(
|
||||
arms: &[ArmId],
|
||||
expr_span: Span,
|
||||
) -> ErrorGuaranteed {
|
||||
for &arm in arms {
|
||||
if let Err(err) = thir[arm].pattern.error_reported() {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
let is_empty_match = arms.is_empty();
|
||||
let non_empty_enum = match scrut_ty.kind() {
|
||||
ty::Adt(def, _) => def.is_enum() && !def.variants().is_empty(),
|
||||
|
@ -153,6 +153,12 @@ impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for &[T] {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Box<[T]> {
|
||||
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix, T> {
|
||||
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||
self.try_map_id(|x| x.try_fold_with(folder))
|
||||
|
@ -7,7 +7,7 @@ struct T;
|
||||
|
||||
fn main() {
|
||||
const C: &S = &S;
|
||||
match C { //~ ERROR: non-exhaustive patterns: `&_` not covered
|
||||
match C {
|
||||
C => {}
|
||||
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
|
||||
}
|
||||
|
@ -7,24 +7,5 @@ LL | C => {}
|
||||
= note: the traits must be derived, manual `impl`s are not sufficient
|
||||
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/match_ice.rs:10:11
|
||||
|
|
||||
LL | match C {
|
||||
| ^ pattern `&_` not covered
|
||||
|
|
||||
note: `S` defined here
|
||||
--> $DIR/match_ice.rs:3:8
|
||||
|
|
||||
LL | struct S;
|
||||
| ^
|
||||
= note: the matched value is of type `&S`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ C => {},
|
||||
LL + &_ => todo!()
|
||||
|
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
@ -2,7 +2,7 @@ const F: &'static dyn PartialEq<u32> = &7u32;
|
||||
|
||||
fn main() {
|
||||
let a: &dyn PartialEq<u32> = &7u32;
|
||||
match a { //~ ERROR: non-exhaustive patterns: `&_` not covered
|
||||
match a {
|
||||
F => panic!(), //~ ERROR: `dyn PartialEq<u32>` cannot be used in patterns
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,5 @@ error: `dyn PartialEq<u32>` cannot be used in patterns
|
||||
LL | F => panic!(),
|
||||
| ^
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/issue-72565.rs:5:11
|
||||
|
|
||||
LL | match a {
|
||||
| ^ pattern `&_` not covered
|
||||
|
|
||||
= note: the matched value is of type `&dyn PartialEq<u32>`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL | F => panic!(), &_ => todo!(),
|
||||
| +++++++++++++++
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
@ -5,10 +5,10 @@
|
||||
#![feature(inline_const_pat)]
|
||||
|
||||
fn main() {
|
||||
match loop {} { //~ ERROR: non-exhaustive patterns: `_` not covered
|
||||
const { || {} } => {}, //~ ERROR cannot be used in patterns
|
||||
match loop {} {
|
||||
const { || {} } => {} //~ ERROR cannot be used in patterns
|
||||
}
|
||||
match loop {} { //~ ERROR: non-exhaustive patterns: `_` not covered
|
||||
const { async {} } => {}, //~ ERROR cannot be used in patterns
|
||||
match loop {} {
|
||||
const { async {} } => {} //~ ERROR cannot be used in patterns
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,14 @@
|
||||
error: `{closure@$DIR/non-structural-match-types.rs:9:17: 9:19}` cannot be used in patterns
|
||||
--> $DIR/non-structural-match-types.rs:9:9
|
||||
|
|
||||
LL | const { || {} } => {},
|
||||
LL | const { || {} } => {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: `{async block@$DIR/non-structural-match-types.rs:12:17: 12:25}` cannot be used in patterns
|
||||
--> $DIR/non-structural-match-types.rs:12:9
|
||||
|
|
||||
LL | const { async {} } => {},
|
||||
LL | const { async {} } => {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `_` not covered
|
||||
--> $DIR/non-structural-match-types.rs:8:11
|
||||
|
|
||||
LL | match loop {} {
|
||||
| ^^^^^^^ pattern `_` not covered
|
||||
|
|
||||
= note: the matched value is of type `{closure@$DIR/non-structural-match-types.rs:9:17: 9:19}`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL | const { || {} } => {}, _ => todo!(),
|
||||
| ++++++++++++++
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `_` not covered
|
||||
--> $DIR/non-structural-match-types.rs:11:11
|
||||
|
|
||||
LL | match loop {} {
|
||||
| ^^^^^^^ pattern `_` not covered
|
||||
|
|
||||
= note: the matched value is of type `{async block@$DIR/non-structural-match-types.rs:12:17: 12:25}`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL | const { async {} } => {}, _ => todo!(),
|
||||
| ++++++++++++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
@ -12,7 +12,7 @@ struct B(i32);
|
||||
|
||||
fn main() {
|
||||
const FOO: [B; 1] = [B(0)];
|
||||
match [B(1)] { //~ ERROR: non-exhaustive patterns: `[_]` not covered
|
||||
match [B(1)] {
|
||||
FOO => { }
|
||||
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
|
||||
}
|
||||
|
@ -7,19 +7,5 @@ LL | FOO => { }
|
||||
= note: the traits must be derived, manual `impl`s are not sufficient
|
||||
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `[_]` not covered
|
||||
--> $DIR/match-nonempty-array-forbidden-without-eq.rs:15:11
|
||||
|
|
||||
LL | match [B(1)] {
|
||||
| ^^^^^^ pattern `[_]` not covered
|
||||
|
|
||||
= note: the matched value is of type `[B; 1]`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ FOO => { },
|
||||
LL + [_] => todo!()
|
||||
|
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user