mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 09:23:05 +00:00
Reuse adt_defined_here
This commit is contained in:
parent
d289f55b0c
commit
40f434b8c5
@ -459,11 +459,9 @@ fn check_exhaustive<'p, 'tcx>(
|
||||
return;
|
||||
} else {
|
||||
// We know the type is inhabited, so this must be wrong
|
||||
let (def_span, non_empty_enum) = match scrut_ty.kind {
|
||||
ty::Adt(def, _) if def.is_enum() => {
|
||||
(cx.tcx.hir().span_if_local(def.did), !def.variants.is_empty())
|
||||
}
|
||||
_ => (None, false),
|
||||
let non_empty_enum = match scrut_ty.kind {
|
||||
ty::Adt(def, _) => def.is_enum() && !def.variants.is_empty(),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if non_empty_enum {
|
||||
@ -478,9 +476,7 @@ fn check_exhaustive<'p, 'tcx>(
|
||||
"ensure that all possible cases are being handled, \
|
||||
possibly by adding wildcards or more match arms",
|
||||
);
|
||||
if let Some(sp) = def_span {
|
||||
err.span_label(sp, format!("`{}` defined here", scrut_ty));
|
||||
}
|
||||
adt_defined_here(cx, &mut err, scrut_ty, &[]);
|
||||
err.emit();
|
||||
return;
|
||||
}
|
||||
|
@ -9,8 +9,13 @@ LL | match uninhab_ref() {
|
||||
error[E0004]: non-exhaustive patterns: type `Foo` is non-empty
|
||||
--> $DIR/always-inhabited-union-ref.rs:27:11
|
||||
|
|
||||
LL | match uninhab_union() {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
LL | / pub union Foo {
|
||||
LL | | foo: !,
|
||||
LL | | }
|
||||
| |_- `Foo` defined here
|
||||
...
|
||||
LL | match uninhab_union() {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
|
@ -39,6 +39,9 @@ LL | match_empty!(0u8);
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
|
||||
--> $DIR/match-empty-exhaustive_patterns.rs:66:18
|
||||
|
|
||||
LL | struct NonEmptyStruct(bool);
|
||||
| ---------------------------- `NonEmptyStruct` defined here
|
||||
...
|
||||
LL | match_empty!(NonEmptyStruct(true));
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
@ -47,16 +50,27 @@ LL | match_empty!(NonEmptyStruct(true));
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
|
||||
--> $DIR/match-empty-exhaustive_patterns.rs:68:18
|
||||
|
|
||||
LL | match_empty!((NonEmptyUnion1 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / union NonEmptyUnion1 {
|
||||
LL | | foo: (),
|
||||
LL | | }
|
||||
| |_- `NonEmptyUnion1` defined here
|
||||
...
|
||||
LL | match_empty!((NonEmptyUnion1 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
|
||||
--> $DIR/match-empty-exhaustive_patterns.rs:70:18
|
||||
|
|
||||
LL | match_empty!((NonEmptyUnion2 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / union NonEmptyUnion2 {
|
||||
LL | | foo: (),
|
||||
LL | | bar: (),
|
||||
LL | | }
|
||||
| |_- `NonEmptyUnion2` defined here
|
||||
...
|
||||
LL | match_empty!((NonEmptyUnion2 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
|
@ -20,6 +20,9 @@ LL | match_empty!(0u8);
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
|
||||
--> $DIR/match-empty.rs:65:18
|
||||
|
|
||||
LL | struct NonEmptyStruct(bool);
|
||||
| ---------------------------- `NonEmptyStruct` defined here
|
||||
...
|
||||
LL | match_empty!(NonEmptyStruct(true));
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
@ -28,16 +31,27 @@ LL | match_empty!(NonEmptyStruct(true));
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
|
||||
--> $DIR/match-empty.rs:67:18
|
||||
|
|
||||
LL | match_empty!((NonEmptyUnion1 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / union NonEmptyUnion1 {
|
||||
LL | | foo: (),
|
||||
LL | | }
|
||||
| |_- `NonEmptyUnion1` defined here
|
||||
...
|
||||
LL | match_empty!((NonEmptyUnion1 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
|
||||
--> $DIR/match-empty.rs:69:18
|
||||
|
|
||||
LL | match_empty!((NonEmptyUnion2 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | / union NonEmptyUnion2 {
|
||||
LL | | foo: (),
|
||||
LL | | bar: (),
|
||||
LL | | }
|
||||
| |_- `NonEmptyUnion2` defined here
|
||||
...
|
||||
LL | match_empty!((NonEmptyUnion2 { foo: () }));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user