Skip to content

Commit

Permalink
Trim whitespace in RemoveLet primary span
Browse files Browse the repository at this point in the history
Separate `RemoveLet` span into primary span for `let` and removal
suggestion span for `let `, so that primary span does not include
whitespace.

Fixes: rust-lang#133031

Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
  • Loading branch information
tyrone-wu committed Nov 15, 2024
1 parent c82e0df commit bba1236
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,9 @@ pub(crate) struct LeftArrowOperator {
#[diag(parse_remove_let)]
pub(crate) struct RemoveLet {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
self.bump();
// Trim extra space after the `let`
let span = lo.with_hi(self.token.span.lo());
self.dcx().emit_err(RemoveLet { span });
self.dcx().emit_err(RemoveLet { span: lo, suggestion: span });
lo = self.token.span;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/unnecessary-let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:2:9
|
LL | for let x of [1, 2, 3] {}
| ^^^^
| ^^^
|
help: remove the unnecessary `let` keyword
|
Expand All @@ -25,7 +25,7 @@ error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:7:9
|
LL | let 1 => {}
| ^^^^
| ^^^
|
help: remove the unnecessary `let` keyword
|
Expand Down

0 comments on commit bba1236

Please sign in to comment.