error[E0425]: cannot find value in this scope
You used a name that doesn’t exist where you used it. Either it’s misspelt, never declared, or declared in a different scope.
Quick fix: Declare the variable in the scope where you use it (often just before a loop or block), or fix the typo.
Code that triggers E0425
fn main() {
for round in 1..=3 {
let total = round * 10;
println!("round {round}: {total}");
}
println!("final total: {total}");
}What the compiler says
error[E0425]: cannot find value `total` in this scope
--> src/main.rs:6:29
|
6 | println!("final total: {total}");
| ^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.Why Rust raises E0425
A variable exists from its let until the closing brace of the block it’s declared in. total is declared inside the loop body, so it’s created and dropped on every iteration and doesn’t exist after the loop.
E0425 also covers plain typos and names that were never declared. When the name is close to an existing one, the compiler adds a help: a local variable with a similar name exists hint.
How to fix E0425
1. Declare it in the scope where you use it
Create total before the loop and update it inside. It needs mut because the loop changes it.
fn main() {
let mut total = 0;
for round in 1..=3 {
total = round * 10;
println!("round {round}: {total}");
}
println!("final total: {total}");
}Related errors
- E0433: failed to resolve: use of undeclared type
- E0603: function, struct or module is private
- E0384: cannot assign twice to immutable variable
Learn the concept behind it
The Ownership: Variable Scope lesson explains the rules behind E0425 with diagrams and more examples. For the official reference, run rustc --explain E0425 or read the E0425 entry in the Rust error index .
Hit a different error? Paste it into the Rust error lookup to find its fix.