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
usefor 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
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
- E0061this function takes N arguments but M were supplied
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0605non-primitive cast
- E0320overflow while adding drop-check rules for `A<T>`
- E0370enum discriminant overflowed
- E0436functional record update syntax requires a struct
- E0455link kind `framework` is only supported on Apple targets
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?