Email me

Rust errors / Names, paths and imports

Rust compiler error · checked with rustc 1.99.0

Rust error E0425: cannot find value in this scope

What it meansA name is used that does not exist where it is used: a typo, a variable from another scope, a missing import, or self outside a method.

What rustc prints

error[E0425]: cannot find value `unknown_variable` in this scope
  --> main.rs:16:9
   |
16 | let x = unknown_variable;  // error: unresolved name `unknown_variable`
   |         ^^^^^^^^^^^^^^^^ not found in this scope

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

Why it happens

  • A typo, or a variable declared inside a block and used after it.
  • A function from another module without a use.
  • Using self or a field name inside an associated function that has no self parameter.

How to fix it

1. Import it

Bring the item into scope.

use crate::utils::parse_line;

2. Declare it in the outer scope

Move the let up so it lives long enough.

let total;
{
    total = compute();
}
println!("{total}");

Other wordings of this error

cannot find value in this scope, cannot find function in this scope, not found in this scope

E0425Names, paths and imports
Activein rustc 1.99.0
7related errors linked below

The compiler team's explanation

An unresolved name was used.

Erroneous code examples:

something_that_doesnt_exist::foo;
// error: unresolved name `something_that_doesnt_exist::foo`

// or:

trait Foo {
    fn bar() {
        Self; // error: unresolved name `Self`
    }
}

// or:

let x = unknown_variable;  // error: unresolved name `unknown_variable`

Please verify that the name wasn't misspelled and ensure that the identifier being referred to is valid for the given situation. Example:

enum something_that_does_exist {
    Foo,
}

Or:

mod something_that_does_exist {
    pub static foo : i32 = 0i32;
}

something_that_does_exist::foo; // ok!

Or:

let unknown_variable = 12u32;
let x = unknown_variable; // ok!

If the item is not defined in the current module, it must be imported using a use statement, like so:

use foo::bar;
bar();

If the item you are importing is not defined in some super-module of the current module, then it must also be declared as public (e.g., pub fn).

From rustc --explain E0425 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0603: is privateA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ