E0425
Rust Programming Language
Severity: MinorWhat it means
Rust cannot find a variable, function, or constant you referenced.
It is either not declared, out of scope, or named differently.
Check spelling, scope, and whether you need to bring it into scope with use.
Affected Models
- Rust stable
- Rust nightly
- Cargo build
- Rust 2021 edition
Common Causes
- Referencing a variable before it is declared with let
- Using a variable outside the block or function where it was defined
- A typo in the variable or function name
- Forgetting to import a constant or function from another module with use
- A variable shadowed by an inner scope and the outer name is no longer accessible
How to Fix It
-
Check the exact name in the error message and compare it to your declaration.
Rust is case-sensitive. my_value and My_Value are different identifiers.
-
Make sure the variable is declared before the line that uses it.
In Rust, variables must be declared with let before use — unlike some languages that hoist declarations.
-
Check that the variable is in scope — not declared inside a block you are outside of.
A variable declared inside an if block or loop body is not accessible after the closing brace.
-
For functions or constants from other modules, add the correct use statement.
Example: use std::cmp::min; brings the min function into scope.
Without it, calling min() fails. -
If you intended to capture a variable in a closure, pass it explicitly or move it into the closure.
Use move || { ... } to move variables into a closure, or pass them as arguments.
When to Call a Professional
E0425 is always a compile-time error safe to fix yourself.
If it appears in generated code from proc macros, check the macro's documentation for the correct variable names it expects.
Frequently Asked Questions
Why can Rust not find my variable even though I declared it?
The most common reason is scope.
If you declared it inside curly braces, it only lives inside those braces.
Declare it in the outer scope before the block if you need it afterwards.
What does 'cannot find value in this scope' mean for a function name?
The function is either not defined, misspelled, or in a different module.
For standard library functions, check if you need a use statement.
For your own functions, check the module path.
How is Rust's scoping different from other languages?
Rust uses block scoping like C and C++.
Variables exist only within the enclosing set of curly braces.
Unlike JavaScript, Rust has no var hoisting — every variable must be explicitly declared before use.