forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#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 rust-lang#78123
- Loading branch information
Showing
5 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/pattern/usefulness/issue-78123-non-exhaustive-reference.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters