Skip to content

Commit 6ad24ba

Browse files
committed
Adjust according to estebank's review comments
1 parent 05d6531 commit 6ad24ba

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

src/librustc_parse/parser/stmt.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ impl<'a> Parser<'a> {
174174
} else {
175175
(None, None)
176176
};
177-
let init = match (self.parse_initializer(let_span, ty.is_some(), err.is_some()), err) {
177+
let init = match (
178+
self.parse_initializer(let_span.until(pat.span), ty.is_some(), err.is_some()),
179+
err,
180+
) {
178181
(Ok(init), None) => {
179182
// init parsed, ty parsed
180183
init
@@ -231,25 +234,19 @@ impl<'a> Parser<'a> {
231234
self.sess.span_diagnostic,
232235
self.token.span,
233236
E0067,
234-
"can't reassign to a uninitialized variable"
237+
"can't reassign to an uninitialized variable"
235238
);
236239
err.span_suggestion_short(
237240
self.token.span,
238-
"replace with `=` to initialize the variable",
241+
"initialize the variable",
239242
"=".to_string(),
240-
if has_ty {
241-
// for `let x: i8 += 1` it's highly likely that the `+` is a typo
242-
Applicability::MachineApplicable
243-
} else {
244-
// for `let x += 1` it's a bit less likely that the `+` is a typo
245-
Applicability::MaybeIncorrect
246-
},
243+
Applicability::MaybeIncorrect,
247244
);
248245
// In case of code like `let x += 1` it's possible the user may have meant to write `x += 1`
249246
if !has_ty {
250247
err.span_suggestion_short(
251248
let_span,
252-
"remove to reassign to a previously initialized variable",
249+
"otherwise, reassign to a previously initialized variable",
253250
"".to_string(),
254251
Applicability::MaybeIncorrect,
255252
);

src/test/ui/parser/let-binop-plus.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
fn main() {
44
let a: i8 += 1;
55
//~^ ERROR expected trait, found builtin type `i8`
6-
//~| ERROR can't reassign to a uninitialized variable
6+
//~| ERROR can't reassign to an uninitialized variable
77
let _ = a;
88
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0067]: can't reassign to a uninitialized variable
1+
error[E0067]: can't reassign to an uninitialized variable
22
--> $DIR/let-binop-plus.rs:4:16
33
|
44
LL | let a: i8 += 1;
5-
| ^ help: replace with `=` to initialize the variable
5+
| ^ help: initialize the variable
66

77
error[E0404]: expected trait, found builtin type `i8`
88
--> $DIR/let-binop-plus.rs:4:12

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
2-
let a: i8 *= 1; //~ ERROR can't reassign to a uninitialized variable
2+
let a: i8 *= 1; //~ ERROR can't reassign to an uninitialized variable
33
let _ = a;
4-
let b += 1; //~ ERROR can't reassign to a uninitialized variable
4+
let b += 1; //~ ERROR can't reassign to an uninitialized variable
55
let _ = b;
6-
let c *= 1; //~ ERROR can't reassign to a uninitialized variable
6+
let c *= 1; //~ ERROR can't reassign to an uninitialized variable
77
let _ = c;
88
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
error[E0067]: can't reassign to a uninitialized variable
1+
error[E0067]: can't reassign to an uninitialized variable
22
--> $DIR/let-binop.rs:2:15
33
|
44
LL | let a: i8 *= 1;
5-
| ^^ help: replace with `=` to initialize the variable
5+
| ^^ help: initialize the variable
66

7-
error[E0067]: can't reassign to a uninitialized variable
7+
error[E0067]: can't reassign to an uninitialized variable
88
--> $DIR/let-binop.rs:4:11
99
|
1010
LL | let b += 1;
1111
| ^^
1212
|
13-
help: replace with `=` to initialize the variable
13+
help: initialize the variable
1414
|
1515
LL | let b = 1;
1616
| ^
17-
help: remove to reassign to a previously initialized variable
17+
help: otherwise, reassign to a previously initialized variable
1818
|
19-
LL | b += 1;
19+
LL | b += 1;
2020
| --
2121

22-
error[E0067]: can't reassign to a uninitialized variable
22+
error[E0067]: can't reassign to an uninitialized variable
2323
--> $DIR/let-binop.rs:6:11
2424
|
2525
LL | let c *= 1;
2626
| ^^
2727
|
28-
help: replace with `=` to initialize the variable
28+
help: initialize the variable
2929
|
3030
LL | let c = 1;
3131
| ^
32-
help: remove to reassign to a previously initialized variable
32+
help: otherwise, reassign to a previously initialized variable
3333
|
34-
LL | c *= 1;
34+
LL | c *= 1;
3535
| --
3636

3737
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)