File tree 3 files changed +33
-1
lines changed
src/tools/rust-analyzer/crates
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1606,7 +1606,11 @@ impl ModCollector<'_, '_> {
1606
1606
1607
1607
// Prelude module is always considered to be `#[macro_use]`.
1608
1608
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
+ {
1610
1614
cov_mark:: hit!( prelude_is_macro_use) ;
1611
1615
self . def_collector . import_macros_from_extern_crate (
1612
1616
prelude_module. krate ,
Original file line number Diff line number Diff line change @@ -2731,4 +2731,23 @@ fn main() {
2731
2731
"# ,
2732
2732
)
2733
2733
}
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
+ }
2734
2753
}
Original file line number Diff line number Diff line change 63
63
//! unsize: sized
64
64
//! todo: panic
65
65
//! unimplemented: panic
66
+ //! column:
66
67
67
68
#![ rustc_coherence_is_core]
68
69
@@ -1617,6 +1618,14 @@ pub mod error {
1617
1618
}
1618
1619
// endregion:error
1619
1620
1621
+ // region:column
1622
+ #[ rustc_builtin_macro]
1623
+ #[ macro_export]
1624
+ macro_rules! column {
1625
+ ( ) => { } ;
1626
+ }
1627
+ // endregion:column
1628
+
1620
1629
pub mod prelude {
1621
1630
pub mod v1 {
1622
1631
pub use crate :: {
You can’t perform that action at this time.
0 commit comments