@@ -53,11 +53,10 @@ assert_eq!(y, "Bigger");
53
53
54
54
An ` if let ` expression is semantically similar to an ` if ` expression but in
55
55
place of a condition expression it expects the keyword ` let ` followed by a
56
- refutable pattern, an ` = ` and an expression. If the value of the expression on
57
- the right hand side of the ` = ` matches the pattern, the corresponding block
58
- will execute, otherwise flow proceeds to the following ` else ` block if it
59
- exists. Like ` if ` expressions, ` if let ` expressions have a value determined by
60
- the block that is evaluated.
56
+ pattern, an ` = ` and a [ scrutinee] expression. If the value of the scrutinee
57
+ matches the pattern, the corresponding block will execute. Otherwise, flow
58
+ proceeds to the following ` else ` block if it exists. Like ` if ` expressions,
59
+ ` if let ` expressions have a value determined by the block that is evaluated.
61
60
62
61
``` rust
63
62
let dish = (" Ham" , " Eggs" );
@@ -74,6 +73,10 @@ if let ("Bacon", b) = dish {
74
73
if let (" Ham" , b ) = dish {
75
74
println! (" Ham is served with {}" , b );
76
75
}
76
+
77
+ if let _ = 5 {
78
+ println! (" Irrefutable patterns are always true" );
79
+ }
77
80
```
78
81
79
82
` if ` and ` if let ` expressions can be intermixed:
@@ -136,3 +139,4 @@ if let PAT = ( EXPR || EXPR ) { .. }
136
139
[ _Pattern_ ] : patterns.html
137
140
[ _LazyBooleanOperatorExpression_ ] : expressions/operator-expr.html#lazy-boolean-operators
138
141
[ _eRFCIfLetChain_ ] : https://github.com/rust-lang/rfcs/blob/master/text/2497-if-let-chains.md#rollout-plan-and-transitioning-to-rust-2018
142
+ [ scrutinee ] : glossary.html#scrutinee
0 commit comments