Improve comment rewriting with normalize_comments == false

Only change multiline comments of the form

```rust
/*
 * Text
 */
```

while not affecting comments of the form

```rust
/*
Text
*/
```

when normalize_comments is off. In the first case,
we have a known character we can align against, while
we don't have one in the second case.

Before, we have converted the second form into the first,
but this is against the spirit of normalize_comments being
turned off.

Fixes #956
This commit is contained in:
est31 2016-09-17 03:20:00 +02:00
parent efd3e5c091
commit c6243c950e
3 changed files with 34 additions and 0 deletions

View File

@ -71,6 +71,16 @@ pub fn rewrite_comment(orig: &str,
let indent_str = offset.to_string(config);
let line_breaks = s.chars().filter(|&c| c == '\n').count();
let num_bare_lines = s.lines()
.enumerate()
.map(|(_, line)| line.trim())
.filter(|l| !(l.starts_with('*') || l.starts_with("//") || l.starts_with("/*")))
.count();
if num_bare_lines > 0 && !config.normalize_comments {
return Some(orig.to_owned());
}
let lines = s.lines()
.enumerate()
.map(|(i, mut line)| {

View File

@ -33,3 +33,15 @@ fn test() {
/// test123
fn doc_comment() {
}
/*
Regression test for issue #956
(some very important text)
*/
/*
fn debug_function() {
println!("hello");
}
// */

View File

@ -32,3 +32,15 @@ fn test() {
/// test123
fn doc_comment() {}
/*
Regression test for issue #956
(some very important text)
*/
/*
fn debug_function() {
println!("hello");
}
// */