Skip to content

Commit f272123

Browse files
authored
refactor(doc): improve merge_inheritdoc docs and simplify cloning (#12517)
Update comment.rs
1 parent 853b653 commit f272123

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

crates/doc/src/parser/comment.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,18 @@ impl Comments {
121121
ref_fn!(pub fn contains_tag(&self, tag: &Comment) -> bool);
122122
ref_fn!(pub fn find_inheritdoc_base(&self) -> Option<&'_ str>);
123123

124-
/// Attempt to lookup
124+
/// Attempts to lookup inherited comments and merge them with the current collection.
125125
///
126-
/// Merges two comments collections by inserting [CommentTag] from the second collection
127-
/// into the first unless they are present.
126+
/// Looks up comments in `inheritdocs` using the key `{base}.{ident}` where `base` is
127+
/// extracted from an `@inheritdoc` tag. Merges the found comments by inserting
128+
/// [CommentTag] from the inherited collection into the current one unless they are
129+
/// already present.
128130
pub fn merge_inheritdoc(
129131
&self,
130132
ident: &str,
131133
inheritdocs: Option<HashMap<String, Self>>,
132134
) -> Self {
133-
let mut result = Self(Vec::from_iter(self.iter().cloned()));
135+
let mut result = self.clone();
134136

135137
if let (Some(inheritdocs), Some(base)) = (inheritdocs, self.find_inheritdoc_base()) {
136138
let key = format!("{base}.{ident}");

0 commit comments

Comments
 (0)