Skip to content

Commit 9a88332

Browse files
bors[bot]Veykril
andauthored
Merge #6743
6743: Don't insert blank lines between doc attributes r=Veykril a=Veykril Fixes #6742. Doc attributes should be concatenated via a single linebreak as written in the [rustdoc book](https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html). Also changed the loop to use an iterator to get rid of the `docs.trim_end_matches("\n\n").to_owned()` part using `Itertools::intersperse`. Co-authored-by: Lukas Wirth <[email protected]>
2 parents 6df91a8 + 93262c7 commit 9a88332

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

crates/hir_def/src/docs.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use std::sync::Arc;
77

88
use either::Either;
9-
use syntax::ast;
9+
use itertools::Itertools;
10+
use syntax::{ast, SmolStr};
1011

1112
use crate::{
1213
db::DefDatabase,
@@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs(
9394
) -> Option<String> {
9495
match (doc_comment_text, doc_attr_text) {
9596
(Some(mut comment_text), Some(attr_text)) => {
96-
comment_text.push_str("\n\n");
97+
comment_text.push_str("\n");
9798
comment_text.push_str(&attr_text);
9899
Some(comment_text)
99100
}
@@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs(
105106

106107
fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> {
107108
let mut docs = String::new();
108-
for attr in owner.attrs() {
109-
if let Some(("doc", value)) =
110-
attr.as_simple_key_value().as_ref().map(|(k, v)| (k.as_str(), v.as_str()))
111-
{
112-
docs.push_str(value);
113-
docs.push_str("\n\n");
114-
}
115-
}
109+
owner
110+
.attrs()
111+
.filter_map(|attr| attr.as_simple_key_value().filter(|(key, _)| key == "doc"))
112+
.map(|(_, value)| value)
113+
.intersperse(SmolStr::new_inline("\n"))
114+
// No FromIterator<SmolStr> for String
115+
.for_each(|s| docs.push_str(s.as_str()));
116116
if docs.is_empty() {
117117
None
118118
} else {
119-
Some(docs.trim_end_matches("\n\n").to_owned())
119+
Some(docs)
120120
}
121121
}

crates/ide/src/hover.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,7 @@ fn foo() { let bar = Ba<|>r; }
15251525
---
15261526
15271527
bar docs 0
1528-
15291528
bar docs 1
1530-
15311529
bar docs 2
15321530
"#]],
15331531
);

0 commit comments

Comments
 (0)