Added a compiler warning and explanations for irrefutable patterns. #835
Conversation
Thanks for the PR! |
@@ -111,6 +111,10 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match | |||
} | |||
``` | |||
|
|||
Using an irrefutable pattern in `match`, `if let` or `while let` expressions produces a compiler warning. E.g. `if let (x, y) = (1, 2) { ... }` results in this compiler message `#[warn(irrefutable_let_patterns)]`. |
ehuss
Jul 7, 2020
Collaborator
In general, the reference does not cover rustc
lints, so I don't think it is appropriate to add this.
In general, the reference does not cover rustc
lints, so I don't think it is appropriate to add this.
@@ -111,6 +111,10 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match | |||
} | |||
``` | |||
|
|||
Using an irrefutable pattern in `match`, `if let` or `while let` expressions produces a compiler warning. E.g. `if let (x, y) = (1, 2) { ... }` results in this compiler message `#[warn(irrefutable_let_patterns)]`. | |||
|
|||
Patterns used in `let` statements, `for` expressions, *Function* and *closure* parameters are always irrefutable. |
ehuss
Jul 7, 2020
Collaborator
Typically we link each phrase to the appropriate section. For example, "let
statements" should link to statements.md#let-statements. There are links to all of these above, so moving those to reference-style links would probably be a good idea.
Also, I think the F
in function shouldn't be capitalized.
I also might use the phrase "must be irrefutable" instead of "are always".
Typically we link each phrase to the appropriate section. For example, "let
statements" should link to statements.md#let-statements. There are links to all of these above, so moving those to reference-style links would probably be a good idea.
Also, I think the F
in function shouldn't be capitalized.
I also might use the phrase "must be irrefutable" instead of "are always".
In response to issue #799
I am very new to Rust (10 days), so it needs to be reviewed for correctness.
I got the compiler warning from running the code and the irrefutability requirements from reading: