aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs28
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs6
2 files changed, 20 insertions, 14 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 3e689e360..698e40247 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -531,20 +531,26 @@ where
531 self.def_collector.import_all_macros_exported(prelude_module); 531 self.def_collector.import_all_macros_exported(prelude_module);
532 } 532 }
533 533
534 // This should be processed eagerly instead of deferred to resolving.
535 // `#[macro_use] extern crate` is hoisted to imports macros before collecting
536 // any other items.
537 for item in items {
538 if let raw::RawItem::Import(import_id) = *item {
539 let import = self.raw_items[import_id].clone();
540 if import.is_extern_crate && import.is_macro_use {
541 self.def_collector.import_macros_from_extern_crate(&import);
542 }
543 }
544 }
545
534 for item in items { 546 for item in items {
535 match *item { 547 match *item {
536 raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]), 548 raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]),
537 raw::RawItem::Import(import_id) => { 549 raw::RawItem::Import(import_id) => self.def_collector.unresolved_imports.push((
538 let import = self.raw_items[import_id].clone(); 550 self.module_id,
539 // This should be processed eagerly instead of deferred to resolving. 551 import_id,
540 // Otherwise, since it will only mutate `global_macro_scope` 552 self.raw_items[import_id].clone(),
541 // without `update` names in `mod`s, unresolved macros cannot be expanded. 553 )),
542 if import.is_extern_crate && import.is_macro_use {
543 self.def_collector.import_macros_from_extern_crate(&import);
544 }
545
546 self.def_collector.unresolved_imports.push((self.module_id, import_id, import));
547 }
548 raw::RawItem::Def(def) => self.define_def(&self.raw_items[def]), 554 raw::RawItem::Def(def) => self.define_def(&self.raw_items[def]),
549 raw::RawItem::Macro(mac) => self.collect_macro(&self.raw_items[mac]), 555 raw::RawItem::Macro(mac) => self.collect_macro(&self.raw_items[mac]),
550 } 556 }
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index 8fcd86bfe..aece1515b 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -144,9 +144,6 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() {
144 let map = def_map_with_crate_graph( 144 let map = def_map_with_crate_graph(
145 " 145 "
146 //- /main.rs 146 //- /main.rs
147 #[macro_use]
148 extern crate foo;
149
150 structs!(Foo); 147 structs!(Foo);
151 structs_priv!(Bar); 148 structs_priv!(Bar);
152 structs_not_exported!(MacroNotResolved1); 149 structs_not_exported!(MacroNotResolved1);
@@ -154,6 +151,9 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() {
154 151
155 mod bar; 152 mod bar;
156 153
154 #[macro_use]
155 extern crate foo;
156
157 //- /bar.rs 157 //- /bar.rs
158 structs!(Baz); 158 structs!(Baz);
159 crate::structs!(MacroNotResolved3); 159 crate::structs!(MacroNotResolved3);