aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/attr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r--crates/ra_hir_def/src/attr.rs18
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
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::db::AstDatabase;
6use mbe::ast_to_token_tree; 5use mbe::ast_to_token_tree;
7use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
8use ra_syntax::{ 7use ra_syntax::{
@@ -11,7 +10,7 @@ use ra_syntax::{
11}; 10};
12use tt::Subtree; 11use tt::Subtree;
13 12
14use crate::{path::Path, HirFileId, Source}; 13use crate::{hygiene::Hygiene, path::Path};
15 14
16#[derive(Debug, Clone, PartialEq, Eq)] 15#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct Attr { 16pub struct Attr {
@@ -26,11 +25,8 @@ pub enum AttrInput {
26} 25}
27 26
28impl Attr { 27impl 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 {