diff options
| author | bors <bors@rust-lang.org> | 2022-06-13 23:36:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-13 23:36:51 +0000 |
| commit | 3bdec3c8abdc48e46715d7b14b764af28da1cee3 (patch) | |
| tree | b72fb84b835e64cc9e6de4c5fc71491b96711fb0 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | ca122c7ebb3ab50149c9d3d24ddb59c252b32272 (diff) | |
| parent | aa71be1b39d7b672414c622093e906e81aa06351 (diff) | |
| download | rust-3bdec3c8abdc48e46715d7b14b764af28da1cee3.tar.gz rust-3bdec3c8abdc48e46715d7b14b764af28da1cee3.zip | |
Auto merge of #98075 - JohnTitor:rollup-nqwodnk, r=JohnTitor
Rollup of 4 pull requests Successful merges: - #95211 (Improve parser diagnostics) - #95243 (Add Apple WatchOS compile targets) - #97385 (Add WIP stable MIR crate) - #97508 (Harden bad placeholder checks on statics/consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 236ccef1d03..b224fa9596e 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -980,12 +980,26 @@ impl<'a> Parser<'a> { fn parse_dot_or_call_expr_with_(&mut self, mut e: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> { loop { - if self.eat(&token::Question) { + let has_question = if self.prev_token.kind == TokenKind::Ident(kw::Return, false) { + // we are using noexpect here because we don't expect a `?` directly after a `return` + // which could be suggested otherwise + self.eat_noexpect(&token::Question) + } else { + self.eat(&token::Question) + }; + if has_question { // `expr?` e = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Try(e), AttrVec::new()); continue; } - if self.eat(&token::Dot) { + let has_dot = if self.prev_token.kind == TokenKind::Ident(kw::Return, false) { + // we are using noexpect here because we don't expect a `.` directly after a `return` + // which could be suggested otherwise + self.eat_noexpect(&token::Dot) + } else { + self.eat(&token::Dot) + }; + if has_dot { // expr.f e = self.parse_dot_suffix_expr(lo, e)?; continue; @@ -1541,9 +1555,13 @@ impl<'a> Parser<'a> { self.parse_for_expr(label, lo, attrs) } else if self.eat_keyword(kw::Loop) { self.parse_loop_expr(label, lo, attrs) - } else if self.check(&token::OpenDelim(Delimiter::Brace)) || self.token.is_whole_block() { + } else if self.check_noexpect(&token::OpenDelim(Delimiter::Brace)) + || self.token.is_whole_block() + { self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs) - } else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) { + } else if !ate_colon + && (self.check_noexpect(&TokenKind::Comma) || self.check_noexpect(&TokenKind::Gt)) + { // We're probably inside of a `Path<'a>` that needs a turbofish let msg = "expected `while`, `for`, `loop` or `{` after a label"; self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit(); |
