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

Specify refutability of patterns in let and if let #660

Closed
wants to merge 1 commit into from
Closed

Specify refutability of patterns in let and if let #660

wants to merge 1 commit into from

Conversation

hawkinsw
Copy link
Contributor

Specify that patterns in 'if let' expressions are refutable
while patterns in 'let' statements are irrefutable.

pattern, an `=` and a [scrutinee] expression. If the value of the scrutinee
matches the pattern, the corresponding block will execute. Otherwise, flow
proceeds to the following `else` block if it exists. Like `if` expressions,
refutable pattern, an `=` and a [scrutinee] expression. If the value of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern in if let can be irrefutable.

@hawkinsw
Copy link
Contributor Author

hawkinsw commented Aug 28, 2019 via email

@hawkinsw
Copy link
Contributor Author

hawkinsw commented Aug 28, 2019 via email

@Centril
Copy link
Contributor

Centril commented Aug 28, 2019

This appears to contradict: https://doc.rust-lang.org/book/ch18-02-refutability.html

The book is wrong.

@hawkinsw
Copy link
Contributor Author

hawkinsw commented Aug 28, 2019 via email

@hawkinsw
Copy link
Contributor Author

hawkinsw commented Aug 28, 2019 via email

@Centril
Copy link
Contributor

Centril commented Aug 28, 2019

Yes we should. Please file a bug against the book's repo.

@hawkinsw
Copy link
Contributor Author

Corresponds to rust-lang/book#2039 which updates the Book. I hope that this is a helpful PR. @Centril

Specify that patterns in
1. 'if let' and 'while let' expressions are either refutable or irrefutable
2. 'let' and 'for' statements are always irrefutable
@hawkinsw
Copy link
Contributor Author

Closing to reopen because I am expanding the scope slightly.

@hawkinsw hawkinsw closed this Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants