From b53aeebbcff40b91c1c19424db2393118a5ae335 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Wed, 19 Apr 2017 17:49:03 +0300 Subject: [PATCH] Fix line length calculation (should be in chars, not bytes) --- src/lib.rs | 2 +- tests/source/max-line-length-in-chars.rs | 4 ++++ tests/target/max-line-length-in-chars.rs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/source/max-line-length-in-chars.rs create mode 100644 tests/target/max-line-length-in-chars.rs diff --git a/src/lib.rs b/src/lib.rs index be4579faba2..ddee0cdc286 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -511,7 +511,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m last_wspace = None; } else { newline_count = 0; - line_len += c.len_utf8(); + line_len += 1; if c.is_whitespace() { if last_wspace.is_none() { last_wspace = Some(b); diff --git a/tests/source/max-line-length-in-chars.rs b/tests/source/max-line-length-in-chars.rs new file mode 100644 index 00000000000..d49fbb7e30e --- /dev/null +++ b/tests/source/max-line-length-in-chars.rs @@ -0,0 +1,4 @@ +// rustfmt-max_width: 25 + +// абвгдеёжзийклмнопрст +fn main() {} diff --git a/tests/target/max-line-length-in-chars.rs b/tests/target/max-line-length-in-chars.rs new file mode 100644 index 00000000000..d49fbb7e30e --- /dev/null +++ b/tests/target/max-line-length-in-chars.rs @@ -0,0 +1,4 @@ +// rustfmt-max_width: 25 + +// абвгдеёжзийклмнопрст +fn main() {}