@@ -23,7 +23,7 @@ The motivation for having any construct at all for this is to simplify the cases
2323a ` match ` statement with a single non-trivial case. This is predominately used for unwrapping
2424` Option<T> ` values, but can be used elsewhere.
2525
26- The idiomatic solution today for testing and unwrawpping an ` Option<T> ` looks like
26+ The idiomatic solution today for testing and unwrapping an ` Option<T> ` looks like
2727
2828``` rust
2929match optVal {
@@ -51,7 +51,7 @@ This is generally considered to be a less idiomatic solution than the `match`. I
5151fixing rightward drift, but it ends up testing the value twice (which should be optimized away, but
5252semantically speaking still happens), with the second test being a method that potentially
5353introduces failure. From context, the failure won't happen, but it still imposes a semantic burden
54- on the reader. Finally, it requies having a pre-existing let-binding for the optional value; if the
54+ on the reader. Finally, it requires having a pre-existing let-binding for the optional value; if the
5555value is a temporary, then a new let-binding in the parent scope is required in order to be able to
5656test and unwrap in two separate expressions.
5757
@@ -67,7 +67,7 @@ if let Some(x) = optVal {
6767
6868The ` if let ` construct is based on the precedent set by Swift, which introduced its own ` if let `
6969statement. In Swift, ` if let var = expr { ... } ` is directly tied to the notion of optional values,
70- and unwraps the optional value that ` expr ` evalutes to. In this proposal, the equivalent is `if let
70+ and unwraps the optional value that ` expr ` evaluates to. In this proposal, the equivalent is `if let
7171Some(var) = expr { ... }`.
7272
7373Given the following rough grammar for an ` if ` condition:
@@ -100,6 +100,10 @@ Optionally, one or more `else if` (not `else if let`) blocks can be placed in th
100100pattern guards on ` _ ` . This could be done to simplify the code when pretty-printing the expansion
101101result. Otherwise, this is an unnecessary transformation.
102102
103+ Due to some uncertainty regarding potentially-surprising fallout of AST rewrites, and some worries
104+ about exhaustiveness-checking (e.g. a tautological ` if let ` would be an error, which may be
105+ unexpected), this is put behind a feature gate named ` if_let ` .
106+
103107## Examples
104108
105109Source:
0 commit comments