Lint against `Vec` deref in `Read::read`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the linked Rust Playground example and inspect how rust-clippy implements lints for calls to Read::read. The work is done when implicit Vec dereferencing at reader.read(&mut buf) is diagnosed and the suggestion uses reader.read(buf.as_mut_slice()), with tests covering the intended behavior.
Written by the indexing model from the issue text.
Description
What it does
As the title says, lint against implicit Vec deref in calls to Read::read.
Advantage
It is easy to mess up when using Read::read with a Vec as users may think that Read::read takes &mut Vec<u8> and therefore updates the len value of Vec, but instead it will return the number of bytes read. It also points users towards rethinking their usage of Vec, as the example could have the Vec replaced with a stack array for better performance. This will also help catch incorrect usages of Read::read, which use an empty Vec instead zero initializing.
Drawbacks
It may lint on correct code, but it recommends an easier to read version.
Example
The example should lint at reader.read(&mut buf) as buf is being implicitly dereferenced into &mut [u8].
It should suggest replacing the implicit deref with reader.read(buf.as_mut_slice()).
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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.
More from rust-lang/rust-clippy
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rust-clippy#17674 · 5 comments ·
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#17673 · 3 comments ·
-
C-bug I-false-positive
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rust-lang/rust-clippy#17566 ·
-
A-documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rust-lang/rust-clippy#17259 · 3 comments ·
-
A-documentation A-website C-bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#16981 · 1 reaction ·
All issues in rust-lang/rust-clippy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100