]> git.lizzy.rs Git - rust.git/commitdiff
Fix bug in identifying comments
authorNick Cameron <ncameron@mozilla.com>
Mon, 16 Jan 2017 23:01:10 +0000 (12:01 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 16 Jan 2017 23:01:10 +0000 (12:01 +1300)
Fixes 1233

src/expr.rs
src/missed_spans.rs
tests/source/comment.rs
tests/source/comment4.rs
tests/target/comment.rs
tests/target/comment4.rs
tests/target/multiple.rs

index 9794ff78093af4f2131a6900c03e2bbf70ac3839..2fc6b8b86d25a9759e28676af514fce3d74dd048 100644 (file)
@@ -359,9 +359,9 @@ pub fn rewrite_array<'a, I>(expr_iter: I,
     where I: Iterator<Item = &'a ast::Expr>
 {
     let bracket_size = if context.config.spaces_within_square_brackets {
-        2  // "[ "
+        2 // "[ "
     } else {
-        1  // "["
+        1 // "["
     };
     let offset = offset + bracket_size;
     let inner_context = &RewriteContext { block_indent: offset, ..*context };
index 9caea8646410ae1e137e55177a20ee72ef780495..d9c2a7714144099538ef1c54d12b5254c6e97edf 100644 (file)
@@ -123,16 +123,20 @@ fn replace_chars(string: &str) -> String {
 
                 let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
 
-                if rewrite_next_comment && fix_indent {
-                    if let Some('{') = last_char {
-                        self.buffer.push_str("\n");
+                if rewrite_next_comment {
+                    if fix_indent {
+                        if let Some('{') = last_char {
+                            self.buffer.push_str("\n");
+                        }
+                        self.buffer.push_str(&self.block_indent.to_string(self.config));
+                    } else {
+                        self.buffer.push_str(" ");
                     }
 
                     let comment_width = ::std::cmp::min(self.config.ideal_width,
                                                         self.config.max_width -
                                                         self.block_indent.width());
 
-                    self.buffer.push_str(&self.block_indent.to_string(self.config));
                     self.buffer.push_str(&rewrite_comment(subslice,
                                                           false,
                                                           comment_width,
index 0f76f22058270264e960fff881c915459a32cd40..bce05ff7a2a6f2ca8867d4970b9a1b8d579ba694 100644 (file)
@@ -9,6 +9,7 @@ fn test() {
 // comment
         // comment2
 
+    // FIXME(1275)
     code(); /* leave this comment alone!
              * ok? */
 
index 38442a79360c1085c6a647d8bfe71601a11ceeea..6d8da3e5445a341186b080e5d6f9511fd9e5a024 100644 (file)
@@ -3,6 +3,7 @@ fn test() {
 // comment
         // comment2
 
+    // FIXME(1275)
     code(); /* leave this comment alone!
              * ok? */
 
index 71ef6acf99a256b4f3ad200854e8318b22484bda..9de4366b1c495c0e3f679dda633e9a044038d02d 100644 (file)
@@ -9,8 +9,9 @@ fn test() {
     // comment
     // comment2
 
-    code(); /* leave this comment alone!
-             * ok? */
+    // FIXME(1275)
+    code(); // leave this comment alone!
+    // ok?
 
     // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
     // diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
@@ -31,8 +32,8 @@ fn test() {
     //                                       self.config)
     //                           .unwrap());
 
-    funk(); //dontchangeme
-            // or me
+    funk(); // dontchangeme
+    // or me
 }
 
 /// test123
index ff71124f464a533e08c1808a5199a2cec3878ce3..fd91b5462f5a0a73553ae217ea823ec5025d3037 100644 (file)
@@ -3,8 +3,9 @@ fn test() {
     // comment
     // comment2
 
+    // FIXME(1275)
     code(); /* leave this comment alone!
-             * ok? */
+     * ok? */
 
     /* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
      * diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
@@ -25,7 +26,7 @@ fn test() {
     //                           .unwrap());
 
     funk(); //dontchangeme
-            // or me
+    // or me
 }
 
 /// test123
index d2a736330f7a9b4b60605b68268a3ee1de23d7be..84f3cf89ba4750c6d2b5905c18ae380d70f92a61 100644 (file)
@@ -133,7 +133,7 @@ fn main() {
                        Cell::new(42usize,
                                  remaining_widthremaining_widthremaining_widthremaining_width),
                        42usize);
-    let rc = RefCell::new(42usize, remaining_width, remaining_width);  // a comment
+    let rc = RefCell::new(42usize, remaining_width, remaining_width); // a comment
     let x = "Hello!!!!!!!!! abcd  abcd abcd abcd abcd abcd\n abcd abcd abcd abcd abcd abcd abcd \
              abcd abcd abcd  abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd \
              abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd \