RefCell borrow is still alive across an .await

ID

rust.correctness.await_holding_refcell_ref

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Concurrency

Language

Rust

Description

This RefCell borrow is still in scope when the task suspends at the .await. Any other code that reaches the same cell while the task is suspended panics, because RefCell checks its borrow rules at run time. Copy out what is needed and end the borrow before the .await, or confine it to its own block.

Rationale

This RefCell borrow is still in scope when the task suspends at the .await. Any other code that reaches the same cell while the task is suspended panics, because RefCell checks its borrow rules at run time. Copy out what is needed and end the borrow before the .await, or confine it to its own block.

The following code illustrates the pattern detected by this rule:

use std::cell::RefCell;
use std::rc::Rc;
async fn persist(_value: u32) {}
pub async fn reader(cell: &RefCell<u32>) {
    // FLAGGED: `RefCell` borrow is still alive across an `.await`
    let value = cell.borrow();
    persist(*value).await;
    println!("{}", *value);
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved