From e70343a5f520c1a028336fc1ccd09479ef4084ae Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 25 Aug 2020 23:52:26 -0500 Subject: [PATCH] Correctly indent skipped-over code Closes #4398 --- src/missed_spans.rs | 1 + tests/source/issue-4398.rs | 19 +++++++++++++++++++ tests/target/issue-4398.rs | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/source/issue-4398.rs create mode 100644 tests/target/issue-4398.rs diff --git a/src/missed_spans.rs b/src/missed_spans.rs index e6889ae9786..17b11ed6cf4 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -353,6 +353,7 @@ fn process_missing_code( let remaining = snippet[status.line_start..subslice.len() + offset].trim(); if !remaining.is_empty() { + self.push_str(&self.block_indent.to_string(self.config)); self.push_str(remaining); status.line_start = subslice.len() + offset; } diff --git a/tests/source/issue-4398.rs b/tests/source/issue-4398.rs new file mode 100644 index 00000000000..b0095aaac79 --- /dev/null +++ b/tests/source/issue-4398.rs @@ -0,0 +1,19 @@ +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} + +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} + +/// Documentation for `Struct` +#[rustfmt::skip] // comment +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} diff --git a/tests/target/issue-4398.rs b/tests/target/issue-4398.rs new file mode 100644 index 00000000000..2ca894528e9 --- /dev/null +++ b/tests/target/issue-4398.rs @@ -0,0 +1,19 @@ +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} + +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} + +/// Documentation for `Struct` +#[rustfmt::skip] // comment +impl Struct { + /// Documentation for `foo` + #[rustfmt::skip] // comment on why use a skip here + pub fn foo(&self) {} +} -- 2.44.0