Skip to content

Commit 535282b

Browse files
committed
Cancel an error before it panics
Fixes #30715
1 parent 5253294 commit 535282b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/libsyntax/parse/parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2793,8 +2793,15 @@ impl<'a> Parser<'a> {
27932793
// We have 2 alternatives here: `x..y` and `x..` The other two variants are
27942794
// handled with `parse_prefix_range_expr` call above.
27952795
let rhs = if self.is_at_start_of_range_notation_rhs() {
2796-
self.parse_assoc_expr_with(op.precedence() + 1,
2797-
LhsExpr::NotYetParsed).ok()
2796+
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
2797+
LhsExpr::NotYetParsed);
2798+
match rhs {
2799+
Ok(e) => Some(e),
2800+
Err(mut e) => {
2801+
e.cancel();
2802+
None
2803+
}
2804+
}
27982805
} else {
27992806
None
28002807
};

src/test/compile-fail/issue-30715.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
macro_rules! parallel {
12+
(
13+
for $id:ident in $iter:expr {
14+
$( $inner:expr; )*
15+
}
16+
) => {};
17+
}
18+
19+
20+
fn main() {
21+
parallel! {
22+
for i in 0..n {
23+
x += i; //~ ERROR no rules expected the token `+=`
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)