diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2024-11-13 13:17:01 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2024-11-13 13:19:13 +0000 |
| commit | 1136bbf0668d84d2b4b09b772e33fd8532994f83 (patch) | |
| tree | 53b23ccae5adc91c10bdc942113aafde6e4498bd | |
| parent | 65b3877488ccfef3b1a903bfdd269559c59b957c (diff) | |
| download | rust-1136bbf0668d84d2b4b09b772e33fd8532994f83.tar.gz rust-1136bbf0668d84d2b4b09b772e33fd8532994f83.zip | |
Trim extra space when suggesting removing bad `let`
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 4 | ||||
| -rw-r--r-- | tests/ui/parser/unnecessary-let.stderr | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 7f114013320..3546e5b0f04 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -683,7 +683,9 @@ impl<'a> Parser<'a> { }) { self.bump(); - self.dcx().emit_err(RemoveLet { span: lo }); + // Trim extra space after the `let` + let span = lo.with_hi(self.token.span.lo()); + self.dcx().emit_err(RemoveLet { span }); lo = self.token.span; } diff --git a/tests/ui/parser/unnecessary-let.stderr b/tests/ui/parser/unnecessary-let.stderr index c6ac0d562f8..05ac1faafd4 100644 --- a/tests/ui/parser/unnecessary-let.stderr +++ b/tests/ui/parser/unnecessary-let.stderr @@ -2,12 +2,12 @@ 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 | LL - for let x of [1, 2, 3] {} -LL + for x of [1, 2, 3] {} +LL + for x of [1, 2, 3] {} | error: missing `in` in `for` loop @@ -25,12 +25,12 @@ error: expected pattern, found `let` --> $DIR/unnecessary-let.rs:7:9 | LL | let 1 => {} - | ^^^ + | ^^^^ | help: remove the unnecessary `let` keyword | LL - let 1 => {} -LL + 1 => {} +LL + 1 => {} | error: aborting due to 3 previous errors |
