mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
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.
This commit is contained in:
@@ -930,6 +930,7 @@ fn parser_done(p: Parser){
|
||||
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)})));
|
||||
|
||||
@@ -4372,13 +4372,15 @@ fn parse_inner_attrs_and_block(&mut self) -> PResult<'a, (Vec<Attribute>, P<Bloc
|
||||
/// 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 @@ fn parse_block_tail(&mut self, lo: Span, s: BlockCheckMode) -> PResult<'a, P<Blo
|
||||
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),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user