Rollup merge of #62388 - rust-lang:fix-loop-break-mir-generation, r=eddyb

Break out of the correct number of scopes in loops

We were incorrectly breaking out of one too many drop scopes when
generating MIR for loops and breakable blocks, resulting in use after
free and associated borrow checker warnings.

This wasn't noticed because the scope that we're breaking out of twice
is only used for temporaries that are created for adjustments applied to
the loop. Since loops generally propagate coercions to the `break`
expressions, the only case we see this is when the type of the loop is a
smart pointer to a trait object.

Closes #62312
This commit is contained in:
Mazdak Farrokhzad 2019-07-05 13:53:13 +02:00 committed by GitHub
commit 18081890ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 21 deletions

View file

@ -0,0 +1,16 @@
// Regression test for #62312
// check-pass
// edition:2018
#![feature(async_await)]
async fn make_boxed_object() -> Box<dyn Send> {
Box::new(()) as _
}
async fn await_object() {
let _ = make_boxed_object().await;
}
fn main() {}

View file

@ -0,0 +1,8 @@
// Regression test for #62312
// check-pass
fn main() {
let _ = loop {
break Box::new(()) as Box<dyn Send>;
};
}