The Wayback Machine - https://web.archive.org/web/20201228170813/https://github.com/rust-lang/reference/pull/835
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a compiler warning and explanations for irrefutable patterns. #835

Open
wants to merge 2 commits into
base: master
from

Conversation

@rimutaka
Copy link

@rimutaka rimutaka commented Jun 21, 2020

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:

@rimutaka rimutaka changed the title Added a compiler warning and explanations for irrefutable patterns. #799 Added a compiler warning and explanations for irrefutable patterns. Jun 21, 2020
Copy link
Collaborator

@ehuss ehuss left a comment

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)]`.

This comment has been minimized.

@ehuss

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.

This comment has been minimized.

@rimutaka

rimutaka Jul 7, 2020
Author

Eric, in that case you should probably close issue #799 making this PR redundant.

@@ -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.

This comment has been minimized.

@ehuss

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.