@@ -19,7 +19,7 @@ Rust supports four loop expressions:
19
19
20
20
* A [ ` loop ` expression] ( #infinite-loops ) denotes an infinite loop.
21
21
* A [ ` while ` expression] ( #predicate-loops ) loops until a predicate is false.
22
- * A [ ` while let ` expression] ( #predicate-pattern-loops ) tests a refutable pattern.
22
+ * A [ ` while let ` expression] ( #predicate-pattern-loops ) tests a pattern.
23
23
* A [ ` for ` expression] ( #iterator-loops ) extracts values from an iterator,
24
24
looping until the iterator is empty.
25
25
@@ -71,9 +71,9 @@ while i < 10 {
71
71
> [ _ BlockExpression_ ]
72
72
73
73
A ` while let ` loop is semantically similar to a ` while ` loop but in place of a
74
- condition expression it expects the keyword ` let ` followed by a refutable
75
- pattern, an ` = ` , a [ scrutinee] expression and a block expression. If the value of
76
- the expression on the right hand side of the ` = ` matches the pattern, the loop
74
+ condition expression it expects the keyword ` let ` followed by a pattern, an
75
+ ` = ` , a [ scrutinee] expression and a block expression. If the value of the
76
+ expression on the right hand side of the ` = ` matches the pattern, the loop
77
77
body block executes then control returns to the pattern matching statement.
78
78
Otherwise, the while expression completes.
79
79
@@ -83,6 +83,13 @@ let mut x = vec![1, 2, 3];
83
83
while let Some (y ) = x . pop () {
84
84
println! (" y = {}" , y );
85
85
}
86
+
87
+ // Irrefutable patterns are allowed primarily to make it easier for macros to
88
+ // accept any kind of pattern.
89
+ while let _ = 5 {
90
+ println! (" Irrefutable patterns are always true" );
91
+ break ;
92
+ }
86
93
```
87
94
88
95
A ` while let ` loop is equivalent to a ` loop ` expression containing a ` match `
0 commit comments