Skip to content

Conversation

Nopey
Copy link

@Nopey Nopey commented Aug 3, 2025

This PR cleans up the clippy lints, allowing some and addressing others.

I am developing on x86_64 Windows, so there's a chance I've overlooked lints in platform-specific places such as the ARM NEON code.

I have intentionally left the following 6 clippy lints unsolved, as they are addressed in sibling PR #121. (click to expand)

(warning and error are repeated 3 times each)

warning: this expression borrows a value the compiler would automatically borrow
    --> src\mem.rs:2055:5
     |
2055 |     (&mut vec[..up_to]).copy_from_slice(head);
     |     ^^^^^^^^^^^^^^^^^^^ help: change this to: `vec[..up_to]`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
    --> src\lib.rs:3319:9
     |
3319 | /         let mut vec: Vec<u8> = Vec::with_capacity(
3320 | |             (checked_add(
3321 | |                 valid_up_to,
3322 | |                 encoder.max_buffer_length_from_utf8_if_no_unmappables(string.len() - valid_up_to),
...    |
3325 | |             .next_power_of_two(),
3326 | |         );
     | |__________^
3327 |           unsafe {
3328 |               vec.set_len(valid_up_to);
     |               ^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: initialize the buffer or wrap the content in `MaybeUninit`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec

warning: `encoding_rs` (lib) generated 6 warnings
error: could not compile `encoding_rs` (lib) due to 3 previous errors; 6 warnings emitted

Obsoletes open PR #78 ("Fix clippy lints") from 3 years ago.

Nopey added 10 commits August 2, 2025 18:54
These were inferred, but the nightly compiler now has a warning:
```
warning: lifetime flowing from input to output with different syntax can
be confusing
```
This warning advises rewriting many places where we check if there is at
least 1 byte in a read buffer as an is_empty() check, which seems like
bad advice here.
Alternative solutions include switching to a glob import, or removing
the unused imports entirely.
When this doc comment was first written in commit
2d67eca, there was some unsafe-- but
this is no longer the case.

Closes issue hsivonen#72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant