Skip to content

Commit 2adc9a8

Browse files
committed
Remove collect proc_macro definitions
1 parent 5bd3aa0 commit 2adc9a8

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr
6565
unexpanded_attribute_macros: Vec::new(),
6666
mod_dirs: FxHashMap::default(),
6767
cfg_options,
68+
69+
// FIXME: pass proc-macro from crate-graph
70+
proc_macros: Default::default(),
6871
};
6972
collector.collect();
7073
collector.finish()
@@ -123,6 +126,7 @@ struct DefCollector<'a> {
123126
unexpanded_attribute_macros: Vec<DeriveDirective>,
124127
mod_dirs: FxHashMap<LocalModuleId, ModDir>,
125128
cfg_options: &'a CfgOptions,
129+
proc_macros: Vec<(Name, ProcMacroExpander)>,
126130
}
127131

128132
impl DefCollector<'_> {
@@ -178,6 +182,24 @@ impl DefCollector<'_> {
178182
for directive in unresolved_imports {
179183
self.record_resolved_import(&directive)
180184
}
185+
186+
// Record proc-macros
187+
self.collect_proc_macro();
188+
}
189+
190+
fn collect_proc_macro(&mut self) {
191+
let proc_macros = std::mem::take(&mut self.proc_macros);
192+
for (name, expander) in proc_macros {
193+
let krate = self.def_map.krate;
194+
195+
let macro_id = MacroDefId {
196+
ast_id: None,
197+
krate: Some(krate),
198+
kind: MacroDefKind::CustomDerive(expander),
199+
};
200+
201+
self.define_proc_macro(name.clone(), macro_id);
202+
}
181203
}
182204

183205
/// Define a macro with `macro_rules`.
@@ -801,7 +823,6 @@ impl ModCollector<'_, '_> {
801823
// in which case we don't add the invocation, just a single attribute
802824
// macro invocation
803825
self.collect_derives(attrs, def);
804-
self.collect_proc_macro(attrs);
805826

806827
let name = def.name.clone();
807828
let container = ContainerId::ModuleId(module);
@@ -878,28 +899,6 @@ impl ModCollector<'_, '_> {
878899
}
879900
}
880901

881-
fn collect_proc_macro(&mut self, attrs: &Attrs) {
882-
if let Some(derive_subtree) = attrs.by_key("proc_macro_derive").tt_values().next() {
883-
if let Some(tt) = derive_subtree.token_trees.get(0) {
884-
let ident = match &tt {
885-
tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => ident,
886-
_ => return, // anything else would be an error (which we currently ignore)
887-
};
888-
let name = ident.as_name();
889-
let krate = self.def_collector.def_map.krate;
890-
let expander = ProcMacroExpander::new(krate);
891-
892-
let macro_id = MacroDefId {
893-
ast_id: None,
894-
krate: Some(krate),
895-
kind: MacroDefKind::CustomDerive(expander),
896-
};
897-
898-
self.def_collector.define_proc_macro(name.clone(), macro_id);
899-
}
900-
}
901-
}
902-
903902
fn collect_macro(&mut self, mac: &raw::MacroData) {
904903
let mut ast_id = AstIdWithPath::new(self.file_id, mac.ast_id, mac.path.clone());
905904

@@ -1001,6 +1000,7 @@ mod tests {
10011000
unexpanded_attribute_macros: Vec::new(),
10021001
mod_dirs: FxHashMap::default(),
10031002
cfg_options: &CfgOptions::default(),
1003+
proc_macros: Default::default(),
10041004
};
10051005
collector.collect();
10061006
collector.def_map

crates/ra_hir_ty/src/tests/macros.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,10 @@ mod clone {
642642

643643
#[test]
644644
fn infer_custom_derive_simple() {
645+
// FIXME: this test current now do nothing
645646
let (db, pos) = TestDB::with_position(
646647
r#"
647-
//- /main.rs crate:main deps:foo
648+
//- /main.rs crate:main
648649
use foo::Foo;
649650
650651
#[derive(Foo)]
@@ -653,11 +654,6 @@ struct S{}
653654
fn test() {
654655
S{}<|>;
655656
}
656-
657-
//- /lib.rs crate:foo
658-
#[proc_macro_derive(Foo)]
659-
pub fn derive_foo(_item: TokenStream) -> TokenStream {
660-
}
661657
"#,
662658
);
663659
assert_eq!("S", type_at_pos(&db, pos));

0 commit comments

Comments
 (0)