Improve the wording for the can't reassign
error
This commit is contained in:
parent
b3e19a221e
commit
0466b6ac6d
2 changed files with 8 additions and 1 deletions
|
@ -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 }))
|
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>>> {
|
fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> {
|
||||||
let eq_consumed = match self.token.kind {
|
let eq_consumed = match self.token.kind {
|
||||||
token::BinOpEq(..) => {
|
token::BinOpEq(..) => {
|
||||||
|
@ -306,6 +306,7 @@ impl<'a> Parser<'a> {
|
||||||
"=".to_string(),
|
"=".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
|
.help("if you meant to overwrite, remove the `let` binding")
|
||||||
.emit();
|
.emit();
|
||||||
self.bump();
|
self.bump();
|
||||||
true
|
true
|
||||||
|
|
|
@ -3,18 +3,24 @@ error: can't reassign to an uninitialized variable
|
||||||
|
|
|
|
||||||
LL | let a: i8 *= 1;
|
LL | let a: i8 *= 1;
|
||||||
| ^^ help: initialize the variable
|
| ^^ help: initialize the variable
|
||||||
|
|
|
||||||
|
= help: if you meant to overwrite, remove the `let` binding
|
||||||
|
|
||||||
error: can't reassign to an uninitialized variable
|
error: can't reassign to an uninitialized variable
|
||||||
--> $DIR/let-binop.rs:6:11
|
--> $DIR/let-binop.rs:6:11
|
||||||
|
|
|
|
||||||
LL | let b += 1;
|
LL | let b += 1;
|
||||||
| ^^ help: initialize the variable
|
| ^^ help: initialize the variable
|
||||||
|
|
|
||||||
|
= help: if you meant to overwrite, remove the `let` binding
|
||||||
|
|
||||||
error: can't reassign to an uninitialized variable
|
error: can't reassign to an uninitialized variable
|
||||||
--> $DIR/let-binop.rs:8:11
|
--> $DIR/let-binop.rs:8:11
|
||||||
|
|
|
|
||||||
LL | let c *= 1;
|
LL | let c *= 1;
|
||||||
| ^^ help: initialize the variable
|
| ^^ help: initialize the variable
|
||||||
|
|
|
||||||
|
= help: if you meant to overwrite, remove the `let` binding
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue