Skip to content

Commit 92520a9

Browse files
committed
tests: add regression test for rust-lang#128845
For codepoint boundary assertion triggered by a let stmt compound assignment removal suggestion when encountering recovered multi-byte compound ops. Issue: <rust-lang#128845>
1 parent fac7753 commit 92520a9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Previously we would try to issue a suggestion for `let x <op>= 1`, i.e. a compound assignment
2+
//! within a `let` binding, to remove the `<op>`. The suggestion code unfortunately incorrectly
3+
//! assumed that the `<op>` is an exactly-1-byte ASCII character, but this assumption is incorrect
4+
//! because we also recover Unicode-confusables like `➖=` as `-=`. In this example, the suggestion
5+
//! code used a `+ BytePos(1)` to calculate the span of the `<op>` codepoint that looks like `-` but
6+
//! the mult-byte Unicode look-alike would cause the suggested removal span to be inside a
7+
//! multi-byte codepoint boundary, triggering a codepoint boundary assertion.
8+
//!
9+
//! issue: rust-lang/rust#128845
10+
11+
fn main() {
12+
// Adapted from #128845 but with irrelevant components removed and simplified.
13+
let x ➖= 1;
14+
//~^ ERROR unknown start of token: \u{2796}
15+
//~| ERROR: can't reassign to an uninitialized variable
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: unknown start of token: \u{2796}
2+
--> $DIR/suggest-remove-compount-assign-let-ice.rs:13:11
3+
|
4+
LL | let x ➖= 1;
5+
| ^^
6+
|
7+
help: Unicode character '➖' (Heavy Minus Sign) looks like '-' (Minus/Hyphen), but it is not
8+
|
9+
LL | let x -= 1;
10+
| ~
11+
12+
error: can't reassign to an uninitialized variable
13+
--> $DIR/suggest-remove-compount-assign-let-ice.rs:13:11
14+
|
15+
LL | let x ➖= 1;
16+
| ^^^
17+
|
18+
= help: if you meant to overwrite, remove the `let` binding
19+
help: initialize the variable
20+
|
21+
LL - let x ➖= 1;
22+
LL + let x = 1;
23+
|
24+
25+
error: aborting due to 2 previous errors
26+

0 commit comments

Comments
 (0)