Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2b92ef5
let-else first draft
Fishrock123 Jun 1, 2021
3438586
let-else draft updates from zulip
Fishrock123 Jun 2, 2021
c131adb
let-else draft updates for if-let-chains
Fishrock123 Jun 2, 2021
c9e75dc
let-else draft updates for practical refactor example
Fishrock123 Jun 2, 2021
d9e8bd4
let-else draft, add desugar example
Fishrock123 Jun 2, 2021
b5c3456
let-else draft, fix let-if-chains example
Fishrock123 Jun 2, 2021
059587f
let-else draft, remove old example
Fishrock123 Jun 3, 2021
93c1f7c
let-else: rfc PR link
Fishrock123 Jun 3, 2021
836f2c4
let-else: inital updates from Josh
Fishrock123 Jun 3, 2021
22e8430
let-else: note alternative 'else' names
Fishrock123 Jun 4, 2021
d25d51a
let-else: unless -> otherwise
Fishrock123 Jun 4, 2021
f3473f6
let-else, multiple updates
Fishrock123 Jun 8, 2021
6a9a9ef
let-else, another round of updates
Fishrock123 Jun 14, 2021
18ebdca
let-else, avoid let-else within if-let
Fishrock123 Jun 17, 2021
324117c
let-else, add note about multiple patterns
Fishrock123 Jun 17, 2021
bb81a98
let-else, note let-else-else-chains
Fishrock123 Jun 17, 2021
ff866ea
let-else, note that `||` in patterns is still possible
Fishrock123 Jun 17, 2021
a4d9456
let-else, update || example desugar
Fishrock123 Jun 17, 2021
cab12fc
let-else, variable name spelling
Fishrock123 Jun 17, 2021
89c5b6e
let-else, PFCP updates
Fishrock123 Jun 28, 2021
54bca55
let-else, fix a never type link
Fishrock123 Jul 2, 2021
c0c2fcc
let-else, FCP updates
Fishrock123 Jul 13, 2021
76e8bb5
let-else, Mario's edits
Fishrock123 Jul 19, 2021
b6b87d6
let-else, disallow any expr ending with `}`.
Fishrock123 Jul 20, 2021
952745b
let-else, mention macro expansions
Fishrock123 Jul 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
let-else, Mario's edits
Excluding the block grammar clarifications for now, because those have evolved somewhat in Zulip.

Co-authored-by: Mario Carneiro <[email protected]>
  • Loading branch information
Fishrock123 and digama0 authored Jul 19, 2021
commit 76e8bb5c07f3c960edd50d46d735376a754ec420
6 changes: 4 additions & 2 deletions text/0000-let-else.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Any refutable pattern that could be put into if-let's pattern position can be pu
If the pattern is irrefutable, rustc will emit the `irrefutable_let_patterns` warning lint, as it does with an irrefutable pattern in an `if let`.

The `else` block must _diverge_, meaning the `else` block must return the [never type (`!`)][never-type]).
This could be a keyword which diverges (returns `!`), or a panic.
This could be a keyword which diverges (returns `!`), such as `return`, `break`, `continue` or `loop { ... }`, a diverging function like `std::process::abort` or `std::process::exit`, or a panic.

If the pattern does not match, the expression is not consumed, and so any existing variables from the surrounding scope are
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a separate call-out? Isn't the pattern-match behaviour exactly the same as implemented by the match expression due to the let-else statement being a sugar for let-match in this particular respect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but all existing pattern matches (to my knowledge) make the binding available to an inner scope, whereas this one makes it available to the surrounding scope.

accessible as they would normally be.
Expand Down Expand Up @@ -315,6 +315,8 @@ While this feature can partly be covered by functions such `or_or`/`ok_or_else`
such functions do not exist automatically on custom enum types and require non-obvious and non-trivial implementation, and may not be map-able
to `Option`/`Result`-style functions at all (especially for enums where the "success" variant is contextual and there are many variants).
These functions will also not work for code which wishes to return something other than `Option` or `Result`.
Moreover, this does not cover diverging blocks that do something other than return with an error or target an enclosing `try` block,
for example if the diverging expression is `continue e` or `break 'outer_loop e`.

### Naming of `else` (`let ... otherwise { ... }`)

Expand Down Expand Up @@ -445,7 +447,7 @@ let Enum::Var1(x) = a || b || { return anyhow!("Bad x"); } && let Some(z) = x ||
// Complex. Both x and z are now in scope.
```

This is not a simple construct, and could be quite confusing to newcomers
This is not a simple construct, and could be quite confusing to newcomers.

That said, such a thing is not perfectly obvious to write today, and might be just as confusing to read:
```rust
Expand Down