Skip to content

Commit b6d0fd0

Browse files
committed
Auto merge of #17987 - ChayimFriedman2:column-macro, r=Veykril
fix: Fix name resolution of shadowed builtin macro Fixes #17969.
2 parents e0625d5 + 4880eee commit b6d0fd0

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,11 @@ impl ModCollector<'_, '_> {
16061606

16071607
// Prelude module is always considered to be `#[macro_use]`.
16081608
if let Some((prelude_module, _use)) = self.def_collector.def_map.prelude {
1609-
if prelude_module.krate != krate && is_crate_root {
1609+
// Don't insert macros from the prelude into blocks, as they can be shadowed by other macros.
1610+
if prelude_module.krate != krate
1611+
&& is_crate_root
1612+
&& self.def_collector.def_map.block.is_none()
1613+
{
16101614
cov_mark::hit!(prelude_is_macro_use);
16111615
self.def_collector.import_macros_from_extern_crate(
16121616
prelude_module.krate,

Diff for: src/tools/rust-analyzer/crates/ide/src/goto_definition.rs

+19
Original file line numberDiff line numberDiff line change
@@ -2731,4 +2731,23 @@ fn main() {
27312731
"#,
27322732
)
27332733
}
2734+
2735+
#[test]
2736+
fn shadow_builtin_macro() {
2737+
check(
2738+
r#"
2739+
//- minicore: column
2740+
//- /a.rs crate:a
2741+
#[macro_export]
2742+
macro_rules! column { () => {} }
2743+
// ^^^^^^
2744+
2745+
//- /b.rs crate:b deps:a
2746+
use a::column;
2747+
fn foo() {
2748+
$0column!();
2749+
}
2750+
"#,
2751+
);
2752+
}
27342753
}

Diff for: src/tools/rust-analyzer/crates/test-utils/src/minicore.rs

+9
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
//! unsize: sized
6464
//! todo: panic
6565
//! unimplemented: panic
66+
//! column:
6667
6768
#![rustc_coherence_is_core]
6869

@@ -1617,6 +1618,14 @@ pub mod error {
16171618
}
16181619
// endregion:error
16191620

1621+
// region:column
1622+
#[rustc_builtin_macro]
1623+
#[macro_export]
1624+
macro_rules! column {
1625+
() => {};
1626+
}
1627+
// endregion:column
1628+
16201629
pub mod prelude {
16211630
pub mod v1 {
16221631
pub use crate::{

0 commit comments

Comments
 (0)