Skip to content

Commit 47e8317

Browse files
0ndorioemilio
authored andcommitted
Avoid trimming non whitespace characters.
Rustc already removes all leading `/` symbols during the conversion from doc-comments into annotations. Any additional trimming of non whitespace characters just reduces the formatting flexibility of a comment. ... fixes mozilla#374
1 parent 65958a5 commit 47e8317

File tree

9 files changed

+76
-28
lines changed

9 files changed

+76
-28
lines changed

src/bindgen/utilities.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,41 +252,25 @@ impl SynAttributeHelpers for [syn::Attribute] {
252252
}
253253

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

257257
for attr in self {
258258
if attr.style == syn::AttrStyle::Outer {
259259
if let Some(syn::Meta::NameValue(syn::MetaNameValue {
260260
ident,
261-
lit: syn::Lit::Str(comment),
261+
lit: syn::Lit::Str(content),
262262
..
263263
})) = attr.interpret_meta()
264264
{
265265
let name = ident.to_string();
266266
if &*name == "doc" {
267-
let text = comment.value();
268-
raw_comment += &text;
269-
raw_comment += "\n";
267+
let text = content.value().trim().to_owned();
268+
comment.push(text);
270269
}
271270
}
272271
}
273272
}
274273

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-
290-
comment_lines
274+
comment
291275
}
292276
}

tests/expectations/both/documentation.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
* # Hint
1313
*
1414
* Always ensure that everything is properly documented, even if you feel lazy.
15-
* Sometimes** it is also helpful to include some markdown formatting.
15+
* **Sometimes** it is also helpful to include some markdown formatting.
16+
*
17+
* ////////////////////////////////////////////////////////////////////////////
18+
*
19+
* # Attention
20+
*
21+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
22+
* marker you need to add at least a single whitespace inbetween the tripple
23+
* slash doc-comment marker and the rest.
1624
*/
1725
void root(void);

tests/expectations/both/documentation.compat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ extern "C" {
1616
* # Hint
1717
*
1818
* Always ensure that everything is properly documented, even if you feel lazy.
19-
* Sometimes** it is also helpful to include some markdown formatting.
19+
* **Sometimes** it is also helpful to include some markdown formatting.
20+
*
21+
* ////////////////////////////////////////////////////////////////////////////
22+
*
23+
* # Attention
24+
*
25+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
26+
* marker you need to add at least a single whitespace inbetween the tripple
27+
* slash doc-comment marker and the rest.
2028
*/
2129
void root(void);
2230

tests/expectations/documentation.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
* # Hint
1313
*
1414
* Always ensure that everything is properly documented, even if you feel lazy.
15-
* Sometimes** it is also helpful to include some markdown formatting.
15+
* **Sometimes** it is also helpful to include some markdown formatting.
16+
*
17+
* ////////////////////////////////////////////////////////////////////////////
18+
*
19+
* # Attention
20+
*
21+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
22+
* marker you need to add at least a single whitespace inbetween the tripple
23+
* slash doc-comment marker and the rest.
1624
*/
1725
void root(void);

tests/expectations/documentation.compat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ extern "C" {
1616
* # Hint
1717
*
1818
* Always ensure that everything is properly documented, even if you feel lazy.
19-
* Sometimes** it is also helpful to include some markdown formatting.
19+
* **Sometimes** it is also helpful to include some markdown formatting.
20+
*
21+
* ////////////////////////////////////////////////////////////////////////////
22+
*
23+
* # Attention
24+
*
25+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
26+
* marker you need to add at least a single whitespace inbetween the tripple
27+
* slash doc-comment marker and the rest.
2028
*/
2129
void root(void);
2230

tests/expectations/documentation.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ extern "C" {
1313
/// # Hint
1414
///
1515
/// Always ensure that everything is properly documented, even if you feel lazy.
16-
/// Sometimes** it is also helpful to include some markdown formatting.
16+
/// **Sometimes** it is also helpful to include some markdown formatting.
17+
///
18+
/// ////////////////////////////////////////////////////////////////////////////
19+
///
20+
/// # Attention
21+
///
22+
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
23+
/// marker you need to add at least a single whitespace inbetween the tripple
24+
/// slash doc-comment marker and the rest.
1725
void root();
1826

1927
} // extern "C"

tests/expectations/tag/documentation.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
* # Hint
1313
*
1414
* Always ensure that everything is properly documented, even if you feel lazy.
15-
* Sometimes** it is also helpful to include some markdown formatting.
15+
* **Sometimes** it is also helpful to include some markdown formatting.
16+
*
17+
* ////////////////////////////////////////////////////////////////////////////
18+
*
19+
* # Attention
20+
*
21+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
22+
* marker you need to add at least a single whitespace inbetween the tripple
23+
* slash doc-comment marker and the rest.
1624
*/
1725
void root(void);

tests/expectations/tag/documentation.compat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ extern "C" {
1616
* # Hint
1717
*
1818
* Always ensure that everything is properly documented, even if you feel lazy.
19-
* Sometimes** it is also helpful to include some markdown formatting.
19+
* **Sometimes** it is also helpful to include some markdown formatting.
20+
*
21+
* ////////////////////////////////////////////////////////////////////////////
22+
*
23+
* # Attention
24+
*
25+
* Rust is going to trim all leading `/` symbols. If you want to use them as a
26+
* marker you need to add at least a single whitespace inbetween the tripple
27+
* slash doc-comment marker and the rest.
2028
*/
2129
void root(void);
2230

tests/rust/documentation.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
///
88
/// Always ensure that everything is properly documented, even if you feel lazy.
99
/// **Sometimes** it is also helpful to include some markdown formatting.
10+
///
11+
/// ////////////////////////////////////////////////////////////////////////////
12+
///
13+
/// # Attention
14+
///
15+
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
16+
/// marker you need to add at least a single whitespace inbetween the tripple
17+
/// slash doc-comment marker and the rest.
1018
#[no_mangle]
1119
pub extern "C" fn root() {
1220
}

0 commit comments

Comments
 (0)