Fix bug in identifying comments

Fixes 1233
This commit is contained in:
Nick Cameron 2017-01-17 12:01:10 +13:00
parent 0218a41d73
commit 29e8913695
7 changed files with 21 additions and 13 deletions

View 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 };

View File

@ -123,16 +123,20 @@ impl<'a> FmtVisitor<'a> {
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,

View File

@ -9,6 +9,7 @@ fn test() {
// comment
// comment2
// FIXME(1275)
code(); /* leave this comment alone!
* ok? */

View File

@ -3,6 +3,7 @@ fn test() {
// comment
// comment2
// FIXME(1275)
code(); /* leave this comment alone!
* ok? */

View 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

View 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

View 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 \