Fix ICE in suggestion caused by being recovered as ==

The second suggestion shown here would previously incorrectly assume that the span corresponding to `⩵` was 2 bytes wide composed by 2 1 byte wide chars, so a span pointing at `==` could point only at one of the `=` to remove it. Instead, we now replace the whole thing (as we should have the whole time):

```
error: unknown start of token: \u{2a75}
  --> $DIR/unicode-double-equals-recovery.rs:1:16
   |
LL | const A: usize ⩵ 2;
   |                ^
   |
help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not
   |
LL | const A: usize == 2;
   |                ~~

error: unexpected `==`
  --> $DIR/unicode-double-equals-recovery.rs:1:16
   |
LL | const A: usize ⩵ 2;
   |                ^
   |
help: try using `=` instead
   |
LL | const A: usize = 2;
   |                ~
```
This commit is contained in:
Esteban Küber 2024-07-16 22:43:30 +00:00
parent e35364a521
commit 67ec1326ee
6 changed files with 33 additions and 12 deletions

View file

@ -660,9 +660,8 @@ pub(crate) struct RemoveLet {
#[diag(parse_use_eq_instead)]
pub(crate) struct UseEqInstead {
#[primary_span]
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "=")]
pub span: Span,
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "")]
pub suggestion: Span,
}
#[derive(Diagnostic)]