about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-07-01 13:46:00 +0200
committerGitHub <noreply@github.com>2023-07-01 13:46:00 +0200
commitb63bc0645f13b360983c4cb38a1757fd5a5b058b (patch)
tree565f518a81347c2f69ba9d8c42fccb6c1b1773b1 /compiler
parente5bb341f0e1db4e4407f129d9834f9ada2030b7c (diff)
parent549f48d0ede94ab53056830cf9d5189c0445428e (diff)
downloadrust-b63bc0645f13b360983c4cb38a1757fd5a5b058b.tar.gz
rust-b63bc0645f13b360983c4cb38a1757fd5a5b058b.zip
Rollup merge of #113168 - bvanjoi:fix-85992, r=petrochenkov
fix(resolve): skip assertion judgment when NonModule is dummy

Fixes #85992

## Why #85992 panic

During `resolve_imports`, the `path_res` of the import `issue_85992_extern_2::Outcome` is pointing to `external::issue_85992_extern_2` instead of `crate::issue_85992_extern_2`. As a result `import.imported_module.set` had been executed.

Attached 1: the state of `early_resolve_ident_in_lexical_scope` during the `resolve_imports` for `use issue_85992_extern_2::Outcome` is as follows:

|iter in `visit_scopes`  | `scope` | `result.binding` |
| -    | -               | -                                                            |
| init | -               | -                                                            |
| 0    | `CrateRoot`     | Err(Determined)     |
| 1    | `ExternPrelude` | pointing to the `issue_85992_extern_2`(external) |

However, during finalization for `issue_85992_extern_2::Outcome`, the `innermost_result` was pointed to `crate::issue_85992_extern_2` and no ambiguity was generated, leading to a panic.

Attached 2: the state of `early_resolve_ident_in_lexical_scope` during the `finalize_import` for `use issue_85992_extern_2::Outcome` is as follows:

|iter in `visit_scopes`  | `scope` | `result.binding` | `innermost_result` |
| -    | -               | -                                                            | -                     |
| init | -               | -                                                            | `None`                |
| 0    | `CrateRoot`     | pointing to `use crate::issue_85992_extern_2` **(introdcued by dummy)**    | same as `result` but with a `Some` wapper|
| 1    | `ExternPrelude` | pointing to the `issue_85992_extern_2`(external) | smae as above |

## Try to solve

Skip assertion judgment when `NonModule` is dummy

r? `@petrochenkov`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_resolve/src/ident.rs2
-rw-r--r--compiler/rustc_resolve/src/imports.rs5
-rw-r--r--compiler/rustc_resolve/src/lib.rs2
3 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs
index 8e921f1ecb1..36f01676e7e 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 8bd08921fe6..074f761c53b 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 ff698452ad5..cc4cb9fa30c 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),