diff options
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r-- | crates/hir_def/src/attr.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index 7825290e6..98293aad3 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -15,7 +15,6 @@ use tt::Subtree; | |||
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | db::DefDatabase, | 17 | db::DefDatabase, |
18 | docs::Documentation, | ||
19 | item_tree::{ItemTreeId, ItemTreeNode}, | 18 | item_tree::{ItemTreeId, ItemTreeNode}, |
20 | nameres::ModuleSource, | 19 | nameres::ModuleSource, |
21 | path::ModPath, | 20 | path::ModPath, |
@@ -23,6 +22,22 @@ use crate::{ | |||
23 | AdtId, AttrDefId, Lookup, | 22 | AdtId, AttrDefId, Lookup, |
24 | }; | 23 | }; |
25 | 24 | ||
25 | /// Holds documentation | ||
26 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
27 | pub struct Documentation(Arc<str>); | ||
28 | |||
29 | impl Documentation { | ||
30 | pub fn as_str(&self) -> &str { | ||
31 | &self.0 | ||
32 | } | ||
33 | } | ||
34 | |||
35 | impl Into<String> for Documentation { | ||
36 | fn into(self) -> String { | ||
37 | self.as_str().to_owned() | ||
38 | } | ||
39 | } | ||
40 | |||
26 | #[derive(Default, Debug, Clone, PartialEq, Eq)] | 41 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
27 | pub struct Attrs { | 42 | pub struct Attrs { |
28 | entries: Option<Arc<[Attr]>>, | 43 | entries: Option<Arc<[Attr]>>, |
@@ -102,7 +117,7 @@ impl Attrs { | |||
102 | }, | 117 | }, |
103 | ); | 118 | ); |
104 | let mut attrs = owner.attrs().peekable(); | 119 | let mut attrs = owner.attrs().peekable(); |
105 | let entries = if attrs.peek().is_none() { | 120 | let entries = if attrs.peek().is_none() && docs.is_none() { |
106 | // Avoid heap allocation | 121 | // Avoid heap allocation |
107 | None | 122 | None |
108 | } else { | 123 | } else { |
@@ -154,7 +169,11 @@ impl Attrs { | |||
154 | .intersperse(&SmolStr::new_inline("\n")) | 169 | .intersperse(&SmolStr::new_inline("\n")) |
155 | // No FromIterator<SmolStr> for String | 170 | // No FromIterator<SmolStr> for String |
156 | .for_each(|s| docs.push_str(s.as_str())); | 171 | .for_each(|s| docs.push_str(s.as_str())); |
157 | if docs.is_empty() { None } else { Some(docs) }.map(|it| Documentation::new(&it)) | 172 | if docs.is_empty() { |
173 | None | ||
174 | } else { | ||
175 | Some(Documentation(docs.into())) | ||
176 | } | ||
158 | } | 177 | } |
159 | } | 178 | } |
160 | 179 | ||