Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
self.r.dcx().emit_err(
errors::MacroExpandedExternCrateCannotShadowExternArguments { span: item.span },
);
return; // Fix: Stop processing this item to avoid inconsistent resolution state.
}

use indexmap::map::Entry;
Expand Down
63 changes: 33 additions & 30 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,36 +771,39 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
} else {
None
};
// Skip ambiguity errors for extern flag bindings "overridden"
// by extern item bindings.
// FIXME: Remove with lang team approval.
let issue_145575_hack = Some(binding) == extern_prelude_flag_binding
&& extern_prelude_item_binding.is_some()
&& extern_prelude_item_binding != Some(innermost_binding);
if let Some(kind) = ambiguity_error_kind
&& !issue_145575_hack
{
let misc = |f: Flags| {
if f.contains(Flags::MISC_SUGGEST_CRATE) {
AmbiguityErrorMisc::SuggestCrate
} else if f.contains(Flags::MISC_SUGGEST_SELF) {
AmbiguityErrorMisc::SuggestSelf
} else if f.contains(Flags::MISC_FROM_PRELUDE) {
AmbiguityErrorMisc::FromPrelude
} else {
AmbiguityErrorMisc::None
}
};
self.ambiguity_errors.push(AmbiguityError {
kind,
ident: orig_ident,
b1: innermost_binding,
b2: binding,
warning: false,
misc1: misc(innermost_flags),
misc2: misc(flags),
});
return true;
if let Some(kind) = ambiguity_error_kind {
// Skip ambiguity errors for extern flag bindings "overridden"
// by extern item bindings.
// FIXME: Remove with lang team approval.
let issue_145575_hack = Some(binding) == extern_prelude_flag_binding
&& extern_prelude_item_binding.is_some()
&& extern_prelude_item_binding != Some(innermost_binding);

if issue_145575_hack {
self.issue_145575_hack_applied = true;
} else {
let misc = |f: Flags| {
if f.contains(Flags::MISC_SUGGEST_CRATE) {
AmbiguityErrorMisc::SuggestCrate
} else if f.contains(Flags::MISC_SUGGEST_SELF) {
AmbiguityErrorMisc::SuggestSelf
} else if f.contains(Flags::MISC_FROM_PRELUDE) {
AmbiguityErrorMisc::FromPrelude
} else {
AmbiguityErrorMisc::None
}
};
self.ambiguity_errors.push(AmbiguityError {
kind,
ident: orig_ident,
b1: innermost_binding,
b2: binding,
warning: false,
misc1: misc(innermost_flags),
misc2: misc(flags),
});
return true;
}
}

false
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return;
}
if let Some(initial_res) = initial_res {
if res != initial_res {
if res != initial_res && !this.issue_145575_hack_applied {
span_bug!(import.span, "inconsistent resolution for an import");
}
} else if this.privacy_errors.is_empty() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ pub struct Resolver<'ra, 'tcx> {
privacy_errors: Vec<PrivacyError<'ra>> = Vec::new(),
/// Ambiguity errors are delayed for deduplication.
ambiguity_errors: Vec<AmbiguityError<'ra>> = Vec::new(),
issue_145575_hack_applied: bool = false,
/// `use` injections are delayed for better placement and deduplication.
use_injections: Vec<UseError<'tcx>> = Vec::new(),
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/crashes/ice-6255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ macro_rules! define_other_core {
}

fn main() {
core::panic!(); //~ ERROR: `core` is ambiguous
core::panic!();
}

define_other_core!();
22 changes: 1 addition & 21 deletions src/tools/clippy/tests/ui/crashes/ice-6255.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,5 @@ LL | define_other_core!();
|
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `core` is ambiguous
--> tests/ui/crashes/ice-6255.rs:12:5
|
LL | core::panic!();
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
= note: `core` could refer to a built-in crate
note: `core` could also refer to the crate imported here
--> tests/ui/crashes/ice-6255.rs:6:9
|
LL | extern crate std as core;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core!();
| -------------------- in this macro invocation
= help: use `crate::core` to refer to this crate unambiguously
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0659`.
4 changes: 2 additions & 2 deletions tests/ui/imports/issue-109148.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! m {

m!();

use std::mem; //~ ERROR `std` is ambiguous
use ::std::mem as _; //~ ERROR `std` is ambiguous
use std::mem;
use ::std::mem as _;

fn main() {}
40 changes: 1 addition & 39 deletions tests/ui/imports/issue-109148.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,5 @@ LL | m!();
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `std` is ambiguous
--> $DIR/issue-109148.rs:13:5
|
LL | use std::mem;
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
= note: `std` could refer to a built-in crate
note: `std` could also refer to the crate imported here
--> $DIR/issue-109148.rs:6:9
|
LL | extern crate core as std;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | m!();
| ---- in this macro invocation
= help: use `crate::std` to refer to this crate unambiguously
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `std` is ambiguous
--> $DIR/issue-109148.rs:14:7
|
LL | use ::std::mem as _;
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
= note: `std` could refer to a built-in crate
note: `std` could also refer to the crate imported here
--> $DIR/issue-109148.rs:6:9
|
LL | extern crate core as std;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | m!();
| ---- in this macro invocation
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0659`.
4 changes: 2 additions & 2 deletions tests/ui/macros/issue-78325-inconsistent-resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ macro_rules! define_other_core {
}

fn main() {
core::panic!(); //~ ERROR `core` is ambiguous
::core::panic!(); //~ ERROR `core` is ambiguous
core::panic!();
::core::panic!();
}

define_other_core!();
40 changes: 1 addition & 39 deletions tests/ui/macros/issue-78325-inconsistent-resolution.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,5 @@ LL | define_other_core!();
|
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `core` is ambiguous
--> $DIR/issue-78325-inconsistent-resolution.rs:11:5
|
LL | core::panic!();
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
= note: `core` could refer to a built-in crate
note: `core` could also refer to the crate imported here
--> $DIR/issue-78325-inconsistent-resolution.rs:5:9
|
LL | extern crate std as core;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core!();
| -------------------- in this macro invocation
= help: use `crate::core` to refer to this crate unambiguously
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `core` is ambiguous
--> $DIR/issue-78325-inconsistent-resolution.rs:12:7
|
LL | ::core::panic!();
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
= note: `core` could refer to a built-in crate
note: `core` could also refer to the crate imported here
--> $DIR/issue-78325-inconsistent-resolution.rs:5:9
|
LL | extern crate std as core;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core!();
| -------------------- in this macro invocation
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0659`.
17 changes: 17 additions & 0 deletions tests/ui/resolve/ice-inconsistent-resolution-149821.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ edition: 2024

mod m {
use crate::*;
use core;
}

macro_rules! define_other_core {
() => {
extern crate std as core;
//~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
};
}

define_other_core! {}

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/resolve/ice-inconsistent-resolution-149821.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
--> $DIR/ice-inconsistent-resolution-149821.rs:10:9
|
LL | extern crate std as core;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core! {}
| --------------------- in this macro invocation
|
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Loading