diff options
| author | bors <bors@rust-lang.org> | 2021-01-04 13:23:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-04 13:23:08 +0000 |
| commit | ab5b9aecb9656a6d6e61fc7c14e4f1fe438dde56 (patch) | |
| tree | 75fd2c4bd5bddefb4f3f2535f9953276ff25de22 /src/test/ui | |
| parent | 6163bfdcce6404c5d61d6ab441bf49a831082194 (diff) | |
| parent | 914bc1717877b7f2520e7b95435ee70742a14ba3 (diff) | |
| download | rust-ab5b9aecb9656a6d6e61fc7c14e4f1fe438dde56.tar.gz rust-ab5b9aecb9656a6d6e61fc7c14e4f1fe438dde56.zip | |
Auto merge of #80651 - GroteGnoom:issue-78123-fix, r=Nadrieril
Add note to non-exhaustive match on reference to empty Rust prints "type `&A` is non-empty" even is A is empty. This is the intended behavior, but can be confusing. This commit adds a note to non-exhaustive pattern errors if they are a reference to something uninhabited. I did not add tests to check that the note is not shown for non-references or inhabited references, because this is already done in other tests. Maybe the added test is superfluous, because `always-inhabited-union-ref` already checks for this case. This does not handle &&Void or &&&void etc. I could add those as special cases as well and ignore people who need quadruple references. Fixes #78123
Diffstat (limited to 'src/test/ui')
4 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr index 0fa77fb73da..2ca774a48b6 100644 --- a/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr +++ b/src/test/ui/pattern/usefulness/always-inhabited-union-ref.stderr @@ -6,6 +6,7 @@ LL | match uninhab_ref() { | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `&!` + = note: references are always considered inhabited error[E0004]: non-exhaustive patterns: type `Foo` is non-empty --> $DIR/always-inhabited-union-ref.rs:27:11 diff --git a/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.rs b/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.rs new file mode 100644 index 00000000000..6c5a331b4b5 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.rs @@ -0,0 +1,11 @@ +enum A {} + //~^ NOTE `A` defined here + +fn f(a: &A) { + match a {} + //~^ ERROR non-exhaustive patterns: type `&A` is non-empty + //~| NOTE the matched value is of type `&A` + //~| NOTE references are always considered inhabited +} + +fn main() {} diff --git a/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.stderr b/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.stderr new file mode 100644 index 00000000000..e992632a91f --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.stderr @@ -0,0 +1,16 @@ +error[E0004]: non-exhaustive patterns: type `&A` is non-empty + --> $DIR/issue-78123-non-exhaustive-reference.rs:5:11 + | +LL | enum A {} + | --------- `A` defined here +... +LL | match a {} + | ^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `&A` + = note: references are always considered inhabited + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index 960c4792e65..7b999f50773 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -23,6 +23,7 @@ LL | let _ = match x {}; | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `&Void` + = note: references are always considered inhabited error[E0004]: non-exhaustive patterns: type `(Void,)` is non-empty --> $DIR/uninhabited-matches-feature-gated.rs:18:19 |
