-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix drop-tracking ICE when a struct containing a field with a
Drop
…
…impl is used across an await Previously, drop-tracking would incorrectly assume the struct would be dropped immediately, which was not true: when the field had a type with a manual `Drop` impl, the drop becomes observable and has to be dropped after the await instead. For reasons I don't understand, this also fixes another error crater popped up related to type parameters. #98476
- Loading branch information
Showing
11 changed files
with
369 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// build-pass | ||
// edition:2018 | ||
// compile-flags: -Zdrop-tracking=y | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} | ||
|
||
async fn from_config(_: Config) {} | ||
|
||
async fn foo() { | ||
from_config(Config { | ||
nickname: None, | ||
..Default::default() | ||
}) | ||
.await; | ||
} | ||
|
||
#[derive(Default)] | ||
struct Config { | ||
nickname: Option<Box<u8>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/test/ui/async-await/issue-70935-complex-spans.normal.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// build-pass | ||
// edition:2018 | ||
// compile-flags: -Zdrop-tracking=y | ||
|
||
#![feature(generators)] | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} | ||
|
||
fn foo() { | ||
|| { | ||
yield drop(Config { | ||
nickname: NonCopy, | ||
b: NonCopy2, | ||
}.nickname); | ||
}; | ||
} | ||
|
||
#[derive(Default)] | ||
struct NonCopy; | ||
impl Drop for NonCopy { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
#[derive(Default)] | ||
struct NonCopy2; | ||
impl Drop for NonCopy2 { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
#[derive(Default)] | ||
struct Config { | ||
nickname: NonCopy, | ||
b: NonCopy2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// check-pass | ||
// compile-flags: --crate-type lib | ||
// edition:2018 | ||
|
||
fn assert_send<F: Send>(_: F) {} | ||
|
||
async fn __post<T>() -> T { | ||
if false { | ||
todo!() | ||
} else { | ||
async {}.await; | ||
todo!() | ||
} | ||
} | ||
|
||
fn foo<T>() { | ||
assert_send(__post::<T>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// build-pass | ||
// compile-flags:-Zdrop-tracking | ||
|
||
//! Like drop-tracking-parent-expression, but also tests that this doesn't ICE when building MIR | ||
#![feature(generators)] | ||
|
||
fn assert_send<T: Send>(_thing: T) {} | ||
|
||
#[derive(Default)] | ||
pub struct Client { pub nickname: String } | ||
|
||
fn main() { | ||
let g = move || match drop(Client { ..Client::default() }) { | ||
_status => yield, | ||
}; | ||
assert_send(g); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// compile-flags: -Zdrop-tracking | ||
#![feature(generators, negative_impls, rustc_attrs)] | ||
|
||
macro_rules! type_combinations { | ||
( | ||
$( $name:ident => { $( $tt:tt )* } );* $(;)? | ||
) => { $( | ||
mod $name { | ||
$( $tt )* | ||
|
||
impl !Sync for Client {} | ||
impl !Send for Client {} | ||
} | ||
|
||
// Struct update syntax. This fails because the Client used in the update is considered | ||
// dropped *after* the yield. | ||
{ | ||
let g = move || match drop($name::Client { ..$name::Client::default() }) { | ||
//~^ `significant_drop::Client` which is not `Send` | ||
//~| `insignificant_dtor::Client` which is not `Send` | ||
//~| `derived_drop::Client` which is not `Send` | ||
_ => yield, | ||
}; | ||
assert_send(g); | ||
//~^ ERROR cannot be sent between threads | ||
//~| ERROR cannot be sent between threads | ||
//~| ERROR cannot be sent between threads | ||
} | ||
|
||
// Simple owned value. This works because the Client is considered moved into `drop`, | ||
// even though the temporary expression doesn't end until after the yield. | ||
{ | ||
let g = move || match drop($name::Client::default()) { | ||
_ => yield, | ||
}; | ||
assert_send(g); | ||
} | ||
)* } | ||
} | ||
|
||
fn assert_send<T: Send>(_thing: T) {} | ||
|
||
fn main() { | ||
type_combinations!( | ||
// OK | ||
copy => { #[derive(Copy, Clone, Default)] pub struct Client; }; | ||
// NOT OK: MIR borrowck thinks that this is used after the yield, even though | ||
// this has no `Drop` impl and only the drops of the fields are observable. | ||
// FIXME: this should compile. | ||
derived_drop => { #[derive(Default)] pub struct Client { pub nickname: String } }; | ||
// NOT OK | ||
significant_drop => { | ||
#[derive(Default)] | ||
pub struct Client; | ||
impl Drop for Client { | ||
fn drop(&mut self) {} | ||
} | ||
}; | ||
// NOT OK (we need to agree with MIR borrowck) | ||
insignificant_dtor => { | ||
#[derive(Default)] | ||
#[rustc_insignificant_dtor] | ||
pub struct Client; | ||
impl Drop for Client { | ||
fn drop(&mut self) {} | ||
} | ||
}; | ||
); | ||
} |
Oops, something went wrong.