From: Nick Cameron Date: Mon, 16 Jan 2017 23:01:10 +0000 (+1300) Subject: Fix bug in identifying comments X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;ds=sidebyside;h=29e89136957b9eedf54255c8059f8a51fbd82a68;p=rust.git Fix bug in identifying comments Fixes 1233 --- diff --git a/src/expr.rs b/src/expr.rs index 9794ff78093..2fc6b8b86d2 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -359,9 +359,9 @@ pub fn rewrite_array<'a, I>(expr_iter: I, where I: Iterator { 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 }; diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 9caea864641..d9c2a771414 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -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, diff --git a/tests/source/comment.rs b/tests/source/comment.rs index 0f76f220582..bce05ff7a2a 100644 --- a/tests/source/comment.rs +++ b/tests/source/comment.rs @@ -9,6 +9,7 @@ fn test() { // comment // comment2 + // FIXME(1275) code(); /* leave this comment alone! * ok? */ diff --git a/tests/source/comment4.rs b/tests/source/comment4.rs index 38442a79360..6d8da3e5445 100644 --- a/tests/source/comment4.rs +++ b/tests/source/comment4.rs @@ -3,6 +3,7 @@ fn test() { // comment // comment2 + // FIXME(1275) code(); /* leave this comment alone! * ok? */ diff --git a/tests/target/comment.rs b/tests/target/comment.rs index 71ef6acf99a..9de4366b1c4 100644 --- a/tests/target/comment.rs +++ b/tests/target/comment.rs @@ -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 diff --git a/tests/target/comment4.rs b/tests/target/comment4.rs index ff71124f464..fd91b5462f5 100644 --- a/tests/target/comment4.rs +++ b/tests/target/comment4.rs @@ -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 diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index d2a736330f7..84f3cf89ba4 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -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 \