aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/attr.rs
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-30 10:47:17 +0100
committeruHOOCCOOHu <[email protected]>2019-10-02 19:28:02 +0100
commita49ad47e5afa5950f92b77badc6679295101328a (patch)
treedfb48fb37c1db1ecbcfb7bf75f5acf0f9023d29d /crates/ra_hir/src/attr.rs
parentd2ea776b8fbb5286a04dde75a9a8f8b14f12bfe9 (diff)
Support cfg attribute on impl blocks
Diffstat (limited to 'crates/ra_hir/src/attr.rs')
-rw-r--r--crates/ra_hir/src/attr.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs
index 19be6de32..84c36b8da 100644
--- a/crates/ra_hir/src/attr.rs
+++ b/crates/ra_hir/src/attr.rs
@@ -1,11 +1,14 @@
1use std::sync::Arc;
2
1use mbe::ast_to_token_tree; 3use mbe::ast_to_token_tree;
4use ra_cfg::CfgOptions;
2use ra_syntax::{ 5use ra_syntax::{
3 ast::{self, AstNode}, 6 ast::{self, AstNode, AttrsOwner},
4 SmolStr, 7 SmolStr,
5}; 8};
6use tt::Subtree; 9use tt::Subtree;
7 10
8use crate::{db::AstDatabase, path::Path, Source}; 11use crate::{db::AstDatabase, path::Path, HirFileId, Source};
9 12
10#[derive(Debug, Clone, PartialEq, Eq)] 13#[derive(Debug, Clone, PartialEq, Eq)]
11pub(crate) struct Attr { 14pub(crate) struct Attr {
@@ -40,6 +43,14 @@ impl Attr {
40 Some(Attr { path, input }) 43 Some(Attr { path, input })
41 } 44 }
42 45
46 pub(crate) fn from_attrs_owner(
47 file_id: HirFileId,
48 owner: &impl AttrsOwner,
49 db: &impl AstDatabase,
50 ) -> Arc<[Attr]> {
51 owner.attrs().flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect()
52 }
53
43 pub(crate) fn is_simple_atom(&self, name: &str) -> bool { 54 pub(crate) fn is_simple_atom(&self, name: &str) -> bool {
44 // FIXME: Avoid cloning 55 // FIXME: Avoid cloning
45 self.path.as_ident().map_or(false, |s| s.to_string() == name) 56 self.path.as_ident().map_or(false, |s| s.to_string() == name)
@@ -55,4 +66,8 @@ impl Attr {
55 None 66 None
56 } 67 }
57 } 68 }
69
70 pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> {
71 cfg_options.is_cfg_enabled(self.as_cfg()?)
72 }
58} 73}