Skip to content

Commit 9720424

Browse files
committed
Fix duplicate error message for destructuring
1 parent 58e4bdb commit 9720424

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/eval/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,16 +1461,16 @@ impl Eval for ast::ForLoop {
14611461

14621462
match (pattern.kind(), iter.clone()) {
14631463
(ast::PatternKind::Ident(_), Value::Str(string)) => {
1464-
// iterate over characters of string
1464+
// Iterate over graphemes of string.
14651465
iter!(for pattern in string.as_str().graphemes(true));
14661466
}
14671467
(_, Value::Dict(dict)) => {
1468-
// iterate over keys of dict
1468+
// Iterate over pairs of dict.
14691469
iter!(for pattern in dict.pairs());
14701470
}
14711471
(_, 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);
14741474
}
14751475
(ast::PatternKind::Ident(_), _) => {
14761476
bail!(self.iter().span(), "cannot loop over {}", iter.type_name());

src/syntax/parser.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -853,16 +853,9 @@ fn pattern(p: &mut Parser) -> PatternKind {
853853

854854
PatternKind::Destructuring
855855
} 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) {
863857
p.wrap(m, SyntaxKind::Pattern);
864858
}
865-
866859
PatternKind::Normal
867860
}
868861
}
@@ -964,7 +957,13 @@ fn for_loop(p: &mut Parser) {
964957
let m = p.marker();
965958
p.assert(SyntaxKind::For);
966959
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+
}
968967
code_expr(p);
969968
block(p);
970969
p.wrap(m, SyntaxKind::ForLoop);

tests/typ/compiler/for.typ

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
---
9494
// Destructuring without parentheses.
9595
// Error: 7 expected keyword `in`. did you mean to use a destructuring pattern?
96-
// Error: 7 expected keyword `in`
9796
#for k, v in (a: 4, b: 5) {
9897
dont-care
9998
}

0 commit comments

Comments
 (0)