From 4d2f6a0843b161df938c341ecf142e636cd54b5b Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 18 Jan 2026 04:34:46 +0900 Subject: [PATCH] fix ICE on inconsistent import resolution with macro-attributed extern crate --- compiler/rustc_resolve/src/imports.rs | 2 +- .../resolve/ice-inconsistent-resolution-151213.rs | 14 ++++++++++++++ .../ice-inconsistent-resolution-151213.stderr | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/ui/resolve/ice-inconsistent-resolution-151213.rs create mode 100644 tests/ui/resolve/ice-inconsistent-resolution-151213.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 451779ae32c6b..016fc407daabe 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -989,7 +989,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { PathResult::Module(module) => { // Consistency checks, analogous to `finalize_macro_resolutions`. if let Some(initial_module) = import.imported_module.get() { - if module != initial_module && no_ambiguity { + if module != initial_module && no_ambiguity && !self.issue_145575_hack_applied { span_bug!(import.span, "inconsistent resolution for an import"); } } else if self.privacy_errors.is_empty() { diff --git a/tests/ui/resolve/ice-inconsistent-resolution-151213.rs b/tests/ui/resolve/ice-inconsistent-resolution-151213.rs new file mode 100644 index 0000000000000..ea0f1c2858ef8 --- /dev/null +++ b/tests/ui/resolve/ice-inconsistent-resolution-151213.rs @@ -0,0 +1,14 @@ +//@ edition: 2024 + +#[attr] +//~^ ERROR cannot find attribute `attr` in this scope +extern crate core as std; +//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern` + +mod inner { + use std::str; + + use crate::*; +} + +fn main() {} diff --git a/tests/ui/resolve/ice-inconsistent-resolution-151213.stderr b/tests/ui/resolve/ice-inconsistent-resolution-151213.stderr new file mode 100644 index 0000000000000..deb1e6c3e1cfe --- /dev/null +++ b/tests/ui/resolve/ice-inconsistent-resolution-151213.stderr @@ -0,0 +1,14 @@ +error: macro-expanded `extern crate` items cannot shadow names passed with `--extern` + --> $DIR/ice-inconsistent-resolution-151213.rs:5:1 + | +LL | extern crate core as std; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `attr` in this scope + --> $DIR/ice-inconsistent-resolution-151213.rs:3:3 + | +LL | #[attr] + | ^^^^ + +error: aborting due to 2 previous errors +