rust-lang / rust-lang/rust-clippy

False positive for `await_holding_refcell_ref`

Open
#6,353 7 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-hard I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

I tried this code:

let mut state = self.state.borrow_mut();
let handles = state.cancel_all_in_flight();
drop(state);
let to_cancel = handles.len();
let cancelled = stream::iter(handles).then(|f| f).count().await;

I expected to see this happen: No error since the RefMut is explicitly dropped before the await

Instead, this happened: Brought up a warning

This happens in the recently promoted beta.

This should be pretty easy to fix. As a short term mitigation, I will downgrade the check from correctness and should hopefully be able to work on the fix next week.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied Rust example with the await_holding_refcell_ref lint enabled, then trace that lint's implementation and existing regression tests in rust-clippy. The fix is complete when an explicitly dropped RefMut before the await no longer produces the warning, while the lint still catches a borrow held across await.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.