diff options
| author | bors <bors@rust-lang.org> | 2017-12-22 07:22:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-22 07:22:33 +0000 |
| commit | c2ecab112131b10894f2930b7b152cfcbdda43e9 (patch) | |
| tree | b8e21a041a6f767db4fca384cd011ba1bd9e28f4 /src/libsyntax | |
| parent | ba2741594ba2d4de2ad8cea69def6408ff5409af (diff) | |
| parent | d90d5d19da1126c5e66ede7d23bcfd8e18601a8a (diff) | |
| download | rust-c2ecab112131b10894f2930b7b152cfcbdda43e9.tar.gz rust-c2ecab112131b10894f2930b7b152cfcbdda43e9.zip | |
Auto merge of #46732 - estebank:silence-recovered-blocks, r=petrochenkov
Do not emit type errors on recovered blocks When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user. Fix #44579.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 7 |
5 files changed, 10 insertions, 3 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 77ce6b7c3ca..e0f14c04c6c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -493,6 +493,7 @@ pub struct Block { /// Distinguishes between `unsafe { ... }` and `{ ... }` pub rules: BlockCheckMode, pub span: Span, + pub recovered: bool, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 0b3272fc1db..34e5610901e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -594,6 +594,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, rules: BlockCheckMode::Default, span, + recovered: false, }) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d1aef0c5042..9916b74aeb3 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -864,11 +864,12 @@ fn noop_fold_bounds<T: Folder>(bounds: TyParamBounds, folder: &mut T) } pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> { - b.map(|Block {id, stmts, rules, span}| Block { + b.map(|Block {id, stmts, rules, span, recovered}| Block { id: folder.new_id(id), stmts: stmts.move_flat_map(|s| folder.fold_stmt(s).into_iter()), rules, span: folder.new_span(span), + recovered, }) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 17bccfc2d0f..a38ceba2f45 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -930,6 +930,7 @@ mod tests { id: ast::DUMMY_NODE_ID, rules: ast::BlockCheckMode::Default, // no idea span: sp(15,21), + recovered: false, })), vis: ast::Visibility::Inherited, span: sp(0,21)}))); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f81421460c7..a4aad81f5f5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4372,13 +4372,15 @@ impl<'a> Parser<'a> { /// Precondition: already parsed the '{'. fn parse_block_tail(&mut self, lo: Span, s: BlockCheckMode) -> PResult<'a, P<Block>> { let mut stmts = vec![]; + let mut recovered = false; while !self.eat(&token::CloseDelim(token::Brace)) { let stmt = match self.parse_full_stmt(false) { Err(mut err) => { err.emit(); - self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Break); + self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); self.eat(&token::CloseDelim(token::Brace)); + recovered = true; break; } Ok(stmt) => stmt, @@ -4397,12 +4399,13 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, rules: s, span: lo.to(self.prev_span), + recovered, })) } /// Parse a statement, including the trailing semicolon. pub fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> { - let mut stmt = match self.parse_stmt_(macro_legacy_warnings) { + let mut stmt = match self.parse_stmt_without_recovery(macro_legacy_warnings)? { Some(stmt) => stmt, None => return Ok(None), }; |
