Skip to content

Commit d0d7a21

Browse files
ayazhafizcalebcartwright
authored andcommitted
Correctly indent skipped-over code
Closes rust-lang#4398
1 parent 5bdfdf9 commit d0d7a21

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/missed_spans.rs

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ impl<'a> FmtVisitor<'a> {
353353

354354
let remaining = snippet[status.line_start..subslice.len() + offset].trim();
355355
if !remaining.is_empty() {
356+
self.push_str(&self.block_indent.to_string(self.config));
356357
self.push_str(remaining);
357358
status.line_start = subslice.len() + offset;
358359
}

tests/source/issue-4398.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
impl Struct {
2+
/// Documentation for `foo`
3+
#[rustfmt::skip] // comment on why use a skip here
4+
pub fn foo(&self) {}
5+
}
6+
7+
impl Struct {
8+
/// Documentation for `foo`
9+
#[rustfmt::skip] // comment on why use a skip here
10+
pub fn foo(&self) {}
11+
}
12+
13+
/// Documentation for `Struct`
14+
#[rustfmt::skip] // comment
15+
impl Struct {
16+
/// Documentation for `foo`
17+
#[rustfmt::skip] // comment on why use a skip here
18+
pub fn foo(&self) {}
19+
}

tests/target/issue-4398.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
impl Struct {
2+
/// Documentation for `foo`
3+
#[rustfmt::skip] // comment on why use a skip here
4+
pub fn foo(&self) {}
5+
}
6+
7+
impl Struct {
8+
/// Documentation for `foo`
9+
#[rustfmt::skip] // comment on why use a skip here
10+
pub fn foo(&self) {}
11+
}
12+
13+
/// Documentation for `Struct`
14+
#[rustfmt::skip] // comment
15+
impl Struct {
16+
/// Documentation for `foo`
17+
#[rustfmt::skip] // comment on why use a skip here
18+
pub fn foo(&self) {}
19+
}

0 commit comments

Comments
 (0)