From ea5cc8d07ac28a2110b894d154468c3fa46d7040 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 19 Dec 2020 01:09:48 +0100 Subject: More accurate `#[derive]` parsing This now allows full paths to the derive macro --- crates/hir_def/src/nameres/collector.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 55228e480..a636ec77d 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1289,20 +1289,20 @@ impl ModCollector<'_, '_> { } fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId) { - for derive_subtree in attrs.by_key("derive").tt_values() { - // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree - for tt in &derive_subtree.token_trees { - let ident = match &tt { - tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => ident, - tt::TokenTree::Leaf(tt::Leaf::Punct(_)) => continue, // , is ok - _ => continue, // anything else would be an error (which we currently ignore) - }; - let path = ModPath::from_tt_ident(ident); - - let ast_id = AstIdWithPath::new(self.file_id, ast_id, path); - self.def_collector - .unexpanded_attribute_macros - .push(DeriveDirective { module_id: self.module_id, ast_id }); + for derive in attrs.by_key("derive").attrs() { + match derive.parse_derive() { + Some(derive_macros) => { + for path in derive_macros { + let ast_id = AstIdWithPath::new(self.file_id, ast_id, path); + self.def_collector + .unexpanded_attribute_macros + .push(DeriveDirective { module_id: self.module_id, ast_id }); + } + } + None => { + // FIXME: diagnose + log::debug!("malformed derive: {:?}", derive); + } } } } -- cgit v1.2.3