Auto merge of #17987 - ChayimFriedman2:column-macro, r=Veykril

fix: Fix name resolution of shadowed builtin macro

Fixes #17969.
This commit is contained in:
bors 2024-08-29 07:59:12 +00:00
commit d9be51bbc9
3 changed files with 33 additions and 1 deletions

View file

@ -1606,7 +1606,11 @@ impl ModCollector<'_, '_> {
// Prelude module is always considered to be `#[macro_use]`.
if let Some((prelude_module, _use)) = self.def_collector.def_map.prelude {
if prelude_module.krate != krate && is_crate_root {
// Don't insert macros from the prelude into blocks, as they can be shadowed by other macros.
if prelude_module.krate != krate
&& is_crate_root
&& self.def_collector.def_map.block.is_none()
{
cov_mark::hit!(prelude_is_macro_use);
self.def_collector.import_macros_from_extern_crate(
prelude_module.krate,

View file

@ -2731,4 +2731,23 @@ fn main() {
"#,
)
}
#[test]
fn shadow_builtin_macro() {
check(
r#"
//- minicore: column
//- /a.rs crate:a
#[macro_export]
macro_rules! column { () => {} }
// ^^^^^^
//- /b.rs crate:b deps:a
use a::column;
fn foo() {
$0column!();
}
"#,
);
}
}

View file

@ -63,6 +63,7 @@
//! unsize: sized
//! todo: panic
//! unimplemented: panic
//! column:
#![rustc_coherence_is_core]
@ -1617,6 +1618,14 @@ pub mod error {
}
// endregion:error
// region:column
#[rustc_builtin_macro]
#[macro_export]
macro_rules! column {
() => {};
}
// endregion:column
pub mod prelude {
pub mod v1 {
pub use crate::{