aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/attr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r--crates/hir_def/src/attr.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index 0171d8a92..a2479016e 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -95,13 +95,17 @@ impl ops::Deref for AttrsWithOwner {
95impl RawAttrs { 95impl RawAttrs {
96 pub(crate) const EMPTY: Self = Self { entries: None }; 96 pub(crate) const EMPTY: Self = Self { entries: None };
97 97
98 pub(crate) fn new(owner: &dyn ast::AttrsOwner, hygiene: &Hygiene) -> Self { 98 pub(crate) fn new(
99 db: &dyn DefDatabase,
100 owner: &dyn ast::AttrsOwner,
101 hygiene: &Hygiene,
102 ) -> Self {
99 let entries = collect_attrs(owner) 103 let entries = collect_attrs(owner)
100 .enumerate() 104 .enumerate()
101 .flat_map(|(i, attr)| { 105 .flat_map(|(i, attr)| {
102 let index = AttrId(i as u32); 106 let index = AttrId(i as u32);
103 match attr { 107 match attr {
104 Either::Left(attr) => Attr::from_src(attr, hygiene, index), 108 Either::Left(attr) => Attr::from_src(db, attr, hygiene, index),
105 Either::Right(comment) => comment.doc_comment().map(|doc| Attr { 109 Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
106 id: index, 110 id: index,
107 input: Some(AttrInput::Literal(SmolStr::new(doc))), 111 input: Some(AttrInput::Literal(SmolStr::new(doc))),
@@ -116,7 +120,7 @@ impl RawAttrs {
116 120
117 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn ast::AttrsOwner>) -> Self { 121 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn ast::AttrsOwner>) -> Self {
118 let hygiene = Hygiene::new(db.upcast(), owner.file_id); 122 let hygiene = Hygiene::new(db.upcast(), owner.file_id);
119 Self::new(owner.value, &hygiene) 123 Self::new(db, owner.value, &hygiene)
120 } 124 }
121 125
122 pub(crate) fn merge(&self, other: Self) -> Self { 126 pub(crate) fn merge(&self, other: Self) -> Self {
@@ -170,7 +174,7 @@ impl RawAttrs {
170 let attr = ast::Attr::parse(&format!("#[{}]", tree)).ok()?; 174 let attr = ast::Attr::parse(&format!("#[{}]", tree)).ok()?;
171 // FIXME hygiene 175 // FIXME hygiene
172 let hygiene = Hygiene::new_unhygienic(); 176 let hygiene = Hygiene::new_unhygienic();
173 Attr::from_src(attr, &hygiene, index) 177 Attr::from_src(db, attr, &hygiene, index)
174 }); 178 });
175 179
176 let cfg_options = &crate_graph[krate].cfg_options; 180 let cfg_options = &crate_graph[krate].cfg_options;
@@ -627,8 +631,13 @@ pub enum AttrInput {
627} 631}
628 632
629impl Attr { 633impl Attr {
630 fn from_src(ast: ast::Attr, hygiene: &Hygiene, id: AttrId) -> Option<Attr> { 634 fn from_src(
631 let path = Interned::new(ModPath::from_src(ast.path()?, hygiene)?); 635 db: &dyn DefDatabase,
636 ast: ast::Attr,
637 hygiene: &Hygiene,
638 id: AttrId,
639 ) -> Option<Attr> {
640 let path = Interned::new(ModPath::from_src(db, ast.path()?, hygiene)?);
632 let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() { 641 let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
633 let value = match lit.kind() { 642 let value = match lit.kind() {
634 ast::LiteralKind::String(string) => string.value()?.into(), 643 ast::LiteralKind::String(string) => string.value()?.into(),