Skip to content

Commit c41b208

Browse files
committed
fix(resolve): not defined extern crate shadow_name
1 parent 8b4b208 commit c41b208

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

+5
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
873873
let msg = "macro-expanded `extern crate` items cannot \
874874
shadow names passed with `--extern`";
875875
self.r.tcx.sess.span_err(item.span, msg);
876+
// `return` is intended to discard this binding because it's an
877+
// unregistered ambiguity error which would result in a panic
878+
// caused by inconsistency `path_res`
879+
// more details: https://github.com/rust-lang/rust/pull/111761
880+
return;
876881
}
877882
}
878883
let entry = self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Determinacy {
106106
/// A specific scope in which a name can be looked up.
107107
/// This enum is currently used only for early resolution (imports and macros),
108108
/// but not for late resolution yet.
109-
#[derive(Clone, Copy)]
109+
#[derive(Clone, Copy, Debug)]
110110
enum Scope<'a> {
111111
DeriveHelpers(LocalExpnId),
112112
DeriveHelpersCompat,

tests/ui/imports/issue-109148.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition: 2021
2+
3+
// https://github.com/rust-lang/rust/pull/111761#issuecomment-1557777314
4+
macro_rules! m {
5+
() => {
6+
extern crate core as std;
7+
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
8+
}
9+
}
10+
11+
m!();
12+
13+
use std::mem;
14+
15+
fn main() {}

tests/ui/imports/issue-109148.stderr

+13
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/issue-109148.rs:6:9
3+
|
4+
LL | extern crate core as std;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | m!();
8+
| ---- in this macro invocation
9+
|
10+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)