diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2021-09-02 18:34:03 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2021-09-03 14:43:04 +0000 |
| commit | 12ce6e9c60c662dc7181b70021145f191c0f9f3e (patch) | |
| tree | 2d25c254eeec0782df8dced3f020e4cff9ef6785 /compiler/rustc_parse/src/parser | |
| parent | fcce644119cf4e8e36001368e514bb5ed67cb855 (diff) | |
| download | rust-12ce6e9c60c662dc7181b70021145f191c0f9f3e.tar.gz rust-12ce6e9c60c662dc7181b70021145f191c0f9f3e.zip | |
Detect bare blocks with type ascription that were meant to be a `struct` literal
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 273fbea3580..59e0feb67c5 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -446,11 +446,13 @@ impl<'a> Parser<'a> { ) .emit(); *self = snapshot; - Ok(self.mk_block( + let mut tail = self.mk_block( vec![self.mk_stmt_err(expr.span)], s, lo.to(self.prev_token.span), - )) + ); + tail.could_be_bare_literal = true; + Ok(tail) } (Err(mut err), Ok(tail)) => { // We have a block tail that contains a somehow valid type ascription expr. @@ -463,7 +465,10 @@ impl<'a> Parser<'a> { self.consume_block(token::Brace, ConsumeClosingDelim::Yes); Err(err) } - (Ok(_), Ok(tail)) => Ok(tail), + (Ok(_), Ok(mut tail)) => { + tail.could_be_bare_literal = true; + Ok(tail) + } }); } None diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 068bd36af55..25dcb4a112d 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -574,7 +574,14 @@ impl<'a> Parser<'a> { } pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> { - P(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None }) + P(Block { + stmts, + id: DUMMY_NODE_ID, + rules, + span, + tokens: None, + could_be_bare_literal: false, + }) } pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt { |
