Skip to content

Commit b63bc06

Browse files
authored
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`
2 parents e5bb341 + 549f48d commit b63bc06

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

compiler/rustc_resolve/src/ident.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
370370
/// expansion and import resolution (perhaps they can be merged in the future).
371371
/// The function is used for resolving initial segments of macro paths (e.g., `foo` in
372372
/// `foo::bar!();` or `foo!();`) and also for import paths on 2018 edition.
373-
#[instrument(level = "debug", skip(self, scope_set))]
373+
#[instrument(level = "debug", skip(self))]
374374
pub(crate) fn early_resolve_ident_in_lexical_scope(
375375
&mut self,
376376
orig_ident: Ident,

compiler/rustc_resolve/src/imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
894894
}
895895
return None;
896896
}
897-
PathResult::NonModule(_) => {
898-
if no_ambiguity {
897+
PathResult::NonModule(partial_res) => {
898+
if no_ambiguity && partial_res.full_res() != Some(Res::Err) {
899+
// Check if there are no ambiguities and the result is not dummy.
899900
assert!(import.imported_module.get().is_none());
900901
}
901902
// The error was already reported earlier.

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ enum Scope<'a> {
128128
/// with different restrictions when looking up the resolution.
129129
/// This enum is currently used only for early resolution (imports and macros),
130130
/// but not for late resolution yet.
131-
#[derive(Clone, Copy)]
131+
#[derive(Clone, Copy, Debug)]
132132
enum ScopeSet<'a> {
133133
/// All scopes with the given namespace.
134134
All(Namespace),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! m {
3+
() => {
4+
use issue_85992_extern_2::Outcome;
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing

tests/ui/imports/issue-85992.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// edition: 2021
2+
// compile-flags: --extern issue_85992_extern_1 --extern issue_85992_extern_2
3+
// aux-build: issue-85992-extern-1.rs
4+
// aux-build: issue-85992-extern-2.rs
5+
6+
issue_85992_extern_1::m!();
7+
8+
use crate::issue_85992_extern_2;
9+
//~^ ERROR unresolved import `crate::issue_85992_extern_2`
10+
11+
fn main() {}

tests/ui/imports/issue-85992.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0432]: unresolved import `crate::issue_85992_extern_2`
2+
--> $DIR/issue-85992.rs:8:5
3+
|
4+
LL | use crate::issue_85992_extern_2;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `issue_85992_extern_2` in the root
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)