fix rust-lang#101880: suggest let for assignment, and some code refactor

This commit is contained in:
yukang 2022-09-17 06:46:46 +08:00
parent dcb3761150
commit eb68e27e4c
6 changed files with 165 additions and 53 deletions

View file

@ -0,0 +1,17 @@
// run-rustfix
fn main() {
let demo = 1; //~ ERROR cannot find value `demo` in this scope
dbg!(demo); //~ ERROR cannot find value `demo` in this scope
let x = "x"; //~ ERROR cannot find value `x` in this scope
println!("x: {}", x); //~ ERROR cannot find value `x` in this scope
if x == "x" {
//~^ ERROR cannot find value `x` in this scope
println!("x is 1");
}
let y = 1 + 2; //~ ERROR cannot find value `y` in this scope
println!("y: {}", y); //~ ERROR cannot find value `y` in this scope
}

View file

@ -0,0 +1,17 @@
// run-rustfix
fn main() {
demo = 1; //~ ERROR cannot find value `demo` in this scope
dbg!(demo); //~ ERROR cannot find value `demo` in this scope
x = "x"; //~ ERROR cannot find value `x` in this scope
println!("x: {}", x); //~ ERROR cannot find value `x` in this scope
if x == "x" {
//~^ ERROR cannot find value `x` in this scope
println!("x is 1");
}
y = 1 + 2; //~ ERROR cannot find value `y` in this scope
println!("y: {}", y); //~ ERROR cannot find value `y` in this scope
}

View file

@ -0,0 +1,60 @@
error[E0425]: cannot find value `demo` in this scope
--> $DIR/suggest-let-for-assignment.rs:4:5
|
LL | demo = 1;
| ^^^^
|
help: you might have meant to introduce a new binding
|
LL | let demo = 1;
| +++
error[E0425]: cannot find value `demo` in this scope
--> $DIR/suggest-let-for-assignment.rs:5:10
|
LL | dbg!(demo);
| ^^^^ not found in this scope
error[E0425]: cannot find value `x` in this scope
--> $DIR/suggest-let-for-assignment.rs:7:5
|
LL | x = "x";
| ^
|
help: you might have meant to introduce a new binding
|
LL | let x = "x";
| +++
error[E0425]: cannot find value `x` in this scope
--> $DIR/suggest-let-for-assignment.rs:8:23
|
LL | println!("x: {}", x);
| ^ not found in this scope
error[E0425]: cannot find value `x` in this scope
--> $DIR/suggest-let-for-assignment.rs:10:8
|
LL | if x == "x" {
| ^ not found in this scope
error[E0425]: cannot find value `y` in this scope
--> $DIR/suggest-let-for-assignment.rs:15:5
|
LL | y = 1 + 2;
| ^
|
help: you might have meant to introduce a new binding
|
LL | let y = 1 + 2;
| +++
error[E0425]: cannot find value `y` in this scope
--> $DIR/suggest-let-for-assignment.rs:16:23
|
LL | println!("y: {}", y);
| ^ not found in this scope
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0425`.