Skip to content

Commit b87101e

Browse files
authored
Unrolled build for rust-lang#127835
Rollup merge of rust-lang#127835 - estebank:issue-127823, r=compiler-errors 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; | ~ ``` Fix rust-lang#127823.
2 parents 5affbb1 + 67ec132 commit b87101e

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
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) {

tests/ui/parser/issues/issue-101477-enum.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ LL | B == 2
77
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
88
help: try using `=` instead
99
|
10-
LL - B == 2
11-
LL + B = 2
12-
|
10+
LL | B = 2
11+
| ~
1312

1413
error: expected item, found `==`
1514
--> $DIR/issue-101477-enum.rs:6:7

tests/ui/parser/issues/issue-101477-let.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ LL | let x == 2;
66
|
77
help: try using `=` instead
88
|
9-
LL - let x == 2;
10-
LL + let x = 2;
11-
|
9+
LL | let x = 2;
10+
| ~
1211

1312
error: aborting due to 1 previous error
1413

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)