]> git.lizzy.rs Git - rust.git/commitdiff
save/restore `pessimistic_yield` when entering bodies
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 24 Mar 2020 19:20:19 +0000 (15:20 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 24 Mar 2020 19:25:43 +0000 (15:25 -0400)
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.

src/librustc_passes/region.rs
src/test/ui/async-await/issues/issue-69307.rs [new file with mode: 0644]

index e771696a5b6bf9678935529ad070d3178caef8c0..1807756fe524b75ae59470518ea744aaa93629ee 100644 (file)
@@ -720,6 +720,7 @@ fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
         let outer_ec = mem::replace(&mut self.expr_and_pat_count, 0);
         let outer_cx = self.cx;
         let outer_ts = mem::take(&mut self.terminating_scopes);
+        let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
         self.terminating_scopes.insert(body.value.hir_id.local_id);
 
         if let Some(root_id) = self.cx.root_id {
@@ -771,6 +772,7 @@ fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
         self.expr_and_pat_count = outer_ec;
         self.cx = outer_cx;
         self.terminating_scopes = outer_ts;
+        self.pessimistic_yield = outer_pessimistic_yield;
     }
 
     fn visit_arm(&mut self, a: &'tcx Arm<'tcx>) {
diff --git a/src/test/ui/async-await/issues/issue-69307.rs b/src/test/ui/async-await/issues/issue-69307.rs
new file mode 100644 (file)
index 0000000..4dae96e
--- /dev/null
@@ -0,0 +1,23 @@
+// Regression test for #69307
+//
+// Having a `async { .. foo.await .. }` block appear inside of a `+=`
+// expression was causing an ICE due to a failure to save/restore
+// state in the AST numbering pass when entering a nested body.
+//
+// check-pass
+// edition:2018
+
+fn block_on<F>(_: F) -> usize {
+    0
+}
+
+fn main() {}
+
+async fn bar() {
+    let mut sum = 0;
+    sum += block_on(async {
+        baz().await;
+    });
+}
+
+async fn baz() {}