Skip to content

Commit

Permalink
Avoid trimming non whitespace characters.
Browse files Browse the repository at this point in the history
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 #374
  • Loading branch information
0ndorio authored and emilio committed Aug 8, 2019
1 parent 65958a5 commit 47e8317
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 28 deletions.
26 changes: 5 additions & 21 deletions src/bindgen/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,41 +252,25 @@ impl SynAttributeHelpers for [syn::Attribute] {
}

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

for attr in self {
if attr.style == syn::AttrStyle::Outer {
if let Some(syn::Meta::NameValue(syn::MetaNameValue {
ident,
lit: syn::Lit::Str(comment),
lit: syn::Lit::Str(content),
..
})) = attr.interpret_meta()
{
let name = ident.to_string();
if &*name == "doc" {
let text = comment.value();
raw_comment += &text;
raw_comment += "\n";
let text = content.value().trim().to_owned();
comment.push(text);
}
}
}
}

let mut comment_lines = Vec::new();
for raw in raw_comment.lines() {
let line = raw
.trim_start_matches(" ")
.trim_start_matches("//")
.trim_start_matches("///")
.trim_start_matches("/**")
.trim_start_matches("/*")
.trim_start_matches("*/")
.trim_start_matches("*")
.trim_end();

comment_lines.push(line.to_owned());
}

comment_lines
comment
}
}
10 changes: 9 additions & 1 deletion tests/expectations/both/documentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);
10 changes: 9 additions & 1 deletion tests/expectations/both/documentation.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ extern "C" {
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);

Expand Down
10 changes: 9 additions & 1 deletion tests/expectations/documentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);
10 changes: 9 additions & 1 deletion tests/expectations/documentation.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ extern "C" {
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);

Expand Down
10 changes: 9 additions & 1 deletion tests/expectations/documentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ extern "C" {
/// # Hint
///
/// Always ensure that everything is properly documented, even if you feel lazy.
/// Sometimes** it is also helpful to include some markdown formatting.
/// **Sometimes** it is also helpful to include some markdown formatting.
///
/// ////////////////////////////////////////////////////////////////////////////
///
/// # Attention
///
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
/// marker you need to add at least a single whitespace inbetween the tripple
/// slash doc-comment marker and the rest.
void root();

} // extern "C"
10 changes: 9 additions & 1 deletion tests/expectations/tag/documentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);
10 changes: 9 additions & 1 deletion tests/expectations/tag/documentation.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ extern "C" {
* # Hint
*
* Always ensure that everything is properly documented, even if you feel lazy.
* Sometimes** it is also helpful to include some markdown formatting.
* **Sometimes** it is also helpful to include some markdown formatting.
*
* ////////////////////////////////////////////////////////////////////////////
*
* # Attention
*
* Rust is going to trim all leading `/` symbols. If you want to use them as a
* marker you need to add at least a single whitespace inbetween the tripple
* slash doc-comment marker and the rest.
*/
void root(void);

Expand Down
8 changes: 8 additions & 0 deletions tests/rust/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
///
/// Always ensure that everything is properly documented, even if you feel lazy.
/// **Sometimes** it is also helpful to include some markdown formatting.
///
/// ////////////////////////////////////////////////////////////////////////////
///
/// # Attention
///
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
/// marker you need to add at least a single whitespace inbetween the tripple
/// slash doc-comment marker and the rest.
#[no_mangle]
pub extern "C" fn root() {
}

0 comments on commit 47e8317

Please sign in to comment.