Fix clippy needless_late_init in txt_helpers (#2332)

Master fails `cargo clippy -- -D warnings` on lib_ccxr, so format_rust
is red on every open pull request regardless of what it changes. Authors
have been fixing it inside unrelated PRs to get their CI green, which
couples a one-line lint fix to whatever else they are working on.

Assign c_len from an if-expression instead of declaring it and filling
it in on each branch. Behaviour is identical.
This commit is contained in:
Carlos Fernandez Sanz
2026-09-05 14:58:33 -07:00
committed by GitHub
parent 982586e824
commit cf42e6cb05

View File

@@ -42,21 +42,21 @@ fn change_utf8_encoding(dest: &mut [u8], src: &[u8], len: i32, out_enc: Encoding
while src_idx < max {
let c = src[src_idx];
let c_len: usize;
if c < 0x80 {
c_len = 1;
// Leading-byte width. A byte that matches none of the UTF-8 lead
// patterns is consumed one at a time so the loop always advances.
let c_len: usize = if c < 0x80 {
1
} else if (c & 0x20) == 0 {
c_len = 2;
2
} else if (c & 0x10) == 0 {
c_len = 3;
3
} else if (c & 0x08) == 0 {
c_len = 4;
4
} else if (c & 0x04) == 0 {
c_len = 5;
5
} else {
c_len = 1;
}
1
};
match out_enc {
Encoding::UTF8 => {