Skip to content

Commit 41775d4

Browse files
committed
Fix: Prevent macro-expanded extern crates from shadowing extern arguments
1 parent 198328a commit 41775d4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10361036
self.r.dcx().emit_err(
10371037
errors::MacroExpandedExternCrateCannotShadowExternArguments { span: item.span },
10381038
);
1039+
return; // Fix: Stop processing this item to avoid inconsistent resolution state.
10391040
}
10401041

10411042
use indexmap::map::Entry;
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)