Skip to content

await_holding_refcell_ref false negative when inside async block #6904

Open
@omni-corp

Description

@omni-corp

Example code

use std::cell::RefCell;
use std::future::Future;

#[allow(unused)]
async fn foo(x: &RefCell<u32>, bar: impl Future<Output=()>) {
    async {
        let mut y = x.borrow_mut();
        *y += 1;
        bar.await;
    }.await;
}

When running cargo clippy -- -W clippy::pedantic expected the warning this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await. Instead no warning is produced. Removing the async block produces the warning as expected.

Meta

cargo clippy -V:
clippy 0.1.52 (acca8189 2021-03-13)

rustc -Vv:

rustc 1.52.0-nightly (acca81892 2021-03-13)
binary: rustc
commit-hash: acca818928654807ed3bc1ce0e97df118f8716c8
commit-date: 2021-03-13
host: x86_64-pc-windows-msvc
release: 1.52.0-nightly

Activity

added
C-bugCategory: Clippy is not doing the correct thing
I-false-negativeIssue: The lint should have been triggered on code, but wasn't
on Mar 16, 2021
added
E-hardCall for participation: This a hard problem and requires more experience or effort to work on
on Mar 29, 2021
kellerb

kellerb commented on Mar 24, 2023

@kellerb

This false negative also occurs with await_holding_lock
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6e840ea9a1e3ce8231aa6c76db10b50f

async fn _hold_lock() {
    //async { // Uncomment this block and the clippy lint goes away
        let lock = parking_lot::Mutex::new(());
        let _guard = lock.lock();
        let () = async {}.await;
    //}.await
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @camsteffen@kellerb@giraffate@omni-corp

        Issue actions

          await_holding_refcell_ref false negative when inside async block · Issue #6904 · rust-lang/rust-clippy