From 5b64c796a441a32f6661bef7783637c6d2a3e169 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 23 Jan 2013 20:27:12 -0800 Subject: syntax/rustc: Improve error message for misuse of `for` loop Print out a clearer error message when a `for` gets used with the wrong type of iterator. Also fix spans on `for` loop bodies, and suppress some more derived errors. r=brson Closes #3651 --- src/libsyntax/parse/parser.rs | 76 ++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2b1312f16d9..7183b623ef4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1660,43 +1660,45 @@ impl Parser { // them as the lambda arguments let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP); match e.node { - expr_call(f, args, false) => { - let block = self.parse_lambda_block_expr(); - let last_arg = self.mk_expr(block.span.lo, block.span.hi, - ctor(block)); - let args = vec::append(args, ~[last_arg]); - @expr {node: expr_call(f, args, true), .. *e} - } - expr_method_call(f, i, tps, args, false) => { - let block = self.parse_lambda_block_expr(); - let last_arg = self.mk_expr(block.span.lo, block.span.hi, - ctor(block)); - let args = vec::append(args, ~[last_arg]); - @expr {node: expr_method_call(f, i, tps, args, true), .. *e} - } - expr_field(f, i, tps) => { - let block = self.parse_lambda_block_expr(); - let last_arg = self.mk_expr(block.span.lo, block.span.hi, - ctor(block)); - @expr {node: expr_method_call(f, i, tps, ~[last_arg], true), - .. *e} - } - expr_path(*) | expr_call(*) | expr_method_call(*) | - expr_paren(*) => { - let block = self.parse_lambda_block_expr(); - let last_arg = self.mk_expr(block.span.lo, block.span.hi, - ctor(block)); - self.mk_expr(lo.lo, last_arg.span.hi, - expr_call(e, ~[last_arg], true)) - } - _ => { - // There may be other types of expressions that can - // represent the callee in `for` and `do` expressions - // but they aren't represented by tests - debug!("sugary call on %?", e.node); - self.span_fatal( - lo, fmt!("`%s` must be followed by a block call", keyword)); - } + expr_call(f, args, false) => { + let block = self.parse_lambda_block_expr(); + let last_arg = self.mk_expr(block.span.lo, block.span.hi, + ctor(block)); + let args = vec::append(args, ~[last_arg]); + self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, true)) + } + expr_method_call(f, i, tps, args, false) => { + let block = self.parse_lambda_block_expr(); + let last_arg = self.mk_expr(block.span.lo, block.span.hi, + ctor(block)); + let args = vec::append(args, ~[last_arg]); + self.mk_expr(lo.lo, block.span.hi, + expr_method_call(f, i, tps, args, true)) + } + expr_field(f, i, tps) => { + let block = self.parse_lambda_block_expr(); + let last_arg = self.mk_expr(block.span.lo, block.span.hi, + ctor(block)); + self.mk_expr(lo.lo, block.span.hi, + expr_method_call(f, i, tps, ~[last_arg], true)) + } + expr_path(*) | expr_call(*) | expr_method_call(*) | + expr_paren(*) => { + let block = self.parse_lambda_block_expr(); + let last_arg = self.mk_expr(block.span.lo, block.span.hi, + ctor(block)); + self.mk_expr(lo.lo, last_arg.span.hi, + expr_call(e, ~[last_arg], true)) + } + _ => { + // There may be other types of expressions that can + // represent the callee in `for` and `do` expressions + // but they aren't represented by tests + debug!("sugary call on %?", e.node); + self.span_fatal( + lo, fmt!("`%s` must be followed by a block call", + keyword)); + } } } -- cgit 1.4.1-3-g733a5