rust-lang / rust-lang/rust-clippy
await_holding_borrow - like await_holding_lock, but for 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
This lint should warn users attempting to hold a RefCell's Ref or RefMut guards across an await point.
Advantage
Even in a single-threaded environment, external code can run during awaits. This code may attempt to borrow the same RefCell, causing a panic.
Drawbacks
Holding a borrow may be intentional, although it likely isn't.
Example
async {
let my_cell: RefCell<_> = /* divine it from somewhere */;
let my_borrow = my_cell.borrow();
some_future().await;
println!("The value is {}!", *my_borrow);
}
There is no trivial improvement to this code. Some examples of a fix might be
- moving the println! before the await;
- wrapping the value in an Rc, cloning it, and dropping the borrow before the await;
- or simply removing the borrow (and println!).
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 reading the existing await_holding_lock lint and its tests, then compare how RefCell Ref and RefMut guards are identified across an await point. Done means the lint warns for the described borrow patterns, covers the example cases, and avoids unrelated borrows.
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