-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix drop-tracking ICE when a struct containing a field with a significant drop is used across an await #98754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.