@@ -16,7 +16,7 @@ use rustc_ast::{
16
16
} ;
17
17
use rustc_ast:: { Block , BlockCheckMode , Expr , ExprKind , Local , Stmt } ;
18
18
use rustc_ast:: { StmtKind , DUMMY_NODE_ID } ;
19
- use rustc_errors:: { Applicability , PResult } ;
19
+ use rustc_errors:: { Applicability , DiagnosticBuilder , PResult } ;
20
20
use rustc_span:: source_map:: { BytePos , Span } ;
21
21
use rustc_span:: symbol:: { kw, sym} ;
22
22
@@ -300,6 +300,12 @@ impl<'a> Parser<'a> {
300
300
None => LocalKind :: Decl ,
301
301
Some ( init) => {
302
302
if self . eat_keyword ( kw:: Else ) {
303
+ if self . token . is_keyword ( kw:: If ) {
304
+ // `let...else if`. Emit the same error that `parse_block()` would,
305
+ // but explicitly point out that this pattern is not allowed.
306
+ let msg = "conditional `else if` is not supported for `let...else`" ;
307
+ return Err ( self . error_block_no_opening_brace_msg ( msg) ) ;
308
+ }
303
309
let els = self . parse_block ( ) ?;
304
310
self . check_let_else_init_bool_expr ( & init) ;
305
311
self . check_let_else_init_trailing_brace ( & init) ;
@@ -392,10 +398,9 @@ impl<'a> Parser<'a> {
392
398
Ok ( block)
393
399
}
394
400
395
- fn error_block_no_opening_brace < T > ( & mut self ) -> PResult < ' a , T > {
401
+ fn error_block_no_opening_brace_msg ( & mut self , msg : & str ) -> DiagnosticBuilder < ' a > {
396
402
let sp = self . token . span ;
397
- let tok = super :: token_descr ( & self . token ) ;
398
- let mut e = self . struct_span_err ( sp, & format ! ( "expected `{{`, found {}" , tok) ) ;
403
+ let mut e = self . struct_span_err ( sp, msg) ;
399
404
let do_not_suggest_help = self . token . is_keyword ( kw:: In ) || self . token == token:: Colon ;
400
405
401
406
// Check to see if the user has written something like
@@ -435,7 +440,13 @@ impl<'a> Parser<'a> {
435
440
_ => { }
436
441
}
437
442
e. span_label ( sp, "expected `{`" ) ;
438
- Err ( e)
443
+ e
444
+ }
445
+
446
+ fn error_block_no_opening_brace < T > ( & mut self ) -> PResult < ' a , T > {
447
+ let tok = super :: token_descr ( & self . token ) ;
448
+ let msg = format ! ( "expected `{{`, found {}" , tok) ;
449
+ Err ( self . error_block_no_opening_brace_msg ( & msg) )
439
450
}
440
451
441
452
/// Parses a block. Inner attributes are allowed.
0 commit comments