rust-lang / rust-lang/rust-clippy
needless_borrow suggestion doesn't go far enough
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
In this code:
fn main() {
let mut w = [42];
(&mut w[..]).copy_from_slice(&[43]);
println!("{:?}", &w);
}
clippy suggests as follows:
4 | (&mut w[..]).copy_from_slice(&[43]);
| ^^^^^^^^^^^^ help: change this to: `w[..]`
This is correct as far as it goes. But a better suggestion would be just w, implying
w.copy_from_slice(&[43]);
which also DTRT.
FTR, stable doesn't issue this lint in this situation at all. #8367 and #8355 may be relevant.
Version
rustcargo@zealot:/home/ian/Rustup/Arti/experiments$ rustc -Vv
rustc 1.60.0-nightly (a00e130da 2022-01-29)
binary: rustc
commit-hash: a00e130dae74a213338e2b095ec855156d8f3d8a
commit-date: 2022-01-29
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
rustcargo@zealot:/home/ian/Rustup/Arti/experiments$
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the needless_borrow example from the issue and inspect the lint's implementation and tests; no file or test path is named in the report. Compare the current suggestion with the requested w.copy_from_slice(&[43]) form, and review issues #8367 and #8355 for related context. Done means the lint suggests the shorter form where appropriate and its tests cover the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100