Skip to content

Commit d6eaea1

Browse files
committed
Auto merge of rust-lang#83062 - JohnTitor:improve-reassign-err, r=davidtwco
Improve the wording for the `can't reassign` error Follow-up for rust-lang#71976 (comment). Fixes rust-lang#66736
2 parents bb4cdf8 + 0466b6a commit d6eaea1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/rustc_parse/src/parser/stmt.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a> Parser<'a> {
291291
Ok(P(ast::Local { ty, pat, init, id: DUMMY_NODE_ID, span: lo.to(hi), attrs, tokens: None }))
292292
}
293293

294-
/// Parses the RHS of a local variable declaration (e.g., '= 14;').
294+
/// Parses the RHS of a local variable declaration (e.g., `= 14;`).
295295
fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> {
296296
let eq_consumed = match self.token.kind {
297297
token::BinOpEq(..) => {
@@ -306,6 +306,7 @@ impl<'a> Parser<'a> {
306306
"=".to_string(),
307307
Applicability::MaybeIncorrect,
308308
)
309+
.help("if you meant to overwrite, remove the `let` binding")
309310
.emit();
310311
self.bump();
311312
true

src/test/ui/parser/let-binop.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ error: can't reassign to an uninitialized variable
33
|
44
LL | let a: i8 *= 1;
55
| ^^ help: initialize the variable
6+
|
7+
= help: if you meant to overwrite, remove the `let` binding
68

79
error: can't reassign to an uninitialized variable
810
--> $DIR/let-binop.rs:6:11
911
|
1012
LL | let b += 1;
1113
| ^^ help: initialize the variable
14+
|
15+
= help: if you meant to overwrite, remove the `let` binding
1216

1317
error: can't reassign to an uninitialized variable
1418
--> $DIR/let-binop.rs:8:11
1519
|
1620
LL | let c *= 1;
1721
| ^^ help: initialize the variable
22+
|
23+
= help: if you meant to overwrite, remove the `let` binding
1824

1925
error: aborting due to 3 previous errors
2026

0 commit comments

Comments
 (0)