File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -731,7 +731,7 @@ impl<'a> Parser<'a> {
731731 Applicability :: MaybeIncorrect ,
732732 ) ;
733733 err. emit ( ) ;
734- // self.expected_tokens.clear(); // reduce errors
734+ self . expected_tokens . clear ( ) ; // reduce errors
735735 Ok ( true )
736736 }
737737 _ => Err ( err) ,
@@ -2814,6 +2814,21 @@ impl<'a> Parser<'a> {
28142814 hi = pth. span ;
28152815 ex = ExprKind :: Path ( None , pth) ;
28162816 } else {
2817+ if !self . unclosed_delims . is_empty ( ) && self . check ( & token:: Semi ) {
2818+ // Don't complain about bare semicolons after unclosed braces
2819+ // recovery in order to keep the error count down. Fixing the
2820+ // delimiters will possibly also fix the bare semicolon found in
2821+ // expression context. For example, silence the following error:
2822+ // ```
2823+ // error: expected expression, found `;`
2824+ // --> file.rs:2:13
2825+ // |
2826+ // 2 | foo(bar(;
2827+ // | ^ expected expression
2828+ // ```
2829+ self . bump ( ) ;
2830+ return Ok ( self . mk_expr ( self . span , ExprKind :: Err , ThinVec :: new ( ) ) ) ;
2831+ }
28172832 match self . parse_literal_maybe_minus ( ) {
28182833 Ok ( expr) => {
28192834 hi = expr. span ;
Original file line number Diff line number Diff line change 22
33fn main( ) {
44 foo( bar( ;
5- //~^ ERROR: expected expression, found `;`
5+ //~^ ERROR cannot find function `bar` in this scope
66}
77//~^ ERROR: incorrect close delimiter: `}`
8+
9+ fn foo ( _: usize ) { }
Original file line number Diff line number Diff line change 1- error: expected expression, found `;`
2- --> $DIR/token-error-correct.rs:4:13
3- |
4- LL | foo(bar(;
5- | ^ expected expression
6-
71error: incorrect close delimiter: `}`
82 --> $DIR/token-error-correct.rs:6:1
93 |
104LL | fn main() {
115 | - close delimiter possibly meant for this
126LL | foo(bar(;
137 | - un-closed delimiter
14- LL | //~^ ERROR: expected expression, found `;`
8+ LL | //~^ ERROR cannot find function `bar` in this scope
159LL | }
1610 | ^ incorrect close delimiter
1711
12+ error[E0425]: cannot find function `bar` in this scope
13+ --> $DIR/token-error-correct.rs:4:9
14+ |
15+ LL | foo(bar(;
16+ | ^^^ not found in this scope
17+
1818error: aborting due to 2 previous errors
1919
20+ For more information about this error, try `rustc --explain E0425`.
You can’t perform that action at this time.
0 commit comments