aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree/lower.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-16 22:42:54 +0000
committerGitHub <[email protected]>2020-12-16 22:42:54 +0000
commit785860bd171da1a18aed78a5020732831596cd78 (patch)
treeda9ac7abc2f426dbe2783aa7a2a29e57d17cddf8 /crates/hir_def/src/item_tree/lower.rs
parent067067a6c11bb5afda98f5af14bfdec4744e7812 (diff)
parent28b5334580e5814d102b006e310ca0d1f03cdd72 (diff)
Merge #6909
6909: Avoid querying attributes in item tree lowering r=jonas-schievink a=jonas-schievink ItemTree is per-file, so there is no unique crate associated with it. This means that it cannot know the active CfgOptions and thus couldn't handle `cfg_attr`. Prepare it for `cfg_attr`s by avoiding accessing attributes. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/item_tree/lower.rs')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs24
1 files changed, 2 insertions, 22 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index dd3409762..7de385ee8 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -539,39 +539,19 @@ impl Ctx {
539 539
540 fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> { 540 fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> {
541 let name = m.name().map(|it| it.as_name())?; 541 let name = m.name().map(|it| it.as_name())?;
542 let attrs = Attrs::new(m, &self.hygiene);
543
544 let ast_id = self.source_ast_id_map.ast_id(m); 542 let ast_id = self.source_ast_id_map.ast_id(m);
545 543
546 // FIXME: cfg_attr 544 let res = MacroRules { name, ast_id };
547 let export_attr = attrs.by_key("macro_export");
548
549 let is_export = export_attr.exists();
550 let is_local_inner = if is_export {
551 export_attr.tt_values().map(|it| &it.token_trees).flatten().any(|it| match it {
552 tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => {
553 ident.text.contains("local_inner_macros")
554 }
555 _ => false,
556 })
557 } else {
558 false
559 };
560
561 let is_builtin = attrs.by_key("rustc_builtin_macro").exists();
562 let res = MacroRules { name, is_export, is_builtin, is_local_inner, ast_id };
563 Some(id(self.data().macro_rules.alloc(res))) 545 Some(id(self.data().macro_rules.alloc(res)))
564 } 546 }
565 547
566 fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<MacroDef>> { 548 fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<MacroDef>> {
567 let name = m.name().map(|it| it.as_name())?; 549 let name = m.name().map(|it| it.as_name())?;
568 let attrs = Attrs::new(m, &self.hygiene);
569 550
570 let ast_id = self.source_ast_id_map.ast_id(m); 551 let ast_id = self.source_ast_id_map.ast_id(m);
571 let visibility = self.lower_visibility(m); 552 let visibility = self.lower_visibility(m);
572 553
573 let is_builtin = attrs.by_key("rustc_builtin_macro").exists(); 554 let res = MacroDef { name, ast_id, visibility };
574 let res = MacroDef { name, is_builtin, ast_id, visibility };
575 Some(id(self.data().macro_defs.alloc(res))) 555 Some(id(self.data().macro_defs.alloc(res)))
576 } 556 }
577 557