File tree Expand file tree Collapse file tree 3 files changed +12
-14
lines changed Expand file tree Collapse file tree 3 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -1461,16 +1461,16 @@ impl Eval for ast::ForLoop {
1461
1461
1462
1462
match ( pattern. kind ( ) , iter. clone ( ) ) {
1463
1463
( ast:: PatternKind :: Ident ( _) , Value :: Str ( string) ) => {
1464
- // iterate over characters of string
1464
+ // Iterate over graphemes of string.
1465
1465
iter ! ( for pattern in string. as_str( ) . graphemes( true ) ) ;
1466
1466
}
1467
1467
( _, Value :: Dict ( dict) ) => {
1468
- // iterate over keys of dict
1468
+ // Iterate over pairs of dict.
1469
1469
iter ! ( for pattern in dict. pairs( ) ) ;
1470
1470
}
1471
1471
( _, Value :: Array ( array) ) => {
1472
- // iterate over values of array and allow destructuring
1473
- iter ! ( for pattern in array. into_iter ( ) ) ;
1472
+ // Iterate over values of array.
1473
+ iter ! ( for pattern in array) ;
1474
1474
}
1475
1475
( ast:: PatternKind :: Ident ( _) , _) => {
1476
1476
bail ! ( self . iter( ) . span( ) , "cannot loop over {}" , iter. type_name( ) ) ;
Original file line number Diff line number Diff line change @@ -853,16 +853,9 @@ fn pattern(p: &mut Parser) -> PatternKind {
853
853
854
854
PatternKind :: Destructuring
855
855
} else {
856
- let success = p. expect ( SyntaxKind :: Ident ) ;
857
- if p. at ( SyntaxKind :: Comma ) {
858
- // TODO: this should only be a warning instead
859
- p. expected ( "keyword `in`. did you mean to use a destructuring pattern?" ) ;
860
- }
861
-
862
- if success {
856
+ if p. expect ( SyntaxKind :: Ident ) {
863
857
p. wrap ( m, SyntaxKind :: Pattern ) ;
864
858
}
865
-
866
859
PatternKind :: Normal
867
860
}
868
861
}
@@ -964,7 +957,13 @@ fn for_loop(p: &mut Parser) {
964
957
let m = p. marker ( ) ;
965
958
p. assert ( SyntaxKind :: For ) ;
966
959
pattern ( p) ;
967
- p. expect ( SyntaxKind :: In ) ;
960
+ if p. at ( SyntaxKind :: Comma ) {
961
+ p. expected ( "keyword `in`. did you mean to use a destructuring pattern?" ) ;
962
+ p. eat_if ( SyntaxKind :: Ident ) ;
963
+ p. eat_if ( SyntaxKind :: In ) ;
964
+ } else {
965
+ p. expect ( SyntaxKind :: In ) ;
966
+ }
968
967
code_expr ( p) ;
969
968
block ( p) ;
970
969
p. wrap ( m, SyntaxKind :: ForLoop ) ;
Original file line number Diff line number Diff line change 93
93
---
94
94
// Destructuring without parentheses.
95
95
// Error: 7 expected keyword `in`. did you mean to use a destructuring pattern?
96
- // Error: 7 expected keyword `in`
97
96
# for k , v in (a: 4, b: 5) {
98
97
dont-care
99
98
}
You can’t perform that action at this time.
0 commit comments