Avoid emitting the non_exhaustive error if other errors already occurred
This commit is contained in:
parent
d1fd11f3f9
commit
e83467c3b8
11 changed files with 34 additions and 90 deletions
|
@ -581,13 +581,13 @@ pub enum BindingMode {
|
||||||
ByRef(BorrowKind),
|
ByRef(BorrowKind),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||||
pub struct FieldPat<'tcx> {
|
pub struct FieldPat<'tcx> {
|
||||||
pub field: FieldIdx,
|
pub field: FieldIdx,
|
||||||
pub pattern: Box<Pat<'tcx>>,
|
pub pattern: Box<Pat<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||||
pub struct Pat<'tcx> {
|
pub struct Pat<'tcx> {
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
pub span: Span,
|
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 struct Ascription<'tcx> {
|
||||||
pub annotation: CanonicalUserTypeAnnotation<'tcx>,
|
pub annotation: CanonicalUserTypeAnnotation<'tcx>,
|
||||||
/// Variance to use when relating the `user_ty` to the **type of the value being
|
/// 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,
|
pub variance: ty::Variance,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable, TypeVisitable)]
|
||||||
pub enum PatKind<'tcx> {
|
pub enum PatKind<'tcx> {
|
||||||
/// A wildcard pattern: `_`.
|
/// A wildcard pattern: `_`.
|
||||||
Wild,
|
Wild,
|
||||||
|
@ -702,7 +702,9 @@ pub enum PatKind<'tcx> {
|
||||||
Binding {
|
Binding {
|
||||||
mutability: Mutability,
|
mutability: Mutability,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
|
#[type_visitable(ignore)]
|
||||||
mode: BindingMode,
|
mode: BindingMode,
|
||||||
|
#[type_visitable(ignore)]
|
||||||
var: LocalVarId,
|
var: LocalVarId,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
subpattern: Option<Box<Pat<'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 struct PatRange<'tcx> {
|
||||||
pub lo: mir::Const<'tcx>,
|
pub lo: mir::Const<'tcx>,
|
||||||
pub hi: mir::Const<'tcx>,
|
pub hi: mir::Const<'tcx>,
|
||||||
|
#[type_visitable(ignore)]
|
||||||
pub end: RangeEnd,
|
pub end: RangeEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ use rustc_hir::HirId;
|
||||||
use rustc_middle::thir::visit::{self, Visitor};
|
use rustc_middle::thir::visit::{self, Visitor};
|
||||||
use rustc_middle::thir::*;
|
use rustc_middle::thir::*;
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
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::{
|
use rustc_session::lint::builtin::{
|
||||||
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
|
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
|
||||||
};
|
};
|
||||||
|
@ -682,6 +682,12 @@ fn non_exhaustive_match<'p, 'tcx>(
|
||||||
arms: &[ArmId],
|
arms: &[ArmId],
|
||||||
expr_span: Span,
|
expr_span: Span,
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
|
for &arm in arms {
|
||||||
|
if let Err(err) = thir[arm].pattern.error_reported() {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let is_empty_match = arms.is_empty();
|
let is_empty_match = arms.is_empty();
|
||||||
let non_empty_enum = match scrut_ty.kind() {
|
let non_empty_enum = match scrut_ty.kind() {
|
||||||
ty::Adt(def, _) => def.is_enum() && !def.variants().is_empty(),
|
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> {
|
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> {
|
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))
|
self.try_map_id(|x| x.try_fold_with(folder))
|
||||||
|
|
|
@ -7,7 +7,7 @@ struct T;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
const C: &S = &S;
|
const C: &S = &S;
|
||||||
match C { //~ ERROR: non-exhaustive patterns: `&_` not covered
|
match C {
|
||||||
C => {}
|
C => {}
|
||||||
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
|
//~^ 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: 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
|
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
|
||||||
|
|
||||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
error: aborting due to previous error
|
||||||
--> $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 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() {
|
fn main() {
|
||||||
let a: &dyn PartialEq<u32> = &7u32;
|
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
|
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!(),
|
LL | F => panic!(),
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
error: aborting due to previous error
|
||||||
--> $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 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0004`.
|
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
#![feature(inline_const_pat)]
|
#![feature(inline_const_pat)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match loop {} { //~ ERROR: non-exhaustive patterns: `_` not covered
|
match loop {} {
|
||||||
const { || {} } => {}, //~ ERROR cannot be used in patterns
|
const { || {} } => {} //~ ERROR cannot be used in patterns
|
||||||
}
|
}
|
||||||
match loop {} { //~ ERROR: non-exhaustive patterns: `_` not covered
|
match loop {} {
|
||||||
const { async {} } => {}, //~ ERROR cannot be used in patterns
|
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
|
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
|
--> $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
|
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
|
--> $DIR/non-structural-match-types.rs:12:9
|
||||||
|
|
|
|
||||||
LL | const { async {} } => {},
|
LL | const { async {} } => {}
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0004]: non-exhaustive patterns: `_` not covered
|
error: aborting due to 2 previous errors
|
||||||
--> $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[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() {
|
fn main() {
|
||||||
const FOO: [B; 1] = [B(0)];
|
const FOO: [B; 1] = [B(0)];
|
||||||
match [B(1)] { //~ ERROR: non-exhaustive patterns: `[_]` not covered
|
match [B(1)] {
|
||||||
FOO => { }
|
FOO => { }
|
||||||
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
|
//~^ 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: 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
|
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
|
||||||
|
|
||||||
error[E0004]: non-exhaustive patterns: `[_]` not covered
|
error: aborting due to previous error
|
||||||
--> $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 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0004`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue