From 0466b6ac6d2af6e9aa6cdcdde18acbf2a5056944 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 13 Mar 2021 05:56:30 +0900 Subject: [PATCH] Improve the wording for the `can't reassign` error --- compiler/rustc_parse/src/parser/stmt.rs | 3 ++- src/test/ui/parser/let-binop.stderr | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index f6599927c6e6d..92e67e7929180 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -291,7 +291,7 @@ impl<'a> Parser<'a> { Ok(P(ast::Local { ty, pat, init, id: DUMMY_NODE_ID, span: lo.to(hi), attrs, tokens: None })) } - /// Parses the RHS of a local variable declaration (e.g., '= 14;'). + /// Parses the RHS of a local variable declaration (e.g., `= 14;`). fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option>> { let eq_consumed = match self.token.kind { token::BinOpEq(..) => { @@ -306,6 +306,7 @@ impl<'a> Parser<'a> { "=".to_string(), Applicability::MaybeIncorrect, ) + .help("if you meant to overwrite, remove the `let` binding") .emit(); self.bump(); true diff --git a/src/test/ui/parser/let-binop.stderr b/src/test/ui/parser/let-binop.stderr index 90295854a2d2d..dd33e9157cfd5 100644 --- a/src/test/ui/parser/let-binop.stderr +++ b/src/test/ui/parser/let-binop.stderr @@ -3,18 +3,24 @@ error: can't reassign to an uninitialized variable | LL | let a: i8 *= 1; | ^^ help: initialize the variable + | + = help: if you meant to overwrite, remove the `let` binding error: can't reassign to an uninitialized variable --> $DIR/let-binop.rs:6:11 | LL | let b += 1; | ^^ help: initialize the variable + | + = help: if you meant to overwrite, remove the `let` binding error: can't reassign to an uninitialized variable --> $DIR/let-binop.rs:8:11 | LL | let c *= 1; | ^^ help: initialize the variable + | + = help: if you meant to overwrite, remove the `let` binding error: aborting due to 3 previous errors