diff options
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 248f03cdf..71f92adc2 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::db::AstDatabase; | ||
6 | use mbe::ast_to_token_tree; | 5 | use mbe::ast_to_token_tree; |
7 | use ra_cfg::CfgOptions; | 6 | use ra_cfg::CfgOptions; |
8 | use ra_syntax::{ | 7 | use ra_syntax::{ |
@@ -11,7 +10,7 @@ use ra_syntax::{ | |||
11 | }; | 10 | }; |
12 | use tt::Subtree; | 11 | use tt::Subtree; |
13 | 12 | ||
14 | use crate::{path::Path, HirFileId, Source}; | 13 | use crate::{hygiene::Hygiene, path::Path}; |
15 | 14 | ||
16 | #[derive(Debug, Clone, PartialEq, Eq)] | 15 | #[derive(Debug, Clone, PartialEq, Eq)] |
17 | pub struct Attr { | 16 | pub struct Attr { |
@@ -26,11 +25,8 @@ pub enum AttrInput { | |||
26 | } | 25 | } |
27 | 26 | ||
28 | impl Attr { | 27 | impl Attr { |
29 | pub(crate) fn from_src( | 28 | pub(crate) fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { |
30 | Source { file_id, ast }: Source<ast::Attr>, | 29 | let path = Path::from_src(ast.path()?, hygiene)?; |
31 | db: &impl AstDatabase, | ||
32 | ) -> Option<Attr> { | ||
33 | let path = Path::from_src(Source { file_id, ast: ast.path()? }, db)?; | ||
34 | let input = match ast.input() { | 30 | let input = match ast.input() { |
35 | None => None, | 31 | None => None, |
36 | Some(ast::AttrInput::Literal(lit)) => { | 32 | Some(ast::AttrInput::Literal(lit)) => { |
@@ -46,17 +42,13 @@ impl Attr { | |||
46 | Some(Attr { path, input }) | 42 | Some(Attr { path, input }) |
47 | } | 43 | } |
48 | 44 | ||
49 | pub fn from_attrs_owner( | 45 | pub fn from_attrs_owner(owner: &dyn AttrsOwner, hygiene: &Hygiene) -> Option<Arc<[Attr]>> { |
50 | file_id: HirFileId, | ||
51 | owner: &dyn AttrsOwner, | ||
52 | db: &impl AstDatabase, | ||
53 | ) -> Option<Arc<[Attr]>> { | ||
54 | let mut attrs = owner.attrs().peekable(); | 46 | let mut attrs = owner.attrs().peekable(); |
55 | if attrs.peek().is_none() { | 47 | if attrs.peek().is_none() { |
56 | // Avoid heap allocation | 48 | // Avoid heap allocation |
57 | return None; | 49 | return None; |
58 | } | 50 | } |
59 | Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect()) | 51 | Some(attrs.flat_map(|ast| Attr::from_src(ast, hygiene)).collect()) |
60 | } | 52 | } |
61 | 53 | ||
62 | pub fn is_simple_atom(&self, name: &str) -> bool { | 54 | pub fn is_simple_atom(&self, name: &str) -> bool { |