Skip to content

Use the last line's width for indent width in rewriting missed span to fix unindented comments #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -169,11 +169,12 @@ impl<'a> FmtVisitor<'a> {
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());

Expand Down
6 changes: 1 addition & 5 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ impl<'a> FmtVisitor<'a> {
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)
}
Expand Down
1 change: 0 additions & 1 deletion tests/source/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fn test() {
// comment
// comment2

// FIXME(1275)
code(); /* leave this comment alone!
* ok? */

Expand Down
1 change: 0 additions & 1 deletion tests/source/comment4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn test() {
// comment
// comment2

// FIXME(1275)
code(); /* leave this comment alone!
* ok? */

Expand Down
5 changes: 2 additions & 3 deletions tests/target/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ fn test() {
// comment
// comment2

// FIXME(1275)
code(); // leave this comment alone!
// ok?
// ok?

// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
// diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
Expand All @@ -33,7 +32,7 @@ fn test() {
// .unwrap());

funk(); // dontchangeme
// or me
// or me

// #1388
const EXCEPTION_PATHS: &'static [&'static str] = &[
Expand Down
5 changes: 2 additions & 3 deletions tests/target/comment4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ fn test() {
// comment
// comment2

// FIXME(1275)
code(); /* leave this comment alone!
* ok? */
* ok? */

/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a
* diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
Expand All @@ -28,7 +27,7 @@ fn test() {
// .unwrap());

funk(); //dontchangeme
// or me
// or me
}

/// test123
Expand Down