diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-23 20:27:12 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-24 11:04:54 -0800 |
| commit | 5b64c796a441a32f6661bef7783637c6d2a3e169 (patch) | |
| tree | a61bbfdf1ce72b0bc2d833f56e1bfd4ca5fe3e46 /src/libsyntax/parse/parser.rs | |
| parent | e8f4da78e78238d7a24dc452302a4c1f113f0e2a (diff) | |
| download | rust-5b64c796a441a32f6661bef7783637c6d2a3e169.tar.gz rust-5b64c796a441a32f6661bef7783637c6d2a3e169.zip | |
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
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 76 |
1 files changed, 39 insertions, 37 deletions
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)); + } } } |
