]> git.lizzy.rs Git - rust.git/commitdiff
Improve comment rewriting with normalize_comments == false
authorest31 <MTest31@outlook.com>
Sat, 17 Sep 2016 01:20:00 +0000 (03:20 +0200)
committerest31 <MTest31@outlook.com>
Sat, 17 Sep 2016 01:41:11 +0000 (03:41 +0200)
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

src/comment.rs
tests/source/comment4.rs
tests/target/comment4.rs

index 979d3bef90e230aec9a58eadf5a85c465c7e22db..5a525f1bb23da4020479d75562ebd54deceb0de1 100644 (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)| {
index 81754f93c4c6feebb66347d635e6321730cf49b0..0ed18ca8da12a70cc417e7c80453380bd4afce79 100644 (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");
+}
+// */
index c4d25ca11435fe845cfd8ada45328699dbe0818c..910bade6c88f46620e149f8d286d5b418e35deec 100644 (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");
+}
+// */