Skip to content

Commit b4b82a5

Browse files
0ndorioemilio
authored andcommitted
Preserve empty lines in doc comments.
This required two changes in parallel. As a first and obvious step it removes a check that skipped emptys lines during documentation loading, but it was also necessary to refactore the `get_comment_lines()` utility method as a second step. This second refactoring was necessary as each line in a doc comment is trimmed and transformed in its own doc attribute. The attribute of an empty line therefore contains an empty string as value. If we now call `lines()` on such an empty string we end up with an empty iterator as the method is internally configured to ignore trailing empty lines.
1 parent 65fbb25 commit b4b82a5

24 files changed

+191
-16
lines changed

src/bindgen/ir/documentation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Documentation {
2020
let doc = attrs
2121
.get_comment_lines()
2222
.into_iter()
23-
.filter(|x| !x.is_empty() && !x.starts_with("cbindgen:"))
23+
.filter(|x| !x.starts_with("cbindgen:"))
2424
.collect();
2525

2626
Documentation { doc_comment: doc }

src/bindgen/utilities.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl SynAttributeHelpers for [syn::Attribute] {
252252
}
253253

254254
fn get_comment_lines(&self) -> Vec<String> {
255-
let mut comment_lines = Vec::new();
255+
let mut raw_comment = String::new();
256256

257257
for attr in self {
258258
if attr.style == syn::AttrStyle::Outer {
@@ -263,26 +263,30 @@ impl SynAttributeHelpers for [syn::Attribute] {
263263
})) = attr.interpret_meta()
264264
{
265265
let name = ident.to_string();
266-
let comment = comment.value();
267-
268266
if &*name == "doc" {
269-
for raw in comment.lines() {
270-
let line = raw
271-
.trim_start_matches(" ")
272-
.trim_start_matches("//")
273-
.trim_start_matches("///")
274-
.trim_start_matches("/**")
275-
.trim_start_matches("/*")
276-
.trim_start_matches("*/")
277-
.trim_start_matches("*")
278-
.trim_end();
279-
comment_lines.push(line.to_owned());
280-
}
267+
let text = comment.value();
268+
raw_comment += &text;
269+
raw_comment += "\n";
281270
}
282271
}
283272
}
284273
}
285274

275+
let mut comment_lines = Vec::new();
276+
for raw in raw_comment.lines() {
277+
let line = raw
278+
.trim_start_matches(" ")
279+
.trim_start_matches("//")
280+
.trim_start_matches("///")
281+
.trim_start_matches("/**")
282+
.trim_start_matches("/*")
283+
.trim_start_matches("*/")
284+
.trim_start_matches("*")
285+
.trim_end();
286+
287+
comment_lines.push(line.to_owned());
288+
}
289+
286290
comment_lines
287291
}
288292
}

tests/expectations/associated_in_body.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct {

tests/expectations/associated_in_body.compat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct {

tests/expectations/associated_in_body.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <new>
55

66
/// Constants shared by multiple CSS Box Alignment properties
7+
///
78
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
89
struct StyleAlignFlags {
910
uint8_t bits;

tests/expectations/bitflags.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct {

tests/expectations/bitflags.compat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct {

tests/expectations/bitflags.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <new>
55

66
/// Constants shared by multiple CSS Box Alignment properties
7+
///
78
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
89
struct AlignFlags {
910
uint8_t bits;

tests/expectations/both/associated_in_body.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct StyleAlignFlags {

tests/expectations/both/associated_in_body.compat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* Constants shared by multiple CSS Box Alignment properties
8+
*
89
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
910
*/
1011
typedef struct StyleAlignFlags {

0 commit comments

Comments
 (0)