Merge pull request #1947 from topecongiro/issue-1275

Use the last line's width for indent width in rewriting missed span to fix unindented comments
This commit is contained in:
Nick Cameron 2017-09-06 10:21:46 +12:00 committed by GitHub
commit 3b6a5fa881
6 changed files with 8 additions and 15 deletions

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use Shape;
use {Indent, Shape};
use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
use config::WriteMode;
use syntax::codemap::{BytePos, Pos, Span};
@ -169,11 +169,12 @@ fn replace_chars(string: &str) -> String {
self.config.comment_width(),
self.config.max_width() - self.block_indent.width(),
);
let comment_indent = Indent::from_width(self.config, self.buffer.cur_offset());
self.buffer.push_str(&rewrite_comment(
subslice,
false,
Shape::legacy(comment_width, self.block_indent),
Shape::legacy(comment_width, comment_indent),
self.config,
).unwrap());

View File

@ -72,11 +72,7 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
ast::StmtKind::Item(ref item) => {
self.visit_item(item);
}
ast::StmtKind::Local(..) => {
let rewrite = stmt.rewrite(&self.get_context(), self.shape());
self.push_rewrite(stmt.span(), rewrite);
}
ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => {
ast::StmtKind::Local(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => {
let rewrite = stmt.rewrite(&self.get_context(), self.shape());
self.push_rewrite(stmt.span(), rewrite)
}

View File

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

View File

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

View File

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

View File

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