Closed
Description
Code
I tried this code:
use std::cell::RefCell;
fn main() {
}
async fn bug(ref_cell: &RefCell<Option<bool>>) {
let borrow = ref_cell.borrow();
if let Some(_) = borrow.as_ref() {
drop(borrow);
async {
}.await;
}
}
Note: The if let Some(_) = borrow.as_ref() { }
block is not necessary to reproduce (only its contents are needed), but this is how my actual code is structured, so I want to ensure it is considered
Playground link: here
I expected to see this compile without errors.
Instead, this happened:
warning: `Ref` held across a suspend point, but should not be
--> src/main.rs:9:9
|
9 | let borrow = ref_cell.borrow();
| ^^^^^^
...
13 | / async {
14 | |
15 | | }.await;
| |_______________- the value is held across this suspend point
|
= note: `#[warn(must_not_suspend)]` on by default
note: holding a Ref across suspend points can cause BorrowErrors
--> src/main.rs:9:9
|
9 | let borrow = ref_cell.borrow();
| ^^^^^^
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
--> src/main.rs:9:9
|
9 | let borrow = ref_cell.borrow();
| ^^^^^^
Version it worked on
It most recently worked on: 1.56.0 stable
Version with regression
rustc --version --verbose
:
1.58.0-nightly 2021-10-29 e99963c554e4d12010c2
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged