Email me

Rust errors / Everything else

Rust compiler error · checked with rustc 1.99.0

Rust error E0412: cannot find type in this scope

What it meansA type name is used that is not declared or imported here.

Retired: rustc no longer emits this error code. You may still see it in old answers, books and CI logs from older toolchains; the explanation below is kept for reference.

Why it happens

  • A missing use for a type from another module or crate.
  • A typo in the type name, or a generic parameter not declared in <T>.

How to fix it

1. Import or declare it

use std::path::PathBuf;
fn open<T: AsRef<std::path::Path>>(p: T) {}

Other wordings of this error

cannot find type in this scope, not found in this scope

E0412Everything else
Retiredin rustc 1.99.0
8related errors linked below

The compiler team's explanation

Note: this error code is no longer emitted by the compiler.

Erroneous code examples:

impl Something {} // error: type name `Something` is not in scope

// or:

trait Foo {
    fn bar(N); // error: type name `N` is not in scope
}

// or:

fn foo(x: T) {} // type name `T` is not in scope

To fix this error, please verify you didn't misspell the type name, you did declare it or imported it into the scope. Examples:

struct Something;

impl Something {} // ok!

// or:

trait Foo {
    type N;

    fn bar(_: Self::N); // ok!
}

// or:

fn foo<T>(x: T) {} // ok!

Another case that causes this error is when a type is imported into a parent module. To fix this, you can follow the suggestion and use File directly or use super::File; which will import the types from the parent namespace. An example that causes this error is below:

use std::fs::File;

mod foo {
    fn some_function(f: File) {}
}
use std::fs::File;

mod foo {
    // either
    use super::File;
    // or
    // use std::fs::File;
    fn foo(f: File) {}
}

From rustc --explain E0412 (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 nextE0061: this function takes N arguments but M were suppliedA 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