mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Hoist macros from extern crate with macro_use
This commit is contained in:
parent
dec43a0c5d
commit
67d33cc21a
2 changed files with 20 additions and 14 deletions
|
@ -531,20 +531,26 @@ where
|
||||||
self.def_collector.import_all_macros_exported(prelude_module);
|
self.def_collector.import_all_macros_exported(prelude_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should be processed eagerly instead of deferred to resolving.
|
||||||
|
// `#[macro_use] extern crate` is hoisted to imports macros before collecting
|
||||||
|
// any other items.
|
||||||
|
for item in items {
|
||||||
|
if let raw::RawItem::Import(import_id) = *item {
|
||||||
|
let import = self.raw_items[import_id].clone();
|
||||||
|
if import.is_extern_crate && import.is_macro_use {
|
||||||
|
self.def_collector.import_macros_from_extern_crate(&import);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
match *item {
|
match *item {
|
||||||
raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]),
|
raw::RawItem::Module(m) => self.collect_module(&self.raw_items[m]),
|
||||||
raw::RawItem::Import(import_id) => {
|
raw::RawItem::Import(import_id) => self.def_collector.unresolved_imports.push((
|
||||||
let import = self.raw_items[import_id].clone();
|
self.module_id,
|
||||||
// This should be processed eagerly instead of deferred to resolving.
|
import_id,
|
||||||
// Otherwise, since it will only mutate `global_macro_scope`
|
self.raw_items[import_id].clone(),
|
||||||
// without `update` names in `mod`s, unresolved macros cannot be expanded.
|
)),
|
||||||
if import.is_extern_crate && import.is_macro_use {
|
|
||||||
self.def_collector.import_macros_from_extern_crate(&import);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.def_collector.unresolved_imports.push((self.module_id, import_id, import));
|
|
||||||
}
|
|
||||||
raw::RawItem::Def(def) => self.define_def(&self.raw_items[def]),
|
raw::RawItem::Def(def) => self.define_def(&self.raw_items[def]),
|
||||||
raw::RawItem::Macro(mac) => self.collect_macro(&self.raw_items[mac]),
|
raw::RawItem::Macro(mac) => self.collect_macro(&self.raw_items[mac]),
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,9 +144,6 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[macro_use]
|
|
||||||
extern crate foo;
|
|
||||||
|
|
||||||
structs!(Foo);
|
structs!(Foo);
|
||||||
structs_priv!(Bar);
|
structs_priv!(Bar);
|
||||||
structs_not_exported!(MacroNotResolved1);
|
structs_not_exported!(MacroNotResolved1);
|
||||||
|
@ -154,6 +151,9 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() {
|
||||||
|
|
||||||
mod bar;
|
mod bar;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate foo;
|
||||||
|
|
||||||
//- /bar.rs
|
//- /bar.rs
|
||||||
structs!(Baz);
|
structs!(Baz);
|
||||||
crate::structs!(MacroNotResolved3);
|
crate::structs!(MacroNotResolved3);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue