diff options
| author | Zachary Mayhew <mayhew.zachary2003@gmail.com> | 2023-05-04 23:31:04 -0400 |
|---|---|---|
| committer | Zachary Mayhew <mayhew.zachary2003@gmail.com> | 2023-05-05 11:17:14 -0400 |
| commit | a183ac6f90dc43a550a8afa5c01fdc797cf3d1d4 (patch) | |
| tree | b09d978fcc0e25710dfb67feab533cd8b8f254d1 /compiler/rustc_parse/src | |
| parent | 74c4821045c68d42bb8b8a7c998bdb5c2a72bd0d (diff) | |
| download | rust-a183ac6f90dc43a550a8afa5c01fdc797cf3d1d4.tar.gz rust-a183ac6f90dc43a550a8afa5c01fdc797cf3d1d4.zip | |
add hint for =< as <=
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f58f8919e5c..dd1b0ddc025 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1448,8 +1448,19 @@ impl<'a> Parser<'a> { } fn parse_expr_path_start(&mut self) -> PResult<'a, P<Expr>> { + let maybe_eq_tok = self.prev_token.clone(); let (qself, path) = if self.eat_lt() { - let (qself, path) = self.parse_qpath(PathStyle::Expr)?; + let lt_span = self.prev_token.span; + let (qself, path) = self.parse_qpath(PathStyle::Expr).map_err(|mut err| { + // Suggests using '<=' if there is an error parsing qpath when the previous token + // is an '=' token. Only emits suggestion if the '<' token and '=' token are + // directly adjacent (i.e. '=<') + if maybe_eq_tok.kind == TokenKind::Eq && maybe_eq_tok.span.hi() == lt_span.lo() { + let eq_lt = maybe_eq_tok.span.to(lt_span); + err.span_suggestion(eq_lt, "did you mean", "<=", Applicability::Unspecified); + } + err + })?; (Some(qself), path) } else { (None, self.parse_path(PathStyle::Expr)?) |
