From 1caaa201fa55caaedaa124d23934c178bdf15b18 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Dec 2020 18:49:03 +0100 Subject: Remove hir_def/docs.rs module --- crates/hir_def/src/attr.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/hir_def/src/attr.rs') 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; use crate::{ db::DefDatabase, - docs::Documentation, item_tree::{ItemTreeId, ItemTreeNode}, nameres::ModuleSource, path::ModPath, @@ -23,6 +22,22 @@ use crate::{ AdtId, AttrDefId, Lookup, }; +/// Holds documentation +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Documentation(Arc); + +impl Documentation { + pub fn as_str(&self) -> &str { + &self.0 + } +} + +impl Into for Documentation { + fn into(self) -> String { + self.as_str().to_owned() + } +} + #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct Attrs { entries: Option>, @@ -102,7 +117,7 @@ impl Attrs { }, ); let mut attrs = owner.attrs().peekable(); - let entries = if attrs.peek().is_none() { + let entries = if attrs.peek().is_none() && docs.is_none() { // Avoid heap allocation None } else { @@ -154,7 +169,11 @@ impl Attrs { .intersperse(&SmolStr::new_inline("\n")) // No FromIterator for String .for_each(|s| docs.push_str(s.as_str())); - if docs.is_empty() { None } else { Some(docs) }.map(|it| Documentation::new(&it)) + if docs.is_empty() { + None + } else { + Some(Documentation(docs.into())) + } } } -- cgit v1.2.3