From 1b4778d0bcd6b7b7f7b44cbe25ca8ba95c4fabb0 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Tue, 5 Jun 2018 15:57:49 +0900 Subject: [PATCH] Handle code block with indented escapce character --- src/comment.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 4ca96f54c02..0a729c53127 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -505,9 +505,16 @@ fn hide_sharp_behind_comment<'a>(s: &'a str) -> Cow<'a, str> { } } -fn trim_custom_comment_prefix(s: String) -> String { +fn trim_custom_comment_prefix(s: &str) -> String { s.lines() - .map(|line| line.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX)) + .map(|line| { + let left_trimmed = line.trim_left(); + if left_trimmed.starts_with(RUSTFMT_CUSTOM_COMMENT_PREFIX) { + left_trimmed.trim_left_matches(RUSTFMT_CUSTOM_COMMENT_PREFIX) + } else { + line + } + }) .collect::>() .join("\n") }