aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-07 15:12:53 +0000
committerGitHub <[email protected]>2020-12-07 15:12:53 +0000
commit9a88332452d661d4afea10f0063c893142e08019 (patch)
tree6c86ff943373b9e20f5c7cd877706aacacc9a505 /crates/hir_def
parent6df91a84dc129b13dc58db510e68c5eb04297087 (diff)
parent93262c750e65dcc58b9a87b9efdec55177269210 (diff)
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]>
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/docs.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/hir_def/src/docs.rs b/crates/hir_def/src/docs.rs
index e9a02b11b..3e59a8f47 100644
--- a/crates/hir_def/src/docs.rs
+++ b/crates/hir_def/src/docs.rs
@@ -6,7 +6,8 @@
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use either::Either; 8use either::Either;
9use syntax::ast; 9use itertools::Itertools;
10use syntax::{ast, SmolStr};
10 11
11use crate::{ 12use crate::{
12 db::DefDatabase, 13 db::DefDatabase,
@@ -93,7 +94,7 @@ fn merge_doc_comments_and_attrs(
93) -> Option<String> { 94) -> Option<String> {
94 match (doc_comment_text, doc_attr_text) { 95 match (doc_comment_text, doc_attr_text) {
95 (Some(mut comment_text), Some(attr_text)) => { 96 (Some(mut comment_text), Some(attr_text)) => {
96 comment_text.push_str("\n\n"); 97 comment_text.push_str("\n");
97 comment_text.push_str(&attr_text); 98 comment_text.push_str(&attr_text);
98 Some(comment_text) 99 Some(comment_text)
99 } 100 }
@@ -105,17 +106,16 @@ fn merge_doc_comments_and_attrs(
105 106
106fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> { 107fn expand_doc_attrs(owner: &dyn ast::AttrsOwner) -> Option<String> {
107 let mut docs = String::new(); 108 let mut docs = String::new();
108 for attr in owner.attrs() { 109 owner
109 if let Some(("doc", value)) = 110 .attrs()
110 attr.as_simple_key_value().as_ref().map(|(k, v)| (k.as_str(), v.as_str())) 111 .filter_map(|attr| attr.as_simple_key_value().filter(|(key, _)| key == "doc"))
111 { 112 .map(|(_, value)| value)
112 docs.push_str(value); 113 .intersperse(SmolStr::new_inline("\n"))
113 docs.push_str("\n\n"); 114 // No FromIterator<SmolStr> for String
114 } 115 .for_each(|s| docs.push_str(s.as_str()));
115 }
116 if docs.is_empty() { 116 if docs.is_empty() {
117 None 117 None
118 } else { 118 } else {
119 Some(docs.trim_end_matches("\n\n").to_owned()) 119 Some(docs)
120 } 120 }
121} 121}