Skip to content

Commit b6e4b0f

Browse files
committed
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; | ~ ```
1 parent 16b5690 commit b6e4b0f

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

compiler/rustc_parse/src/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,8 @@ pub(crate) struct RemoveLet {
660660
#[diag(parse_use_eq_instead)]
661661
pub(crate) struct UseEqInstead {
662662
#[primary_span]
663+
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "=")]
663664
pub span: Span,
664-
#[suggestion(style = "verbose", applicability = "machine-applicable", code = "")]
665-
pub suggestion: Span,
666665
}
667666

668667
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/diagnostics.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,7 @@ impl<'a> Parser<'a> {
566566
&& expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Eq)))
567567
{
568568
// Likely typo: `=` → `==` in let expr or enum item
569-
return Err(self.dcx().create_err(UseEqInstead {
570-
span: self.token.span,
571-
suggestion: self.token.span.with_lo(self.token.span.lo() + BytePos(1)),
572-
}));
569+
return Err(self.dcx().create_err(UseEqInstead { span: self.token.span }));
573570
}
574571

575572
if self.token.is_keyword(kw::Move) && self.prev_token.is_keyword(kw::Async) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const A: usize2;
2+
//~^ ERROR unknown start of token: \u{2a75}
3+
//~| ERROR unexpected `==`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: unknown start of token: \u{2a75}
2+
--> $DIR/unicode-double-equals-recovery.rs:1:16
3+
|
4+
LL | const A: usize ⩵ 2;
5+
| ^
6+
|
7+
help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not
8+
|
9+
LL | const A: usize == 2;
10+
| ~~
11+
12+
error: unexpected `==`
13+
--> $DIR/unicode-double-equals-recovery.rs:1:16
14+
|
15+
LL | const A: usize ⩵ 2;
16+
| ^
17+
|
18+
help: try using `=` instead
19+
|
20+
LL | const A: usize = 2;
21+
| ~
22+
23+
error: aborting due to 2 previous errors
24+

0 commit comments

Comments
 (0)