diff --git a/src/librustc_parse/lexer/tokentrees.rs b/src/librustc_parse/lexer/tokentrees.rs index 6c0acd0302f..b65b8941728 100644 --- a/src/librustc_parse/lexer/tokentrees.rs +++ b/src/librustc_parse/lexer/tokentrees.rs @@ -40,6 +40,7 @@ struct TokenTreesReader<'a> { /// Used only for error recovery when arriving to EOF with mismatched braces. matching_delim_spans: Vec<(token::DelimToken, Span, Span)>, last_unclosed_found_span: Option, + /// Collect empty block spans that might have been auto-inserted by editors. last_delim_empty_block_spans: FxHashMap, } @@ -138,7 +139,11 @@ impl<'a> TokenTreesReader<'a> { if tts.is_empty() { let empty_block_span = open_brace_span.to(close_brace_span); - self.last_delim_empty_block_spans.insert(delim, empty_block_span); + if !sm.is_multiline(empty_block_span) { + // Only track if the block is in the form of `{}`, otherwise it is + // likely that it was written on purpose. + self.last_delim_empty_block_spans.insert(delim, empty_block_span); + } } if self.open_braces.is_empty() { diff --git a/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr b/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr index 311f1768d82..f1be5dc5ba7 100644 --- a/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr +++ b/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr @@ -1,14 +1,8 @@ error: unexpected closing delimiter: `}` --> $DIR/mismatched-delim-brace-empty-block.rs:5:1 | -LL | fn main() { - | ___________- -LL | | -LL | | } - | |_- this block is empty, you might have not meant to close it -LL | let _ = (); -LL | } - | ^ unexpected closing delimiter +LL | } + | ^ unexpected closing delimiter error: aborting due to previous error