diff options
| author | bors <bors@rust-lang.org> | 2024-03-02 05:03:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-02 05:03:46 +0000 |
| commit | 4cdd20584ccb75890d7d9bfae266054abfae5d46 (patch) | |
| tree | d9b0b65bb0610b950e674720a90c5d5515e3be88 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 1dc5f73c138bc316218c99cda09bcb12bf90e26e (diff) | |
| parent | bde2dfb127a524321d6629607df5f3008921327e (diff) | |
| download | rust-4cdd20584ccb75890d7d9bfae266054abfae5d46.tar.gz rust-4cdd20584ccb75890d7d9bfae266054abfae5d46.zip | |
Auto merge of #121657 - estebank:issue-119665, r=davidtwco
Detect more cases of `=` to `:` typo
When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`.
```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
--> file.rs:2:32
|
2 | let _: std::env::temp_dir().join("foo");
| - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
| |
| while parsing the type for `_`
| help: use `=` if you meant to assign
```
Fix #119665.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 316a9c4f8df..54771cccd75 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -430,7 +430,7 @@ impl<'a> Parser<'a> { /// The method does not advance the current token. /// /// Also performs recovery for `and` / `or` which are mistaken for `&&` and `||` respectively. - fn check_assoc_op(&self) -> Option<Spanned<AssocOp>> { + pub fn check_assoc_op(&self) -> Option<Spanned<AssocOp>> { let (op, span) = match (AssocOp::from_token(&self.token), self.token.ident()) { // When parsing const expressions, stop parsing when encountering `>`. ( @@ -994,7 +994,7 @@ impl<'a> Parser<'a> { } } - fn parse_dot_suffix_expr(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> { + pub fn parse_dot_suffix_expr(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> { match self.token.uninterpolate().kind { token::Ident(..) => self.parse_dot_suffix(base, lo), token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => { |
