Skip to content

Commit

Permalink
Rollup merge of rust-lang#83062 - JohnTitor:improve-reassign-err, r=d…
Browse files Browse the repository at this point in the history
…avidtwco

Improve the wording for the `can't reassign` error

Follow-up for rust-lang#71976 (comment).
Fixes rust-lang#66736
  • Loading branch information
Dylan-DPC authored Mar 14, 2021
2 parents 68422d2 + 0466b6a commit 5f27f0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P<Expr>>> {
let eq_consumed = match self.token.kind {
token::BinOpEq(..) => {
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/parser/let-binop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5f27f0e

Please sign in to comment.