Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 4 additions & 62 deletions compiler/rustc_error_codes/src/error_codes/E0412.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,6 @@
A used type name is not in scope.
This error code is no longer emitted by the compiler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add note on the top is good enough, see E0001.md for an example.


Erroneous code examples:
Unresolved types are now reported under the unified error code E0425
("cannot find ... in this scope").

```compile_fail,E0412
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:

```compile_fail,E0412
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) {}
}
# fn main() {} // don't insert it for us; that'll break imports
```
See the explanation for E0425 for guidance on common causes and fixes.
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl PathSource<'_, '_, '_> {
(PathSource::Trait(_), true) => E0404,
(PathSource::Trait(_), false) => E0405,
(PathSource::Type | PathSource::DefineOpaques, true) => E0573,
(PathSource::Type | PathSource::DefineOpaques, false) => E0412,
(PathSource::Type | PathSource::DefineOpaques, false) => E0425,
(PathSource::Struct(_), true) => E0574,
(PathSource::Struct(_), false) => E0422,
(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
Expand Down Expand Up @@ -3158,7 +3158,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
result
}

/// When evaluating a `trait` use its associated types' idents for suggestions in E0412.
/// When evaluating a `trait` use its associated types' idents for suggestions in E0425.
fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
let trait_assoc_items =
replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
Expand Down Expand Up @@ -4342,15 +4342,15 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

// There are two different error messages user might receive at
// this point:
// - E0412 cannot find type `{}` in this scope
// - E0425 cannot find `{}` in this scope
// - E0433 failed to resolve: use of undeclared type or module `{}`
//
// The first one is emitted for paths in type-position, and the
// latter one - for paths in expression-position.
//
// Thus (since we're in expression-position at this point), not to
// confuse the user, we want to keep the *message* from E0433 (so
// `parent_err`), but we want *hints* from E0412 (so `err`).
// `parent_err`), but we want *hints* from the unified E0425 (so `err`).
Copy link
Contributor

@mu001999 mu001999 Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just E0425 here

//
// And that's what happens below - we're just mixing both messages
// into a single one.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if !enum_candidates.is_empty() {
enum_candidates.sort();

// Contextualize for E0412 "cannot find type", but don't belabor the point
// Contextualize for E0425 "cannot find type", but don't belabor the point
// (that it's a variant) for E0573 "expected type, found variant".
let preamble = if res.is_none() {
let others = match enum_candidates.len() {
Expand Down Expand Up @@ -1125,7 +1125,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
}
}
} else if err_code == E0412 {
// cannot find type in this scope
if let Some(correct) = Self::likely_rust_type(path) {
err.span_suggestion(
span,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `PhantomData` in this scope
error[E0425]: cannot find type `PhantomData` in this scope
--> tests/ui/crashes/ice-6252.rs:9:9
|
LL | _n: PhantomData,
Expand All @@ -9,7 +9,7 @@ help: consider importing this struct
LL + use std::marker::PhantomData;
|

error[E0412]: cannot find type `VAL` in this scope
error[E0425]: cannot find type `VAL` in this scope
--> tests/ui/crashes/ice-6252.rs:12:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
Expand All @@ -31,5 +31,5 @@ LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0046, E0412.
Some errors have detailed explanations: E0046, E0425.
For more information about an error, try `rustc --explain E0046`.
10 changes: 5 additions & 5 deletions tests/rustdoc-ui/impl-fn-nesting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0405]: cannot find trait `UnknownBound` in this scope
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0425]: cannot find type `UnknownType` in this scope
--> $DIR/impl-fn-nesting.rs:11:30
|
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
Expand All @@ -34,7 +34,7 @@ error[E0405]: cannot find trait `UnknownBound` in this scope
LL | impl<T: UnknownBound> UnknownTrait for T {}
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0425]: cannot find type `UnknownType` in this scope
--> $DIR/impl-fn-nesting.rs:18:25
|
LL | impl ValidTrait for UnknownType {}
Expand All @@ -46,19 +46,19 @@ error[E0405]: cannot find trait `UnknownBound` in this scope
LL | impl ValidTrait for ValidType where ValidTrait: UnknownBound {}
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0425]: cannot find type `UnknownType` in this scope
--> $DIR/impl-fn-nesting.rs:25:21
|
LL | type Item = UnknownType;
| ^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0425]: cannot find type `UnknownType` in this scope
--> $DIR/impl-fn-nesting.rs:44:37
|
LL | pub fn doubly_nested(c: UnknownType) {
| ^^^^^^^^^^^ not found in this scope

error: aborting due to 10 previous errors

Some errors have detailed explanations: E0405, E0412.
Some errors have detailed explanations: E0405, E0425.
For more information about an error, try `rustc --explain E0405`.
4 changes: 2 additions & 2 deletions tests/ui/annotate-snippet/missing-type.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `Iter` in this scope
error[E0425]: cannot find type `Iter` in this scope
--> $DIR/missing-type.rs:4:12
|
LL | let x: Iter;
Expand All @@ -18,4 +18,4 @@ LL + use std::collections::hash_map::Iter;

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
4 changes: 2 additions & 2 deletions tests/ui/argument-suggestions/extern-fn-arg-names.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `err` in this scope
error[E0425]: cannot find type `err` in this scope
--> $DIR/extern-fn-arg-names.rs:2:29
|
LL | fn dstfn(src: i32, dst: err);
Expand All @@ -22,5 +22,5 @@ LL | dstfn(1, /* dst */);

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0061, E0412.
Some errors have detailed explanations: E0061, E0425.
For more information about an error, try `rustc --explain E0061`.
2 changes: 1 addition & 1 deletion tests/ui/argument-suggestions/issue-109831.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
struct A;
struct B;

fn f(b1: B, b2: B, a2: C) {} //~ ERROR E0412
fn f(b1: B, b2: B, a2: C) {} //~ ERROR E0425

fn main() {
f(A, A, B, C); //~ ERROR E0425
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/argument-suggestions/issue-109831.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `C` in this scope
error[E0425]: cannot find type `C` in this scope
--> $DIR/issue-109831.rs:4:24
|
LL | struct A;
Expand Down Expand Up @@ -48,5 +48,5 @@ LL + f(/* B */, /* B */, B);

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0061, E0412, E0425.
Some errors have detailed explanations: E0061, E0425.
For more information about an error, try `rustc --explain E0061`.
2 changes: 1 addition & 1 deletion tests/ui/asm/issue-113788.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
//@ needs-asm-support
//@ only-x86_64
fn main() {
let peb: *const PEB; //~ ERROR cannot find type `PEB` in this scope [E0412]
let peb: *const PEB; //~ ERROR cannot find type `PEB` in this scope [E0425]
unsafe { std::arch::asm!("mov {0}, fs:[0x30]", out(reg) peb); }
}
4 changes: 2 additions & 2 deletions tests/ui/asm/issue-113788.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0412]: cannot find type `PEB` in this scope
error[E0425]: cannot find type `PEB` in this scope
--> $DIR/issue-113788.rs:5:21
|
LL | let peb: *const PEB;
| ^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
4 changes: 2 additions & 2 deletions tests/ui/associated-consts/issue-93835.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0425]: cannot find value `p` in this scope
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

error[E0412]: cannot find type `a` in this scope
error[E0425]: cannot find type `a` in this scope
--> $DIR/issue-93835.rs:4:22
|
LL | type_ascribe!(p, a<p:p<e=6>>);
Expand Down Expand Up @@ -39,5 +39,5 @@ LL | type_ascribe!(p, a<p:p<e=6>>);

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0405, E0412, E0425, E0658.
Some errors have detailed explanations: E0405, E0425, E0658.
For more information about an error, try `rustc --explain E0405`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error[E0576]: cannot find function `method` in this scope
LL | method(..): Send,
| ^^^^^^ not found in this scope

error[E0412]: cannot find type `method` in this scope
error[E0425]: cannot find type `method` in this scope
--> $DIR/not-a-method.rs:36:5
|
LL | method(): Send,
Expand All @@ -36,5 +36,5 @@ LL | method(..): Send,

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0412, E0573, E0575, E0576.
For more information about an error, try `rustc --explain E0412`.
Some errors have detailed explanations: E0425, E0573, E0575, E0576.
For more information about an error, try `rustc --explain E0425`.
4 changes: 2 additions & 2 deletions tests/ui/associated-types/associated-types-eq-1.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `A` in this scope
error[E0425]: cannot find type `A` in this scope
--> $DIR/associated-types-eq-1.rs:10:12
|
LL | fn foo2<I: Foo>(x: I) {
Expand All @@ -18,4 +18,4 @@ LL | fn foo2<I: Foo, A>(x: I) {

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
2 changes: 1 addition & 1 deletion tests/ui/async-await/in-trait/return-not-existing-pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

trait MyTrait<'a, 'b, T> {
async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
//~^ ERROR: cannot find type `ConnImpl` in this scope [E0412]
//~^ ERROR: cannot find type `ConnImpl` in this scope [E0425]
}

impl<'a, 'b, T, U> MyTrait<T> for U {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/in-trait/return-not-existing-pair.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ help: indicate the anonymous lifetimes
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
| +++++++

error[E0412]: cannot find type `ConnImpl` in this scope
error[E0425]: cannot find type `ConnImpl` in this scope
--> $DIR/return-not-existing-pair.rs:5:48
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
Expand All @@ -26,5 +26,5 @@ LL | async fn foo(_: T) -> (&'a U, &'b T) {}

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0412, E0726.
Some errors have detailed explanations: E0308, E0425, E0726.
For more information about an error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Wrapper<T>(T);

trait Foo {
fn bar() -> Wrapper<Missing<impl Sized>>;
//~^ ERROR: cannot find type `Missing` in this scope [E0412]
//~^ ERROR: cannot find type `Missing` in this scope [E0425]
}

impl Foo for () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
error[E0425]: cannot find type `Missing` in this scope
--> $DIR/return-not-existing-type-wrapping-rpitit.rs:7:25
|
LL | fn bar() -> Wrapper<Missing<impl Sized>>;
| ^^^^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
6 changes: 3 additions & 3 deletions tests/ui/async-await/issue-72590-type-error-sized.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0412]: cannot find type `Nonexistent` in this scope
error[E0425]: cannot find type `Nonexistent` in this scope
--> $DIR/issue-72590-type-error-sized.rs:6:10
|
LL | foo: Nonexistent,
| ^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `Missing` in this scope
error[E0425]: cannot find type `Missing` in this scope
--> $DIR/issue-72590-type-error-sized.rs:11:11
|
LL | test: Missing
Expand All @@ -30,5 +30,5 @@ LL | async fn frob(&self) {}

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0412.
Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.
4 changes: 2 additions & 2 deletions tests/ui/async-await/unconstrained-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
error[E0425]: cannot find type `Missing` in this scope
--> $DIR/unconstrained-lifetimes.rs:6:17
|
LL | async fn foo(_: Missing<'_>) {}
| ^^^^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
4 changes: 2 additions & 2 deletions tests/ui/borrowck/bad-drop-side-effects.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
error[E0425]: cannot find type `Missing` in this scope
--> $DIR/bad-drop-side-effects.rs:7:16
|
LL | impl<U> B for &Missing {
| ^^^^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
For more information about this error, try `rustc --explain E0425`.
Loading
Loading