aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-12-19 00:09:48 +0000
committerJonas Schievink <[email protected]>2020-12-19 00:10:56 +0000
commitea5cc8d07ac28a2110b894d154468c3fa46d7040 (patch)
treed03e228616092a32a75c7c8af624d4e9c7f7fb2f /crates/hir_def/src/nameres
parentc7b7c37ea5f25806d8c523e309b7ee9be27f2cde (diff)
More accurate `#[derive]` parsing
This now allows full paths to the derive macro
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r--crates/hir_def/src/nameres/collector.rs28
1 files changed, 14 insertions, 14 deletions
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<'_, '_> {
1289 } 1289 }
1290 1290
1291 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) { 1291 fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) {
1292 for derive_subtree in attrs.by_key("derive").tt_values() { 1292 for derive in attrs.by_key("derive").attrs() {
1293 // for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree 1293 match derive.parse_derive() {
1294 for tt in &derive_subtree.token_trees { 1294 Some(derive_macros) => {
1295 let ident = match &tt { 1295 for path in derive_macros {
1296 tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => ident, 1296 let ast_id = AstIdWithPath::new(self.file_id, ast_id, path);
1297 tt::TokenTree::Leaf(tt::Leaf::Punct(_)) => continue, // , is ok 1297 self.def_collector
1298 _ => continue, // anything else would be an error (which we currently ignore) 1298 .unexpanded_attribute_macros
1299 }; 1299 .push(DeriveDirective { module_id: self.module_id, ast_id });
1300 let path = ModPath::from_tt_ident(ident); 1300 }
1301 1301 }
1302 let ast_id = AstIdWithPath::new(self.file_id, ast_id, path); 1302 None => {
1303 self.def_collector 1303 // FIXME: diagnose
1304 .unexpanded_attribute_macros 1304 log::debug!("malformed derive: {:?}", derive);
1305 .push(DeriveDirective { module_id: self.module_id, ast_id }); 1305 }
1306 } 1306 }
1307 } 1307 }
1308 } 1308 }