Skip to content

Commit 97d9e6b

Browse files
committed
Use the last line's width for indent width in rewriting missed span
to fix unindented comments
1 parent 2fb5aff commit 97d9e6b

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

src/missed_spans.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use Shape;
11+
use {Indent, Shape};
1212
use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
1313
use config::WriteMode;
1414
use syntax::codemap::{BytePos, Pos, Span};
@@ -169,11 +169,12 @@ impl<'a> FmtVisitor<'a> {
169169
self.config.comment_width(),
170170
self.config.max_width() - self.block_indent.width(),
171171
);
172+
let comment_indent = Indent::from_width(self.config, self.buffer.cur_offset());
172173

173174
self.buffer.push_str(&rewrite_comment(
174175
subslice,
175176
false,
176-
Shape::legacy(comment_width, self.block_indent),
177+
Shape::legacy(comment_width, comment_indent),
177178
self.config,
178179
).unwrap());
179180

tests/source/comment.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fn test() {
99
// comment
1010
// comment2
1111

12-
// FIXME(1275)
1312
code(); /* leave this comment alone!
1413
* ok? */
1514

tests/source/comment4.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ fn test() {
55
// comment
66
// comment2
77

8-
// FIXME(1275)
98
code(); /* leave this comment alone!
109
* ok? */
1110

tests/target/comment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ fn test() {
99
// comment
1010
// comment2
1111

12-
// FIXME(1275)
1312
code(); // leave this comment alone!
14-
// ok?
13+
// ok?
1514

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

3534
funk(); // dontchangeme
36-
// or me
35+
// or me
3736

3837
// #1388
3938
const EXCEPTION_PATHS: &'static [&'static str] = &[

tests/target/comment4.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ fn test() {
55
// comment
66
// comment2
77

8-
// FIXME(1275)
98
code(); /* leave this comment alone!
10-
* ok? */
9+
* ok? */
1110

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

3029
funk(); //dontchangeme
31-
// or me
30+
// or me
3231
}
3332

3433
/// test123

0 commit comments

Comments
 (0)