rust-lang / rust-lang/rust-clippy
Suggest .as_ref() and .as_mut() instead of Some(ref ...) and Some(ref mut ...) patterns
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Suggests using .as_ref() and .as_mut() on Option to avoid using ref and ref mut in patterns.
Lint Name
useless_ref
Category
style, pedantic
Advantage
ref and ref mut patterns are rarely used comapred to as_ref(), so code using it is hard to read, especially for new contributors who never encountered these constructions.
Drawbacks
.as_ref() is slightly longer than ref
Example
let Some(ref x) = y;
let Some(ref mut x) = y;
Could be written as:
let Some(x) = y.as_ref();
let Some(x) = y.as_mut();
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 locating the Clippy implementation for the useless_ref lint and examining comparable pattern-rewriting lints. Use the issue’s Some(ref ...) and Some(ref mut ...) examples to define the cases that should receive suggestions, then add or update coverage so the lint recommends .as_ref() and .as_mut() without changing unrelated patterns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100