-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve diagnostics for let x += 1
#71976
Changes from all commits
d4fe955
48ff12a
05d6531
6ad24ba
98532a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let a: i8 *= 1; //~ ERROR can't reassign to an uninitialized variable | ||
let _ = a; | ||
let b += 1; //~ ERROR can't reassign to an uninitialized variable | ||
let _ = b; | ||
let c *= 1; //~ ERROR can't reassign to an uninitialized variable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if it's already initialized? let d = 1;
let d += 2; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but one could argue I just initialized it above (same name). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change the wording for initialized variables? Can't reassign to initialized variable, it should only be either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let _ = c; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: can't reassign to an uninitialized variable | ||
--> $DIR/let-binop.rs:2:15 | ||
| | ||
LL | let a: i8 *= 1; | ||
| ^^ help: initialize the variable | ||
|
||
error: can't reassign to an uninitialized variable | ||
--> $DIR/let-binop.rs:4:11 | ||
| | ||
LL | let b += 1; | ||
| ^^ help: initialize the variable | ||
|
||
error: can't reassign to an uninitialized variable | ||
--> $DIR/let-binop.rs:6:11 | ||
| | ||
LL | let c *= 1; | ||
| ^^ help: initialize the variable | ||
|
||
error: aborting due to 3 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.