Fix indent issue when recovering comments

Closes #1989
This commit is contained in:
Seiichi Uchida 2017-12-10 17:41:02 +09:00
parent 414a995926
commit db29f9e0f7

View File

@ -154,21 +154,21 @@ impl<'a> FmtVisitor<'a> {
}
if status.rewrite_next_comment {
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, self.buffer.cur_offset());
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));