From 27420c69d830d7a32544dd42f40c757d9cb4e095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 5 Dec 2024 21:47:06 +0000 Subject: [PATCH] Silence `use foo::Bar;` error if `Bar` isn't found in `foo` and `foo.rs` has parse errors --- compiler/rustc_resolve/src/imports.rs | 7 ++++++- tests/ui/resolve/parse-error-resolve.rs | 2 +- tests/ui/resolve/parse-error-resolve.stderr | 11 ++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 5b8eefbb88db9..2ed3f4d2c4fbb 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -670,9 +670,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { fn throw_unresolved_import_error( &mut self, - errors: Vec<(Import<'_>, UnresolvedImportError)>, + mut errors: Vec<(Import<'_>, UnresolvedImportError)>, glob_error: bool, ) { + errors.retain(|(_import, err)| match err.module { + // Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors. + Some(def_id) if self.mods_with_parse_errors.contains(&def_id) => false, + _ => true, + }); if errors.is_empty() { return; } diff --git a/tests/ui/resolve/parse-error-resolve.rs b/tests/ui/resolve/parse-error-resolve.rs index 9cb58f5512892..1e0772648afec 100644 --- a/tests/ui/resolve/parse-error-resolve.rs +++ b/tests/ui/resolve/parse-error-resolve.rs @@ -1,5 +1,5 @@ mod parse_error; -use parse_error::Canonical; //~ ERROR E0432 +use parse_error::Canonical; // ok, `parse_error.rs` had parse errors fn main() { let _ = "" + 1; //~ ERROR E0369 diff --git a/tests/ui/resolve/parse-error-resolve.stderr b/tests/ui/resolve/parse-error-resolve.stderr index c05a9c6dafbda..30475aa0ee63e 100644 --- a/tests/ui/resolve/parse-error-resolve.stderr +++ b/tests/ui/resolve/parse-error-resolve.stderr @@ -9,12 +9,6 @@ help: you might have meant to end the type parameters here LL | impl>> From for Canonical { | + -error[E0432]: unresolved import `parse_error::Canonical` - --> $DIR/parse-error-resolve.rs:2:5 - | -LL | use parse_error::Canonical; - | ^^^^^^^^^^^^^^^^^^^^^^ no `Canonical` in `parse_error` - error[E0369]: cannot add `{integer}` to `&str` --> $DIR/parse-error-resolve.rs:5:16 | @@ -23,7 +17,6 @@ LL | let _ = "" + 1; | | | &str -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0369, E0432. -For more information about an error, try `rustc --explain E0369`. +For more information about this error, try `rustc --explain E0369`.