E0425 Cannot Find Value Fix
The name in the code and a name the compiler can see are not the same name at that point - because of a spelling difference, because the declaration has not happened yet, because the block that declared it has ended, or because the item lives in a module and was never brought into scope. This guide separates four shapes that produce E0425 and matches each one to the repair the diagnostic itself points at.
Written November 23, 2026 · Tested with Rust 1.99.0 · 17 min read
- The rule underneath: a name is valid only inside its scope, from its declaration
- How to read the diagnostic
- The first failure: a misspelled name, with a similar name in scope
- The second failure: a name used before its declaration
Written November 23, 2026
Tested with Rust 1.99.0
What this guide is
Error E0425 is an unresolved name. The error codes index states the cause in one line: an unresolved name was used. Its advice is to verify that the name was not misspelled and to ensure that the identifier being referred to is valid for the given situation, and it adds that if the item is not defined in the current module, it must be imported using a use statement.
The four forms in this guide each reproduce E0425 with a small, complete program, and each fails for a different reason. A variable name spelled one letter short, with a similar name in scope. A name used on the line before its let. A name declared inside an if block and used after that block ends. And a function defined inside a module, called by its bare name with no path and no import. In each family the failing program is small, the full compiler output is shown, and the fix makes the used name and a visible name the same name at that point - by correcting the spelling, by ordering the declaration first, by declaring in the outer scope, or by naming the path.
Two neighboring codes are not E0425 and are not in the families. Reassigning an immutable variable is E0384, and a private module or function reached by a correct path is E0603: in both, the name resolves and a different rule is what fails. E0425 is only about resolution - whether any item with that name is visible where the name is used.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: a name is valid only inside its scope, from its declaration
A scope is the range within a program for which an item is valid. The Rust Book chapter on ownership works the scope example with a variable that is not valid before its declaration, is valid from that point forward, and is no longer valid once its scope is over: when a name comes into scope it is valid, and it remains valid until it goes out of scope. A block - a pair of curly brackets, such as a function body or an if body - is such a scope, so a name declared inside a block ends at that block's closing bracket, even when the surrounding function continues.
Order inside the scope matters as well as the scope itself. A let binds a name from that statement onward; a use written above the let stands at a point where the binding does not exist yet, and shadowing follows the same rule: the Rust Book chapter on variables and mutability describes the second variable as the one the compiler will see when the name is used, in effect until it is itself shadowed or the scope ends. Names are also exact: spelling and letter case are part of the name, so a use that differs from the declaration in either is a different, unresolved name - which is why the compiler can offer the declared spelling as a suggestion, as the first family shows.
Items in modules follow the same visibility rule through paths. To call a function, the caller needs to know its path: the Rust Book chapter on paths states that a path shows Rust where to find an item in the module tree, in the same way a path is used when navigating a filesystem, and that a path is an absolute path starting from the crate root or a relative path starting from the current module. The error index gives the other route to the same end: import the item with a use statement, which brings its name into the current scope so the bare name resolves. If the item is not defined in some super-module of the current module, the index adds, it must also be declared public, with pub.
So every E0425 repair has the same shape: at the point of use, make the name resolve - to the binding that was meant, declared earlier and in a scope that is still open, or to the module item, named by its path or brought in by use. No type, value, or ownership rule changes; only the name's visibility changes.
How to read the diagnostic
The header names the missing name and the kind of item the compiler took it for: "cannot find value" for a name used as a value, and "cannot find function" for a name used as a call. The caret span marks the exact use that did not resolve, and where the line carries no further label, the name was not found in this scope at all.
Read the help line next, because it separates the families. "A local variable with a similar name exists" means a declared name is close to the used name - a spelling or case difference. "The binding is available in a different scope in the same function" means the name was declared, but in a block that has ended, and the note points back to that declaration. "Consider importing this function" means the item exists in a module and can be brought into scope. "You might have meant to introduce a new binding" means an assignment used a name that was never declared with let. A use before its declaration carries no help line at all in this guide's family: there is no similar name and no other scope to point at, and the repair is the ordering itself.
The first failure: a misspelled name, with a similar name in scope
The declaration spells the name total_score; the print uses total_scor, one letter short. That shorter name was never declared anywhere, so it does not resolve - and because a close name does exist, the compiler names it and shows the missing letter:
fn main() {
let total_score = 42;
println!("{}", total_scor);
}
$ rustc --edition 2021 fail_typo.rs -o fail_typo
error[E0425]: cannot find value `total_scor` in this scope
--> fail_typo.rs:3:20
|
3 | println!("{}", total_scor);
| ^^^^^^^^^^
|
help: a local variable with a similar name exists
|
3 | println!("{}", total_score);
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
The header and the caret span identify the unresolved name, and the help rewrites the line with the declared spelling, marking the added letter with a +. Follow it exactly:
fn main() {
let total_score = 42;
println!("{}", total_score);
}
$ rustc --edition 2021 fix_typo.rs -o fix_typo
$ ./fix_typo
42
The output is the value the failing program was trying to print: 42, the value bound to total_score. The fix is one character because the defect was one character - the binding, its value, and its scope were all already correct.
The second failure: a name used before its declaration
Here the spelling is exact and the scope is right, but the use stands above the let. At the print line, count has not been bound yet, so there is no name to resolve:
fn main() {
println!("{}", count);
let count = 3;
}
$ rustc --edition 2021 fail_before.rs -o fail_before
error[E0425]: cannot find value `count` in this scope
--> fail_before.rs:2:20
|
2 | println!("{}", count);
| ^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
This diagnostic carries no help line: there is no similar name to offer and no other scope holding the binding. The note under the caret says only that the name is not found in this scope. Move the declaration above the use:
fn main() {
let count = 3;
println!("{}", count);
}
$ rustc --edition 2021 fix_before.rs -o fix_before
$ ./fix_before
3
The output is the value the failing program was trying to print: 3. Declaration order is part of resolution, not a style rule - a let makes its name valid from that point forward, and a use before that point is a use of a name that does not exist yet, however correct the later declaration is.
The third failure: a name declared inside a block, used after the block ends
bonus is declared inside the if block, and that block is its scope. The print inside the block resolves; the print after the closing bracket stands in a scope where bonus no longer exists:
fn main() {
let ready = true;
if ready {
let bonus = 10;
println!("inside {}", bonus);
}
println!("outside {}", bonus);
}
$ rustc --edition 2021 fail_scope.rs -o fail_scope
error[E0425]: cannot find value `bonus` in this scope
--> fail_scope.rs:7:28
|
7 | println!("outside {}", bonus);
| ^^^^^
|
help: the binding `bonus` is available in a different scope in the same function
--> fail_scope.rs:4:13
|
4 | let bonus = 10;
| ^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
The help is specific to this shape: the binding is available in a different scope in the same function, and the note points back to the declaration inside the block. The repair is to declare the name in the scope that uses it. Because an if is an expression, the block can produce the value for an outer declaration instead of holding the declaration inside itself:
fn main() {
let ready = true;
let bonus = if ready { 10 } else { 0 };
println!("outside {}", bonus);
}
$ rustc --edition 2021 fix_scope.rs -o fix_scope
$ ./fix_scope
outside 10
The output is the line the failing program was trying to print after the block: outside 10. The value is the same 10 the inner branch chose; what changed is where the name lives. Declaring with let bonus; before the block and assigning inside it repairs the same shape the same way - the binding sits in the outer scope either way.
The fourth failure: a function in a module, called by its bare name
total_with_tax exists and is public, but it is defined inside the module billing. A bare call in main looks for a function of that name in the current scope, where no such name has been brought in:
mod billing {
pub fn total_with_tax(amount: i32) -> i32 {
amount + 5
}
}
fn main() {
println!("{}", total_with_tax(50));
}
$ rustc --edition 2021 fail_fn.rs -o fail_fn
error[E0425]: cannot find function `total_with_tax` in this scope
--> fail_fn.rs:8:20
|
8 | println!("{}", total_with_tax(50));
| ^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this function
|
1 + use crate::billing::total_with_tax;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
The header says "cannot find function", the wording for a call, and the help offers the import route, writing the use line to add at the top of the file. The other route states the path at the call site, as the paths chapter describes - the module name, followed by ::, followed by the function name:
mod billing {
pub fn total_with_tax(amount: i32) -> i32 {
amount + 5
}
}
fn main() {
println!("{}", billing::total_with_tax(50));
}
$ rustc --edition 2021 fix_fn.rs -o fix_fn
$ ./fix_fn
55
The output is the value the failing program was trying to print: 55, the 50 passed in plus the 5 the function adds. Either repair resolves the same name: the path names the item where it lives, and a use crate::billing::total_with_tax; at the top of the file brings the name into scope so the original bare call compiles unchanged. The function also has to be public for code outside its module to name it at all - here it is declared pub, and without that the failure would be a privacy error on a resolved path, not E0425.
The fixes in reach order
- The help names a similar local variable: correct the use to the declared spelling, character for character, including letter case.
- The use stands above the
let: move the declaration above the first use, or move the use below the declaration. - The help says the binding is available in a different scope: declare the name in the outer scope - let the block return the value to an outer
let, or declare before the block and assign inside it. - The header says "cannot find function" and the help offers an import: call the item by its path (
billing::total_with_tax(50)), or add theuseline the help writes out. - An assignment names a variable that was never declared: add
letto introduce the binding, as the traps section shows. - Inside a method, a bare name that matches a field of the struct: write it through
self, as the traps section shows.
Traps
- Letter case alone makes a different name. The declaration is
total, the use isTotal, and the compiler treats the capitalized name as a name that does not exist - then offers the declared spelling as the similar name, showing the whole line rewritten:
fn main() {
let total = 7;
println!("{}", Total);
}
$ rustc --edition 2021 probe_case.rs -o probe_case
error[E0425]: cannot find value `Total` in this scope
--> probe_case.rs:3:20
|
3 | println!("{}", Total);
| ^^^^^
|
help: a local variable with a similar name exists
|
3 - println!("{}", Total);
3 + println!("{}", total);
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
fn main() {
let total = 7;
println!("{}", total);
}
$ rustc --edition 2021 fix_case.rs -o fix_case
$ ./fix_case
7
let, the assignment is a use of an existing name, and there is none:fn main() {
count = 3;
}
$ rustc --edition 2021 probe_no_let.rs -o probe_no_let
error[E0425]: cannot find value `count` in this scope
--> probe_no_let.rs:2:5
|
2 | count = 3;
| ^^^^^
|
help: you might have meant to introduce a new binding
|
2 | let count = 3;
| +++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
The help states the repair in its own wording: "you might have meant to introduce a new binding", and it rewrites the line with let added. Follow it, and the declared name can then be used normally:
fn main() {
let count = 3;
println!("{}", count);
}
$ rustc --edition 2021 fix_no_let.rs -o fix_no_let
$ ./fix_no_let
3
The output is 3. Note what this shape is not: assigning a second time to a declared immutable variable is a different error, E0384 - there the name resolves and mutability is the failing rule. - Inside a method, a field name on its own does not resolve. A struct's fields are not local variables of its methods, so the bare field name fails even though the field exists:
struct Counter {
count: i32,
}
impl Counter {
fn show(&self) {
println!("{}", count);
}
}
fn main() {
let c = Counter { count: 9 };
c.show();
}
$ rustc --edition 2021 probe_self_field.rs -o probe_self_field
error[E0425]: cannot find value `count` in this scope
--> probe_self_field.rs:7:24
|
7 | println!("{}", count);
| ^^^^^
|
help: you might have meant to use the available field
|
7 | println!("{}", self.count);
| +++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
The help names the shape directly - "you might have meant to use the available field" - and rewrites the use with self. in front of it:
struct Counter {
count: i32,
}
impl Counter {
fn show(&self) {
println!("{}", self.count);
}
}
fn main() {
let c = Counter { count: 9 };
c.show();
}
$ rustc --edition 2021 fix_self_field.rs -o fix_self_field
$ ./fix_self_field
9
The output is 9, the field value of the Counter that main built. The field was never missing; it is reached through the receiver, not by its bare name.
- A shadowed name returning after an inner block is not E0425 - it is the scope rule working in the other direction. The inner let x shadows the outer one inside the block only, and when that scope ends the outer binding is what the name sees again:
fn main() {
let x = 5;
let x = x + 1;
{
let x = x * 2;
println!("inner {}", x);
}
println!("outer {}", x);
}
$ rustc --edition 2021 probe_shadow_scope.rs -o probe_shadow_scope
$ ./probe_shadow_scope
inner 12
outer 6
The output is the pair of lines: the inner value 12 inside the block, then the outer value 6 after it. No repair is needed, and the contrast is the diagnostic point: a name declared in an inner block is gone after the block, while a name declared outside and only shadowed inside is still there.
Decision summary
- The help says a local variable with a similar name exists: the use is misspelled or differs in case - correct it to the declared spelling.
- The diagnostic has no help line and the declaration is present below the use: the use is too early - move the
letabove it. - The help says the binding is available in a different scope in the same function: the declaration sits inside a block that has ended - declare the name in the scope that uses it.
- The header says "cannot find function" and the help offers an import: the item lives in a module - call it by its path or add the
use. - The help says "you might have meant to introduce a new binding": an assignment used an undeclared name - add
let. - The help says "you might have meant to use the available field": a bare field name inside a method - write
self.and the field name. - The report is E0384 or E0603 instead: the name resolved - E0384 is reassignment of an immutable binding, and E0603 is a private item on a resolved path - and neither is repaired by making a name visible.
Checklist
- The unresolved name in the header compared character for character with its intended declaration, including letter case.
- The declaration checked to stand above the first use.
- The declaration checked to sit in a scope that is still open at the use - not inside a block, loop, or branch that has already ended.
- A name from another module checked for a path at the call site or a
usethat brings it into scope, and forpubon the item where the caller is outside its module. - An assigned name checked to have been introduced with
let. - A field name inside a method written through
self. - The fixed program run, and its output checked against what the failing program was trying to compute.
Related guides on this site
- Fix Rust E0515 "cannot return value referencing local variable" — a Local String, a Local Number, a Local Vec Slice, and a Struct Wrapping a Local
- E0503 Cannot Use Fix
- E0509 Cannot Move Out Fix
- E0505 Cannot Move Out Fix
Sources
- Rust, Error codes index: E0425 - the definition of the error: an unresolved name was used; verify that the name was not misspelled and ensure that the identifier being referred to is valid for the given situation; an item not defined in the current module must be imported using a
usestatement, and if the item being imported is not defined in some super-module of the current module, it must also be declared public. - The Rust Programming Language, What is Ownership? - scope as the range within a program for which an item is valid: a variable is valid from the point at which it is declared until the end of the current scope, and when a variable goes out of scope its value is dropped.
- The Rust Programming Language, Variables and Mutability - shadowing: a shadowed variable is overshadowed by the second variable, which is what the compiler will see when the name is used, until it is itself shadowed or the scope ends.
- The Rust Programming Language, Paths for Referring to an Item in the Module Tree - to call a function the caller needs to know its path; a path shows Rust where to find an item in the module tree, and takes an absolute form starting from the crate root or a relative form starting from the current module, with identifiers separated by double colons.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.