Skip to content

Commit e7f8895

Browse files
committed
save/restore pessimistic_yield when entering bodies
This flag is used to make the execution order around `+=` operators pessimistic. Failure to save/restore the flag was causing independent async blocks to effect one another, leading to strange ICEs and failed assumptions.
1 parent 2dcf54f commit e7f8895

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustc_passes/region.rs

+2
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
720720
let outer_ec = mem::replace(&mut self.expr_and_pat_count, 0);
721721
let outer_cx = self.cx;
722722
let outer_ts = mem::take(&mut self.terminating_scopes);
723+
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
723724
self.terminating_scopes.insert(body.value.hir_id.local_id);
724725

725726
if let Some(root_id) = self.cx.root_id {
@@ -771,6 +772,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
771772
self.expr_and_pat_count = outer_ec;
772773
self.cx = outer_cx;
773774
self.terminating_scopes = outer_ts;
775+
self.pessimistic_yield = outer_pessimistic_yield;
774776
}
775777

776778
fn visit_arm(&mut self, a: &'tcx Arm<'tcx>) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Regression test for #69307
2+
//
3+
// Having a `async { .. foo.await .. }` block appear inside of a `+=`
4+
// expression was causing an ICE due to a failure to save/restore
5+
// state in the AST numbering pass when entering a nested body.
6+
//
7+
// check-pass
8+
// edition:2018
9+
10+
fn block_on<F>(_: F) -> usize {
11+
0
12+
}
13+
14+
fn main() {}
15+
16+
async fn bar() {
17+
let mut sum = 0;
18+
sum += block_on(async {
19+
baz().await;
20+
});
21+
}
22+
23+
async fn baz() {}

0 commit comments

Comments
 (0)