Trim leading asterisks from doc block comments

This is to handle a change in behaviour in current beta rustc
This commit is contained in:
Graham Esau 2020-09-21 09:55:31 +01:00
parent ac8dd4c368
commit 0c02525fb9
2 changed files with 25 additions and 5 deletions

View file

@ -32,7 +32,7 @@ fn merge_description_lines(doc: &str) -> Option<String> {
}
fn get_doc(attrs: &[Attribute]) -> Option<String> {
let doc = attrs
let attrs = attrs
.iter()
.filter_map(|attr| {
if !attr.path.is_ident("doc") {
@ -46,14 +46,31 @@ fn get_doc(attrs: &[Attribute]) -> Option<String> {
None
})
.collect::<Vec<_>>()
.collect::<Vec<_>>();
let mut lines = attrs
.iter()
.flat_map(|a| a.split('\n'))
.map(str::trim)
.skip_while(|s| *s == "")
.collect::<Vec<_>>()
.join("\n");
none_if_empty(doc)
.collect::<Vec<_>>();
if let Some(&"") = lines.last() {
lines.pop();
}
// Added for backward-compatibility, but perhaps we shouldn't do this
// https://github.com/rust-lang/rust/issues/32088
if lines.iter().all(|l| l.starts_with("*")) {
for line in lines.iter_mut() {
*line = line[1..].trim()
}
while let Some(&"") = lines.first() {
lines.remove(0);
}
};
none_if_empty(lines.join("\n"))
}
fn none_if_empty(s: String) -> Option<String> {