diff options
author | Jonas Schievink <[email protected]> | 2020-12-19 00:09:48 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-19 00:10:56 +0000 |
commit | ea5cc8d07ac28a2110b894d154468c3fa46d7040 (patch) | |
tree | d03e228616092a32a75c7c8af624d4e9c7f7fb2f /crates/hir_def/src/nameres | |
parent | c7b7c37ea5f25806d8c523e309b7ee9be27f2cde (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.rs | 28 |
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 | } |