Skip to content

Commit 4190449

Browse files
committed
Auto merge of #57181 - petrochenkov:impice3, r=estebank
resolve: Fix another ICE in import validation Imports are allowed to have ambiguous resolutions as long as all of them have same `Def`. As it turned out, it's possible for different `Module`s to have same `Def` when `extern crate` items are involved. Fixes #56596
2 parents d5175f4 + 2af1d6f commit 4190449

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/librustc_resolve/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1014,11 +1014,11 @@ enum ModuleOrUniformRoot<'a> {
10141014
CurrentScope,
10151015
}
10161016

1017-
impl<'a> PartialEq for ModuleOrUniformRoot<'a> {
1018-
fn eq(&self, other: &Self) -> bool {
1019-
match (*self, *other) {
1017+
impl ModuleOrUniformRoot<'_> {
1018+
fn same_def(lhs: Self, rhs: Self) -> bool {
1019+
match (lhs, rhs) {
10201020
(ModuleOrUniformRoot::Module(lhs),
1021-
ModuleOrUniformRoot::Module(rhs)) => ptr::eq(lhs, rhs),
1021+
ModuleOrUniformRoot::Module(rhs)) => lhs.def() == rhs.def(),
10221022
(ModuleOrUniformRoot::CrateRootAndExternPrelude,
10231023
ModuleOrUniformRoot::CrateRootAndExternPrelude) |
10241024
(ModuleOrUniformRoot::ExternPrelude, ModuleOrUniformRoot::ExternPrelude) |

src/librustc_resolve/resolve_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
848848
PathResult::Module(module) => {
849849
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
850850
if let Some(initial_module) = directive.imported_module.get() {
851-
if module != initial_module && no_ambiguity {
851+
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
852852
span_bug!(directive.span, "inconsistent resolution for an import");
853853
}
854854
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub extern crate core;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-pass
2+
// edition:2018
3+
// compile-flags: --extern issue_56596_2
4+
// aux-build:issue-56596-2.rs
5+
6+
mod m {
7+
use core::any;
8+
pub use issue_56596_2::*;
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)