Merge pull request #2303 from topecongiro/issue-2296
Fix indent width bug when recovering comments
This commit is contained in:
commit
18c42f1ab4
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user