Adjust according to estebank's review comments

This commit is contained in:
mibac138 2020-05-07 23:45:51 +02:00
parent 05d6531998
commit 6ad24baf06
5 changed files with 24 additions and 27 deletions

View File

@ -174,7 +174,10 @@ impl<'a> Parser<'a> {
} else { } else {
(None, None) (None, None)
}; };
let init = match (self.parse_initializer(let_span, ty.is_some(), err.is_some()), err) { let init = match (
self.parse_initializer(let_span.until(pat.span), ty.is_some(), err.is_some()),
err,
) {
(Ok(init), None) => { (Ok(init), None) => {
// init parsed, ty parsed // init parsed, ty parsed
init init
@ -231,25 +234,19 @@ impl<'a> Parser<'a> {
self.sess.span_diagnostic, self.sess.span_diagnostic,
self.token.span, self.token.span,
E0067, E0067,
"can't reassign to a uninitialized variable" "can't reassign to an uninitialized variable"
); );
err.span_suggestion_short( err.span_suggestion_short(
self.token.span, self.token.span,
"replace with `=` to initialize the variable", "initialize the variable",
"=".to_string(), "=".to_string(),
if has_ty { Applicability::MaybeIncorrect,
// for `let x: i8 += 1` it's highly likely that the `+` is a typo
Applicability::MachineApplicable
} else {
// for `let x += 1` it's a bit less likely that the `+` is a typo
Applicability::MaybeIncorrect
},
); );
// In case of code like `let x += 1` it's possible the user may have meant to write `x += 1` // In case of code like `let x += 1` it's possible the user may have meant to write `x += 1`
if !has_ty { if !has_ty {
err.span_suggestion_short( err.span_suggestion_short(
let_span, let_span,
"remove to reassign to a previously initialized variable", "otherwise, reassign to a previously initialized variable",
"".to_string(), "".to_string(),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );

View File

@ -3,6 +3,6 @@
fn main() { fn main() {
let a: i8 += 1; let a: i8 += 1;
//~^ ERROR expected trait, found builtin type `i8` //~^ ERROR expected trait, found builtin type `i8`
//~| ERROR can't reassign to a uninitialized variable //~| ERROR can't reassign to an uninitialized variable
let _ = a; let _ = a;
} }

View File

@ -1,8 +1,8 @@
error[E0067]: can't reassign to a uninitialized variable error[E0067]: can't reassign to an uninitialized variable
--> $DIR/let-binop-plus.rs:4:16 --> $DIR/let-binop-plus.rs:4:16
| |
LL | let a: i8 += 1; LL | let a: i8 += 1;
| ^ help: replace with `=` to initialize the variable | ^ help: initialize the variable
error[E0404]: expected trait, found builtin type `i8` error[E0404]: expected trait, found builtin type `i8`
--> $DIR/let-binop-plus.rs:4:12 --> $DIR/let-binop-plus.rs:4:12

View File

@ -1,8 +1,8 @@
fn main() { fn main() {
let a: i8 *= 1; //~ ERROR can't reassign to a uninitialized variable let a: i8 *= 1; //~ ERROR can't reassign to an uninitialized variable
let _ = a; let _ = a;
let b += 1; //~ ERROR can't reassign to a uninitialized variable let b += 1; //~ ERROR can't reassign to an uninitialized variable
let _ = b; let _ = b;
let c *= 1; //~ ERROR can't reassign to a uninitialized variable let c *= 1; //~ ERROR can't reassign to an uninitialized variable
let _ = c; let _ = c;
} }

View File

@ -1,37 +1,37 @@
error[E0067]: can't reassign to a uninitialized variable error[E0067]: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:2:15 --> $DIR/let-binop.rs:2:15
| |
LL | let a: i8 *= 1; LL | let a: i8 *= 1;
| ^^ help: replace with `=` to initialize the variable | ^^ help: initialize the variable
error[E0067]: can't reassign to a uninitialized variable error[E0067]: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:4:11 --> $DIR/let-binop.rs:4:11
| |
LL | let b += 1; LL | let b += 1;
| ^^ | ^^
| |
help: replace with `=` to initialize the variable help: initialize the variable
| |
LL | let b = 1; LL | let b = 1;
| ^ | ^
help: remove to reassign to a previously initialized variable help: otherwise, reassign to a previously initialized variable
| |
LL | b += 1; LL | b += 1;
| -- | --
error[E0067]: can't reassign to a uninitialized variable error[E0067]: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:6:11 --> $DIR/let-binop.rs:6:11
| |
LL | let c *= 1; LL | let c *= 1;
| ^^ | ^^
| |
help: replace with `=` to initialize the variable help: initialize the variable
| |
LL | let c = 1; LL | let c = 1;
| ^ | ^
help: remove to reassign to a previously initialized variable help: otherwise, reassign to a previously initialized variable
| |
LL | c *= 1; LL | c *= 1;
| -- | --
error: aborting due to 3 previous errors error: aborting due to 3 previous errors