mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Fix: Prevent macro-expanded extern crates from shadowing extern arguments
This commit is contained in:
@@ -771,36 +771,39 @@ fn maybe_push_ambiguity(
|
||||
} 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
|
||||
|
||||
@@ -1170,7 +1170,7 @@ fn finalize_import(&mut self, import: Import<'ra>) -> Option<UnresolvedImportErr
|
||||
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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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() {}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user