Skip to content

Commit 6a9cd26

Browse files
committed
Fix ICE #149821: Handle inconsistent resolution gracefully
1 parent 377656d commit 6a9cd26

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11711171
}
11721172
if let Some(initial_res) = initial_res {
11731173
if res != initial_res {
1174-
span_bug!(import.span, "inconsistent resolution for an import");
1174+
// If we already have errors, ignore the inconsistency.
1175+
if this.dcx().has_errors().is_some() {
1176+
return;
1177+
}
1178+
1179+
this.dcx().span_delayed_bug(
1180+
import.span,
1181+
"inconsistent resolution for an import",
1182+
);
1183+
return;
11751184
}
11761185
} else if this.privacy_errors.is_empty() {
11771186
this.dcx()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ edition: 2024
2+
3+
mod m {
4+
use crate::*;
5+
use core;
6+
}
7+
8+
macro_rules! define_other_core {
9+
() => {
10+
extern crate std as core;
11+
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
12+
};
13+
}
14+
15+
define_other_core! {}
16+
17+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
2+
--> $DIR/ice-inconsistent-resolution-149821.rs:10:9
3+
|
4+
LL | extern crate std as core;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | define_other_core! {}
8+
| --------------------- in this macro invocation
9+
|
10+
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)