Skip to content

Commit d7f0d76

Browse files
ayazhafizcalebcartwright
authored andcommitted
Correctly indent skipped-over code
Closes #4398
1 parent f7ba2db commit d7f0d76

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Diff for: src/formatting/missed_spans.rs

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

323323
let remaining = snippet[status.line_start..subslice.len() + offset].trim();
324324
if !remaining.is_empty() {
325+
self.push_str(&self.block_indent.to_string(self.config));
325326
self.push_str(remaining);
326327
status.line_start = subslice.len() + offset;
327328
}

Diff for: 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+
}

Diff for: 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)