Skip to content

Commit a0875ed

Browse files
committed
fix: use byte length instead of char count
1 parent cf2e4fb commit a0875ed

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/fmt/src/state/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,13 @@ impl<'sess> State<'sess, '_> {
599599
// Doc comments preserve leading whitespaces (right after the prefix).
600600
self.word(prefix);
601601
let content = &line[prefix.len()..];
602-
let (leading_ws, rest) =
603-
content.split_at(content.chars().take_while(|&c| c.is_whitespace()).count());
602+
let (leading_ws, rest) = content.split_at(
603+
content
604+
.char_indices()
605+
.take_while(|(_, c)| c.is_whitespace())
606+
.last()
607+
.map_or(0, |(idx, c)| idx + c.len_utf8()),
608+
);
604609
if !leading_ws.is_empty() {
605610
self.word(leading_ws.to_owned());
606611
}

0 commit comments

Comments
 (0)