@@ -19,7 +19,7 @@ Rust supports four loop expressions:
1919
2020* A [ ` loop ` expression] ( #infinite-loops ) denotes an infinite loop.
2121* 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.
2323* A [ ` for ` expression] ( #iterator-loops ) extracts values from an iterator,
2424 looping until the iterator is empty.
2525
@@ -71,9 +71,9 @@ while i < 10 {
7171> [ _ BlockExpression_ ]
7272
7373A ` 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
7777body block executes then control returns to the pattern matching statement.
7878Otherwise, the while expression completes.
7979
@@ -83,6 +83,13 @@ let mut x = vec![1, 2, 3];
8383while let Some (y ) = x . pop () {
8484 println! (" y = {}" , y );
8585}
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+ }
8693```
8794
8895A ` while let ` loop is equivalent to a ` loop ` expression containing a ` match `
0 commit comments