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

View File

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

View File

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

View File

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

View File

@ -9,9 +9,8 @@ fn test() {
// comment // comment
// comment2 // comment2
// FIXME(1275)
code(); // leave this comment alone! code(); // leave this comment alone!
// ok? // ok?
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
// diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam // diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
@ -33,7 +32,7 @@ fn test() {
// .unwrap()); // .unwrap());
funk(); // dontchangeme funk(); // dontchangeme
// or me // or me
// #1388 // #1388
const EXCEPTION_PATHS: &'static [&'static str] = &[ const EXCEPTION_PATHS: &'static [&'static str] = &[

View File

@ -5,9 +5,8 @@ fn test() {
// comment // comment
// comment2 // comment2
// FIXME(1275)
code(); /* leave this comment alone! code(); /* leave this comment alone!
* ok? */ * ok? */
/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a /* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
* diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam * diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
@ -28,7 +27,7 @@ fn test() {
// .unwrap()); // .unwrap());
funk(); //dontchangeme funk(); //dontchangeme
// or me // or me
} }
/// test123 /// test123