Open amircodota opened 1 month ago
Another example using loops:
pub fn serialize_to_buffer<F: serde::Serialize>(
mut buffer: &mut Vec<u8>,
iter: &[&str],
) {
for item in iter {
serde_json::to_writer(&mut buffer, &item).unwrap();
// ^ suggestion: remove &mut
// obviously this makes buffer get moved after first iteration
buffer.extend(b"\n");
}
}
minimal repro (playground) thanks to @jwiesler:
fn foo<T: std::io::Write>(_buffer: T) {}
fn bar(mut buffer: &mut Vec<u8>) {
foo(&mut buffer);
buffer.extend(b"\n");
}
Bisected this to this clippy update: https://github.com/rust-lang/rust/commit/72d8d8d9f91122c59601b52c7f495f4e4dc50e29
Running a bisect on the clippy repo now
Perhaps unsurprisingly, the first bad commit is 79a14dea86fe8e8f5588fb2a32f5b73f065529a3. I'm planning to look into this, but in case I get distracted and drop this, don't hesitate to ping me if you'd like to take over.
Summary
When I run clippy on the reproducer code I get
However, if I remove the borrow, I get
Reproducer
I tried this code:
In stable clippy this works fine.
In latest nightly I get the above error (in the summary).
Version
Additional Labels
No response