Skip to content

Commit c627e1c

Browse files
committed
Merge redundant error codes E0412 and E0425
E0412 ("type name is not in scope") and E0425 ("unresolved name") convey essentially the same information to users - that an identifier cannot be found in the current scope. The only difference was that E0412 was used for type positions while E0425 was used for value/ expression positions. This distinction was not meaningful to users. This commit merges E0412 into E0425, making E0425 the unified error code for all unresolved name errors regardless of position. Changes made: - Updated error code mapping in rustc_resolve to use E0425 for both type and expression positions - Updated diagnostic handling code and comments to reflect the merge - Marked E0412 documentation as no longer emitted, noting it has been merged into E0425 - Enhanced E0425 documentation to include type resolution examples - Updated all test files and expected outputs to use E0425 instead of E0412
1 parent ab67c37 commit c627e1c

File tree

200 files changed

+545
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+545
-524
lines changed

compiler/rustc_error_codes/src/error_codes/E0412.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
3+
This error has been merged into E0425.
4+
15
A used type name is not in scope.
26

37
Erroneous code examples:
48

5-
```compile_fail,E0412
9+
```compile_fail,E0425
610
impl Something {} // error: type name `Something` is not in scope
711
812
// or:
@@ -42,7 +46,7 @@ module. To fix this, you can follow the suggestion and use File directly or
4246
`use super::File;` which will import the types from the parent namespace. An
4347
example that causes this error is below:
4448

45-
```compile_fail,E0412
49+
```compile_fail,E0425
4650
use std::fs::File;
4751
4852
mod foo {

compiler/rustc_error_codes/src/error_codes/E0425.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ trait Foo {
1717
// or:
1818
1919
let x = unknown_variable; // error: unresolved name `unknown_variable`
20+
21+
// or:
22+
23+
impl Something {} // error: type name `Something` is not in scope
24+
25+
// or:
26+
27+
fn foo(x: T) {} // error: type name `T` is not in scope
2028
```
2129

2230
Please verify that the name wasn't misspelled and ensure that the
@@ -45,6 +53,18 @@ let unknown_variable = 12u32;
4553
let x = unknown_variable; // ok!
4654
```
4755

56+
Or for types:
57+
58+
```
59+
struct Something;
60+
61+
impl Something {} // ok!
62+
63+
// or:
64+
65+
fn foo<T>(x: T) {} // ok!
66+
```
67+
4868
If the item is not defined in the current module, it must be imported using a
4969
`use` statement, like so:
5070

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ E0805: 0805,
607607
// E0246, // invalid recursive type
608608
// E0247,
609609
// E0248, // value used as a type, now reported earlier during resolution
610-
// // as E0412
610+
// // as E0425
611611
// E0249,
612612
// E0257,
613613
// E0258,

compiler/rustc_resolve/src/late.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl PathSource<'_, '_, '_> {
622622
(PathSource::Trait(_), true) => E0404,
623623
(PathSource::Trait(_), false) => E0405,
624624
(PathSource::Type | PathSource::DefineOpaques, true) => E0573,
625-
(PathSource::Type | PathSource::DefineOpaques, false) => E0412,
625+
(PathSource::Type | PathSource::DefineOpaques, false) => E0425,
626626
(PathSource::Struct(_), true) => E0574,
627627
(PathSource::Struct(_), false) => E0422,
628628
(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
@@ -3161,7 +3161,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
31613161
result
31623162
}
31633163

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

43634363
// There are two different error messages user might receive at
43644364
// this point:
4365-
// - E0412 cannot find type `{}` in this scope
4365+
// - E0425 cannot find value `{}` in this scope
43664366
// - E0433 failed to resolve: use of undeclared type or module `{}`
43674367
//
4368-
// The first one is emitted for paths in type-position, and the
4369-
// latter one - for paths in expression-position.
4368+
// The first one is emitted for unresolved names, and the
4369+
// latter one - for paths in use statements.
43704370
//
43714371
// Thus (since we're in expression-position at this point), not to
43724372
// confuse the user, we want to keep the *message* from E0433 (so
4373-
// `parent_err`), but we want *hints* from E0412 (so `err`).
4373+
// `parent_err`), but we want *hints* from E0425 (so `err`).
43744374
//
43754375
// And that's what happens below - we're just mixing both messages
43764376
// into a single one.

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
705705
if !enum_candidates.is_empty() {
706706
enum_candidates.sort();
707707

708-
// Contextualize for E0412 "cannot find type", but don't belabor the point
708+
// Contextualize for E0425 "cannot find value", but don't belabor the point
709709
// (that it's a variant) for E0573 "expected type, found variant".
710710
let preamble = if res.is_none() {
711711
let others = match enum_candidates.len() {
@@ -1127,7 +1127,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11271127
}
11281128

11291129
self.suggest_ident_hidden_by_hygiene(err, path, span);
1130-
} else if err_code == E0412 {
1130+
} else if err_code == E0425 {
11311131
if let Some(correct) = Self::likely_rust_type(path) {
11321132
err.span_suggestion(
11331133
span,

tests/rustdoc-ui/impl-fn-nesting.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0405]: cannot find trait `UnknownBound` in this scope
1010
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
1111
| ^^^^^^^^^^^^ not found in this scope
1212

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

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

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

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

6161
error: aborting due to 10 previous errors
6262

63-
Some errors have detailed explanations: E0405, E0412.
63+
Some errors have detailed explanations: E0405, E0425.
6464
For more information about an error, try `rustc --explain E0405`.

tests/ui/annotate-snippet/missing-type.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0412]: cannot find type `Iter` in this scope
1+
error[E0425]: cannot find type `Iter` in this scope
22
--> $DIR/missing-type.rs:4:12
33
|
44
LL | let x: Iter;
@@ -18,4 +18,4 @@ LL + use std::collections::hash_map::Iter;
1818

1919
error: aborting due to 1 previous error
2020

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

tests/ui/argument-suggestions/extern-fn-arg-names.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0412]: cannot find type `err` in this scope
1+
error[E0425]: cannot find type `err` in this scope
22
--> $DIR/extern-fn-arg-names.rs:2:29
33
|
44
LL | fn dstfn(src: i32, dst: err);
@@ -22,5 +22,5 @@ LL | dstfn(1, /* dst */);
2222

2323
error: aborting due to 2 previous errors
2424

25-
Some errors have detailed explanations: E0061, E0412.
25+
Some errors have detailed explanations: E0061, E0425.
2626
For more information about an error, try `rustc --explain E0061`.

tests/ui/argument-suggestions/issue-109831.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct A;
22
struct B;
33

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

66
fn main() {
77
f(A, A, B, C); //~ ERROR E0425

tests/ui/argument-suggestions/issue-109831.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0412]: cannot find type `C` in this scope
1+
error[E0425]: cannot find type `C` in this scope
22
--> $DIR/issue-109831.rs:4:24
33
|
44
LL | struct A;
@@ -48,5 +48,5 @@ LL + f(/* B */, /* B */, B);
4848

4949
error: aborting due to 3 previous errors
5050

51-
Some errors have detailed explanations: E0061, E0412, E0425.
51+
Some errors have detailed explanations: E0061, E0425, E0425.
5252
For more information about an error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)