Trim leading asterisks from doc block comments
This is to handle a change in behaviour in current beta rustc
This commit is contained in:
parent
ac8dd4c368
commit
0c02525fb9
2 changed files with 25 additions and 5 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -15,10 +15,13 @@ jobs:
|
||||||
include:
|
include:
|
||||||
- rust: 1.36.0
|
- rust: 1.36.0
|
||||||
test_features: "--all-features"
|
test_features: "--all-features"
|
||||||
|
allow_failure: false
|
||||||
- rust: stable
|
- rust: stable
|
||||||
test_features: "--all-features"
|
test_features: "--all-features"
|
||||||
|
allow_failure: false
|
||||||
- rust: beta
|
- rust: beta
|
||||||
test_features: "--all-features"
|
test_features: "--all-features"
|
||||||
|
allow_failure: false
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
test_features: "--all-features"
|
test_features: "--all-features"
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn merge_description_lines(doc: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_doc(attrs: &[Attribute]) -> Option<String> {
|
fn get_doc(attrs: &[Attribute]) -> Option<String> {
|
||||||
let doc = attrs
|
let attrs = attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|attr| {
|
.filter_map(|attr| {
|
||||||
if !attr.path.is_ident("doc") {
|
if !attr.path.is_ident("doc") {
|
||||||
|
@ -46,14 +46,31 @@ fn get_doc(attrs: &[Attribute]) -> Option<String> {
|
||||||
|
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let mut lines = attrs
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|a| a.split('\n'))
|
.flat_map(|a| a.split('\n'))
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.skip_while(|s| *s == "")
|
.skip_while(|s| *s == "")
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>();
|
||||||
.join("\n");
|
|
||||||
none_if_empty(doc)
|
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> {
|
fn none_if_empty(s: String) -> Option<String> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue