From 02f1f6a8a893bbaabc87079a61815685b0f88d75 Mon Sep 17 00:00:00 2001 From: bohan Date: Sun, 23 Jul 2023 20:21:53 +0800 Subject: [PATCH 1/2] fix(resolve): skip panic when resolution is dummy --- compiler/rustc_resolve/src/imports.rs | 5 ++++- tests/ui/imports/issue-113953.rs | 6 ++++++ tests/ui/imports/issue-113953.stderr | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ui/imports/issue-113953.rs create mode 100644 tests/ui/imports/issue-113953.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 526fc9c3aa511..f18aedd190fd7 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -990,7 +990,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); let res = binding.res(); if let Ok(initial_res) = initial_res { - if res != initial_res && this.ambiguity_errors.is_empty() { + if res != initial_res + && this.ambiguity_errors.is_empty() + && res != Res::Err + { span_bug!(import.span, "inconsistent resolution for an import"); } } else if res != Res::Err diff --git a/tests/ui/imports/issue-113953.rs b/tests/ui/imports/issue-113953.rs new file mode 100644 index 0000000000000..449a074f4b5df --- /dev/null +++ b/tests/ui/imports/issue-113953.rs @@ -0,0 +1,6 @@ +// edition: 2021 +use u8 as imported_u8; +use unresolved as u8; +//~^ ERROR unresolved import `unresolved` + +fn main() {} diff --git a/tests/ui/imports/issue-113953.stderr b/tests/ui/imports/issue-113953.stderr new file mode 100644 index 0000000000000..70f91bd3c5bf0 --- /dev/null +++ b/tests/ui/imports/issue-113953.stderr @@ -0,0 +1,9 @@ +error[E0432]: unresolved import `unresolved` + --> $DIR/issue-113953.rs:3:5 + | +LL | use unresolved as u8; + | ^^^^^^^^^^^^^^^^ no external crate `unresolved` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. From 4cc3834a5ced7ed5bc5c63d283c8a5b23fb9ccf6 Mon Sep 17 00:00:00 2001 From: bohan Date: Tue, 25 Jul 2023 01:57:12 +0800 Subject: [PATCH 2/2] resolve: ensure compile failed when has dummy or ambiguous --- compiler/rustc_resolve/src/imports.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index f18aedd190fd7..f3cf61c5b9326 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -989,17 +989,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { initial_binding.res() }); let res = binding.res(); + if res == Res::Err || !this.ambiguity_errors.is_empty() { + this.tcx + .sess + .delay_span_bug(import.span, "some error happened for an import"); + return; + } if let Ok(initial_res) = initial_res { - if res != initial_res - && this.ambiguity_errors.is_empty() - && res != Res::Err - { + if res != initial_res { span_bug!(import.span, "inconsistent resolution for an import"); } - } else if res != Res::Err - && this.ambiguity_errors.is_empty() - && this.privacy_errors.is_empty() - { + } else if this.privacy_errors.is_empty() { this.tcx .sess .create_err(CannotDetermineImportResolution { span: import.span })