-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #115270 - sebastiantoh:issue-105479, r=Nadrieril
Add note on non-exhaustiveness when matching on str and nested non-exhaustive enums Fixes #105479 r? `@Nadrieril`
- Loading branch information
Showing
11 changed files
with
119 additions
and
41 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
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
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,2 @@ | ||
#[non_exhaustive] | ||
pub enum NonExhaustiveEnum { A, B } |
12 changes: 12 additions & 0 deletions
12
tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.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,12 @@ | ||
fn main() { | ||
let a = ""; | ||
let b = ""; | ||
match (a, b) { | ||
//~^ ERROR non-exhaustive patterns: `(&_, _)` not covered [E0004] | ||
//~| NOTE pattern `(&_, _)` not covered | ||
//~| NOTE the matched value is of type `(&str, &str)` | ||
//~| NOTE `&str` cannot be matched exhaustively, so a wildcard `_` is necessary | ||
("a", "b") => {} | ||
("c", "d") => {} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.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,17 @@ | ||
error[E0004]: non-exhaustive patterns: `(&_, _)` not covered | ||
--> $DIR/issue-105479-str-non-exhaustiveness.rs:4:11 | ||
| | ||
LL | match (a, b) { | ||
| ^^^^^^ pattern `(&_, _)` not covered | ||
| | ||
= note: the matched value is of type `(&str, &str)` | ||
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary | ||
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", "d") => {}, | ||
LL + (&_, _) => todo!() | ||
| | ||
|
||
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
18 changes: 18 additions & 0 deletions
18
tests/ui/pattern/usefulness/nested-non-exhaustive-enums.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,18 @@ | ||
// aux-build:non-exhaustive.rs | ||
|
||
extern crate non_exhaustive; | ||
|
||
use non_exhaustive::NonExhaustiveEnum; | ||
|
||
fn main() { | ||
match Some(NonExhaustiveEnum::A) { | ||
//~^ ERROR non-exhaustive patterns: `Some(_)` not covered [E0004] | ||
//~| NOTE pattern `Some(_)` not covered | ||
//~| NOTE `Option<NonExhaustiveEnum>` defined here | ||
//~| NOTE the matched value is of type `Option<NonExhaustiveEnum>` | ||
//~| NOTE `NonExhaustiveEnum` is marked as non-exhaustive | ||
Some(NonExhaustiveEnum::A) => {} | ||
Some(NonExhaustiveEnum::B) => {} | ||
None => {} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ui/pattern/usefulness/nested-non-exhaustive-enums.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,22 @@ | ||
error[E0004]: non-exhaustive patterns: `Some(_)` not covered | ||
--> $DIR/nested-non-exhaustive-enums.rs:8:11 | ||
| | ||
LL | match Some(NonExhaustiveEnum::A) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Some(_)` not covered | ||
| | ||
note: `Option<NonExhaustiveEnum>` defined here | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
::: $SRC_DIR/core/src/option.rs:LL:COL | ||
| | ||
= note: not covered | ||
= note: the matched value is of type `Option<NonExhaustiveEnum>` | ||
= note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively | ||
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 ~ None => {}, | ||
LL + Some(_) => todo!() | ||
| | ||
|
||
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