From 5da39b4a75400c43d878e66d6177510dd04c23cd Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Wed, 28 Dec 2022 18:29:01 -0500 Subject: [PATCH] Don't remove non-breaking space in block comment with bare lines Fixes 5638 Block comments with bare lines are those that have lines without leading `*` characters. When reformatting these comments we should be mindful not to remove leading non-breaking spaces (U+00A0). --- src/utils.rs | 5 ++++- tests/target/issue_5638.rs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/target/issue_5638.rs diff --git a/src/utils.rs b/src/utils.rs index a97bcba0bd2..1e63c574e13 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -597,7 +597,10 @@ pub(crate) fn trim_left_preserve_layout( trimmed = false; line } else { - line.trim().to_owned() + // use `is_ascii_whitespace` so we don't remove Non-breaking spaces + line.trim_start_matches(|c: char| c.is_ascii_whitespace()) + .trim_end() + .to_owned() }; trimmed_lines.push((trimmed, line, prefix_space_width)); diff --git a/tests/target/issue_5638.rs b/tests/target/issue_5638.rs new file mode 100644 index 00000000000..ce552adc0c6 --- /dev/null +++ b/tests/target/issue_5638.rs @@ -0,0 +1,4 @@ +/* + normal spaces +  non-breaking spaces +*/