diff options
| author | bors <bors@rust-lang.org> | 2021-09-04 01:40:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-04 01:40:36 +0000 |
| commit | b4e8596e3e78395543747ebaba26b49f6a478aa8 (patch) | |
| tree | c782e430605f5b820e4c4aaa448493bf706eccd2 /compiler/rustc_parse/src/parser | |
| parent | 03c775c95596cbd92f2b1e8ca98e7addfa3eade2 (diff) | |
| parent | 12ce6e9c60c662dc7181b70021145f191c0f9f3e (diff) | |
| download | rust-b4e8596e3e78395543747ebaba26b49f6a478aa8.tar.gz rust-b4e8596e3e78395543747ebaba26b49f6a478aa8.zip | |
Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiser
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 cdc1d1cf99f..94ca70d3f95 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 { |
