From 7c1bc0353b8c13edc6e3cb8e0a37e876f06da7b7 Mon Sep 17 00:00:00 2001 From: bohan Date: Wed, 10 May 2023 22:35:01 +0800 Subject: [PATCH] refactor(resolve): clean up the early error return caused by non-call --- compiler/rustc_resolve/src/late.rs | 4 ---- .../equality-bound.stderr | 5 ++++- .../ui/macros/builtin-prelude-no-accidents.stderr | 15 +++++++++------ tests/ui/parser/dyn-trait-compatibility.stderr | 12 ++++++------ tests/ui/pattern/pattern-error-continue.stderr | 15 +++++++++------ tests/ui/resolve/issue-109250.rs | 3 +++ tests/ui/resolve/issue-109250.stderr | 14 ++++++++++++++ .../ui/resolve/resolve-variant-assoc-item.stderr | 14 ++++++++++++++ tests/ui/type/type-path-err-node-types.stderr | 12 ++++++------ 9 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 tests/ui/resolve/issue-109250.rs create mode 100644 tests/ui/resolve/issue-109250.stderr diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2a8287d5554..7129a58b71c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3528,10 +3528,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { // // Similar thing, for types, happens in `report_errors` above. let report_errors_for_call = |this: &mut Self, parent_err: Spanned>| { - if !source.is_call() { - return Some(parent_err); - } - // Before we start looking for candidates, we have to get our hands // on the type user is trying to perform invocation on; basically: // we're transforming `HashMap::new` into just `HashMap`. diff --git a/tests/ui/generic-associated-types/equality-bound.stderr b/tests/ui/generic-associated-types/equality-bound.stderr index d78f7a7fbce..b21ff30a27d 100644 --- a/tests/ui/generic-associated-types/equality-bound.stderr +++ b/tests/ui/generic-associated-types/equality-bound.stderr @@ -36,7 +36,10 @@ error[E0433]: failed to resolve: use of undeclared type `I` --> $DIR/equality-bound.rs:9:41 | LL | fn sum3(i: J) -> i32 where I::Item = i32 { - | ^ use of undeclared type `I` + | ^ + | | + | use of undeclared type `I` + | help: a type parameter with a similar name exists: `J` error: aborting due to 4 previous errors diff --git a/tests/ui/macros/builtin-prelude-no-accidents.stderr b/tests/ui/macros/builtin-prelude-no-accidents.stderr index 56af618d484..8cd9a63b808 100644 --- a/tests/ui/macros/builtin-prelude-no-accidents.stderr +++ b/tests/ui/macros/builtin-prelude-no-accidents.stderr @@ -4,18 +4,21 @@ error[E0433]: failed to resolve: use of undeclared crate or module `env` LL | env::current_dir; | ^^^ use of undeclared crate or module `env` +error[E0433]: failed to resolve: use of undeclared crate or module `vec` + --> $DIR/builtin-prelude-no-accidents.rs:7:14 + | +LL | type B = vec::Vec; + | ^^^ + | | + | use of undeclared crate or module `vec` + | help: a struct with a similar name exists (notice the capitalization): `Vec` + error[E0433]: failed to resolve: use of undeclared crate or module `panic` --> $DIR/builtin-prelude-no-accidents.rs:6:14 | LL | type A = panic::PanicInfo; | ^^^^^ use of undeclared crate or module `panic` -error[E0433]: failed to resolve: use of undeclared crate or module `vec` - --> $DIR/builtin-prelude-no-accidents.rs:7:14 - | -LL | type B = vec::Vec; - | ^^^ use of undeclared crate or module `vec` - error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/parser/dyn-trait-compatibility.stderr b/tests/ui/parser/dyn-trait-compatibility.stderr index 653be5b3b71..e34d855a9d4 100644 --- a/tests/ui/parser/dyn-trait-compatibility.stderr +++ b/tests/ui/parser/dyn-trait-compatibility.stderr @@ -1,9 +1,3 @@ -error[E0433]: failed to resolve: use of undeclared crate or module `dyn` - --> $DIR/dyn-trait-compatibility.rs:3:11 - | -LL | type A1 = dyn::dyn; - | ^^^ use of undeclared crate or module `dyn` - error[E0412]: cannot find type `dyn` in this scope --> $DIR/dyn-trait-compatibility.rs:1:11 | @@ -46,6 +40,12 @@ error[E0412]: cannot find type `dyn` in this scope LL | type A3 = dyn<::dyn>; | ^^^ not found in this scope +error[E0433]: failed to resolve: use of undeclared crate or module `dyn` + --> $DIR/dyn-trait-compatibility.rs:3:11 + | +LL | type A1 = dyn::dyn; + | ^^^ use of undeclared crate or module `dyn` + error: aborting due to 8 previous errors Some errors have detailed explanations: E0405, E0412, E0433. diff --git a/tests/ui/pattern/pattern-error-continue.stderr b/tests/ui/pattern/pattern-error-continue.stderr index e1349fb02ea..10fcccb0301 100644 --- a/tests/ui/pattern/pattern-error-continue.stderr +++ b/tests/ui/pattern/pattern-error-continue.stderr @@ -1,9 +1,3 @@ -error[E0433]: failed to resolve: use of undeclared type `E` - --> $DIR/pattern-error-continue.rs:33:9 - | -LL | E::V => {} - | ^ use of undeclared type `E` - error[E0532]: expected tuple struct or tuple variant, found unit variant `A::D` --> $DIR/pattern-error-continue.rs:18:9 | @@ -56,6 +50,15 @@ note: function defined here LL | fn f(_c: char) {} | ^ -------- +error[E0433]: failed to resolve: use of undeclared type `E` + --> $DIR/pattern-error-continue.rs:33:9 + | +LL | E::V => {} + | ^ + | | + | use of undeclared type `E` + | help: an enum with a similar name exists: `A` + error: aborting due to 5 previous errors Some errors have detailed explanations: E0023, E0308, E0433, E0532. diff --git a/tests/ui/resolve/issue-109250.rs b/tests/ui/resolve/issue-109250.rs new file mode 100644 index 00000000000..68e33f693ce --- /dev/null +++ b/tests/ui/resolve/issue-109250.rs @@ -0,0 +1,3 @@ +fn main() { //~ HELP consider importing + HashMap::new; //~ ERROR failed to resolve: use of undeclared type `HashMap` +} diff --git a/tests/ui/resolve/issue-109250.stderr b/tests/ui/resolve/issue-109250.stderr new file mode 100644 index 00000000000..d5b8c08ced7 --- /dev/null +++ b/tests/ui/resolve/issue-109250.stderr @@ -0,0 +1,14 @@ +error[E0433]: failed to resolve: use of undeclared type `HashMap` + --> $DIR/issue-109250.rs:2:5 + | +LL | HashMap::new; + | ^^^^^^^ use of undeclared type `HashMap` + | +help: consider importing this struct + | +LL + use std::collections::HashMap; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/resolve/resolve-variant-assoc-item.stderr b/tests/ui/resolve/resolve-variant-assoc-item.stderr index 4be1019968b..ed157197d17 100644 --- a/tests/ui/resolve/resolve-variant-assoc-item.stderr +++ b/tests/ui/resolve/resolve-variant-assoc-item.stderr @@ -3,12 +3,26 @@ error[E0433]: failed to resolve: `V` is a variant, not a module | LL | E::V::associated_item; | ^ `V` is a variant, not a module + | +help: there is an enum variant `E::V`; try using the variant's enum + | +LL | E; + | ~ error[E0433]: failed to resolve: `V` is a variant, not a module --> $DIR/resolve-variant-assoc-item.rs:6:5 | LL | V::associated_item; | ^ `V` is a variant, not a module + | +help: there is an enum variant `E::V`; try using the variant's enum + | +LL | E; + | ~ +help: an enum with a similar name exists + | +LL | E::associated_item; + | ~ error: aborting due to 2 previous errors diff --git a/tests/ui/type/type-path-err-node-types.stderr b/tests/ui/type/type-path-err-node-types.stderr index 1aed1dbe4ba..8b12aa1a393 100644 --- a/tests/ui/type/type-path-err-node-types.stderr +++ b/tests/ui/type/type-path-err-node-types.stderr @@ -1,9 +1,3 @@ -error[E0433]: failed to resolve: use of undeclared type `NonExistent` - --> $DIR/type-path-err-node-types.rs:15:5 - | -LL | NonExistent::Assoc::; - | ^^^^^^^^^^^ use of undeclared type `NonExistent` - error[E0412]: cannot find type `Nonexistent` in this scope --> $DIR/type-path-err-node-types.rs:7:12 | @@ -22,6 +16,12 @@ error[E0425]: cannot find value `nonexistent` in this scope LL | nonexistent.nonexistent::(); | ^^^^^^^^^^^ not found in this scope +error[E0433]: failed to resolve: use of undeclared type `NonExistent` + --> $DIR/type-path-err-node-types.rs:15:5 + | +LL | NonExistent::Assoc::; + | ^^^^^^^^^^^ use of undeclared type `NonExistent` + error[E0282]: type annotations needed --> $DIR/type-path-err-node-types.rs:23:14 |