From 549f48d0ede94ab53056830cf9d5189c0445428e Mon Sep 17 00:00:00 2001 From: bohan Date: Sat, 1 Jul 2023 11:53:31 +0800 Subject: [PATCH] fix(resolve): skip assertion judgment when `NonModule` is dummy --- compiler/rustc_resolve/src/ident.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 5 +++-- compiler/rustc_resolve/src/lib.rs | 2 +- tests/ui/imports/auxiliary/issue-85992-extern-1.rs | 6 ++++++ tests/ui/imports/auxiliary/issue-85992-extern-2.rs | 1 + tests/ui/imports/issue-85992.rs | 11 +++++++++++ tests/ui/imports/issue-85992.stderr | 9 +++++++++ 7 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/ui/imports/auxiliary/issue-85992-extern-1.rs create mode 100644 tests/ui/imports/auxiliary/issue-85992-extern-2.rs create mode 100644 tests/ui/imports/issue-85992.rs create mode 100644 tests/ui/imports/issue-85992.stderr diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 8e921f1ecb1a2..36f01676e7e09 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// expansion and import resolution (perhaps they can be merged in the future). /// The function is used for resolving initial segments of macro paths (e.g., `foo` in /// `foo::bar!();` or `foo!();`) and also for import paths on 2018 edition. - #[instrument(level = "debug", skip(self, scope_set))] + #[instrument(level = "debug", skip(self))] pub(crate) fn early_resolve_ident_in_lexical_scope( &mut self, orig_ident: Ident, diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 8bd08921fe603..074f761c53baa 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -894,8 +894,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } return None; } - PathResult::NonModule(_) => { - if no_ambiguity { + PathResult::NonModule(partial_res) => { + if no_ambiguity && partial_res.full_res() != Some(Res::Err) { + // Check if there are no ambiguities and the result is not dummy. assert!(import.imported_module.get().is_none()); } // The error was already reported earlier. diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index ff698452ad550..cc4cb9fa30cd9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -128,7 +128,7 @@ enum Scope<'a> { /// with different restrictions when looking up the resolution. /// This enum is currently used only for early resolution (imports and macros), /// but not for late resolution yet. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum ScopeSet<'a> { /// All scopes with the given namespace. All(Namespace), diff --git a/tests/ui/imports/auxiliary/issue-85992-extern-1.rs b/tests/ui/imports/auxiliary/issue-85992-extern-1.rs new file mode 100644 index 0000000000000..a2d0e20606570 --- /dev/null +++ b/tests/ui/imports/auxiliary/issue-85992-extern-1.rs @@ -0,0 +1,6 @@ +#[macro_export] +macro_rules! m { + () => { + use issue_85992_extern_2::Outcome; + } +} diff --git a/tests/ui/imports/auxiliary/issue-85992-extern-2.rs b/tests/ui/imports/auxiliary/issue-85992-extern-2.rs new file mode 100644 index 0000000000000..e9b6a44cfe212 --- /dev/null +++ b/tests/ui/imports/auxiliary/issue-85992-extern-2.rs @@ -0,0 +1 @@ +// nothing diff --git a/tests/ui/imports/issue-85992.rs b/tests/ui/imports/issue-85992.rs new file mode 100644 index 0000000000000..d55241091449a --- /dev/null +++ b/tests/ui/imports/issue-85992.rs @@ -0,0 +1,11 @@ +// edition: 2021 +// compile-flags: --extern issue_85992_extern_1 --extern issue_85992_extern_2 +// aux-build: issue-85992-extern-1.rs +// aux-build: issue-85992-extern-2.rs + +issue_85992_extern_1::m!(); + +use crate::issue_85992_extern_2; +//~^ ERROR unresolved import `crate::issue_85992_extern_2` + +fn main() {} diff --git a/tests/ui/imports/issue-85992.stderr b/tests/ui/imports/issue-85992.stderr new file mode 100644 index 0000000000000..810d41009c520 --- /dev/null +++ b/tests/ui/imports/issue-85992.stderr @@ -0,0 +1,9 @@ +error[E0432]: unresolved import `crate::issue_85992_extern_2` + --> $DIR/issue-85992.rs:8:5 + | +LL | use crate::issue_85992_extern_2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `issue_85992_extern_2` in the root + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`.