Closed
Description
As a python programmer, forgetting a let
in an assignment to a variable that didn't exist before is an easy mistake to make.
example code
fn main() {
// forgot the "let" here
horses = ["Secretariat", "Seabiscuit", "Binky"];
println!("I have {} horses.", horses.len());
}
Rust sees two uses of an undefined variable here (E0425 twice):
error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find value `horses` in this scope
--> src/main.rs:3:5
|
3 | horses = ["Secretariat", "Seabiscuit", "Binky"];
| ^^^^^^ not found in this scope
error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find value `horses` in this scope
--> src/main.rs:4:35
|
4 | println!("I have {} horses.", horses.len());
| ^^^^^^ not found in this scope
For more information about this error, try `rustc --explain E0425`.
What I would hope for
While the second one is fine, in the first case I would have really appreciated a sentence like this:
Did you mean to use `let` to introduce a new variable? Try `let horses = ...`
This would helped me as a newcomer to the language, because it does an educated guess what the problem might be and tells me how to fix it.
I think the hint should be added if the value is assigned to (first error), but not if it is used as an argument (second error).
I hope this is the right place and format to file this suggestion, I would appreciate hints if this is not the case.