Merge pull request #2303 from topecongiro/issue-2296

Fix indent width bug when recovering comments
This commit is contained in:
Nick Cameron 2017-12-22 17:46:10 +13:00 committed by GitHub
commit 18c42f1ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View file

@ -210,21 +210,22 @@ impl<'a> FmtVisitor<'a> {
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
if fix_indent {
let comment_indent = if fix_indent {
if let Some('{') = last_char {
self.push_str("\n");
}
let indent_str = self.block_indent.to_string(self.config);
self.push_str(&indent_str);
self.block_indent
} else {
self.push_str(" ");
}
Indent::from_width(self.config, last_line_width(&self.buffer))
};
let comment_width = ::std::cmp::min(
self.config.comment_width(),
self.config.max_width() - self.block_indent.width(),
);
let comment_indent = Indent::from_width(self.config, last_line_width(&self.buffer));
let comment_shape = Shape::legacy(comment_width, comment_indent);
let comment_str = rewrite_comment(subslice, false, comment_shape, self.config)
.unwrap_or_else(|| String::from(subslice));

View file

@ -72,3 +72,14 @@ fn generic<T>(arg: T) -> &SomeType
}
});
}
// #2296
impl Foo {
// a comment
// on multiple lines
fn foo() {
// another comment
// on multiple lines
let x = true;
}
}

View file

@ -86,3 +86,14 @@ fn main() {
false => (),
});
}
// #2296
impl Foo {
// a comment
// on multiple lines
fn foo() {
// another comment
// on multiple lines
let x = true;
}
}