rust-lang / rust-lang/rust-clippy
Lint against RefCell::borrow/borrow_mut on &mut RefCell
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
On this code:
use std::cell::RefCell;
pub fn foo(x: &mut RefCell<i32>) {
*x.borrow_mut() += 1;
}
the lint would suggest to use get_mut() rather than borrow_mut(). (Same for borrow(), of course.)
Lint Name
unnecessary_runtime_borrow
Category
perf
Advantage
- Removes unnecessary run-time borrow tracking of
RefCell
Drawbacks
None that I know if
Example
See above.
Mutex and RwLock also have get_mut functions, so the same kind of lint could be added for them.
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 reviewing the proposed unnecessary_runtime_borrow lint and its Rust example, then inspect existing rust-clippy lint patterns for comparable APIs. Done means the lint identifies borrow() and borrow_mut() on &mut RefCell and suggests get_mut(), with the Mutex and RwLock cases resolved explicitly.
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
- 35/100