Skip to content

Commit 6478583

Browse files
committed
Auto merge of #33311 - birkenfeld:issue33262, r=nrc
parser: fix suppression of syntax errors in range RHS Invalid expressions on the RHS were just swallowed without generating an error. The new version more closely mirrors the code for parsing `..x` in the `parse_prefix_range_expr` method below, where no cancel is done either. Fixes #33262.
2 parents c95cda5 + a36fb46 commit 6478583

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/libsyntax/parse/parser.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -3028,15 +3028,8 @@ impl<'a> Parser<'a> {
30283028
// We have 2 alternatives here: `x..y`/`x...y` and `x..`/`x...` The other
30293029
// two variants are handled with `parse_prefix_range_expr` call above.
30303030
let rhs = if self.is_at_start_of_range_notation_rhs() {
3031-
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
3032-
LhsExpr::NotYetParsed);
3033-
match rhs {
3034-
Ok(e) => Some(e),
3035-
Err(mut e) => {
3036-
e.cancel();
3037-
None
3038-
}
3039-
}
3031+
Some(self.parse_assoc_expr_with(op.precedence() + 1,
3032+
LhsExpr::NotYetParsed)?)
30403033
} else {
30413034
None
30423035
};

src/test/parse-fail/issue-33262.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z parse-only
12+
13+
// Issue #33262
14+
15+
pub fn main() {
16+
for i in 0..a as { }
17+
//~^ ERROR expected type, found `{`
18+
}

0 commit comments

Comments
 (0)