-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't mark generators as
!Send
if a Copy + !Send
value is dropped…
… across a yield Copy types can neither read nor write their values when dropped (the language guarantees Drop is a no-op). So it doesn't make sense for them to make the generator non-Send.
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 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,12 @@ | ||
// edition:2018 | ||
// build-pass | ||
async fn trivial_drop() { | ||
let x: *const usize = &0; | ||
async {}.await; | ||
} | ||
|
||
fn assert_send<T: Send>(_: T) {} | ||
|
||
fn main() { | ||
assert_send(trivial_drop()); | ||
} |
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,15 @@ | ||
#![feature(generators, negative_impls)] | ||
|
||
fn assert_send<T: Send>(_: T) {} | ||
|
||
struct S; | ||
impl !Send for S {} | ||
|
||
fn main() { | ||
println!("{}", std::mem::needs_drop::<S>()); | ||
let g = || { | ||
let x = S; //~ type `S` | ||
yield; //~ `x` maybe used later | ||
}; | ||
assert_send(g); //~ ERROR generator cannot be sent between threads | ||
} |
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,24 @@ | ||
error: generator cannot be sent between threads safely | ||
--> $DIR/trivial-drop-non-copy.rs:14:5 | ||
| | ||
LL | assert_send(g); | ||
| ^^^^^^^^^^^ generator is not `Send` | ||
| | ||
= help: within `[generator@$DIR/trivial-drop-non-copy.rs:10:13: 10:15]`, the trait `Send` is not implemented for `S` | ||
note: generator is not `Send` as this value is used across a yield | ||
--> $DIR/trivial-drop-non-copy.rs:12:9 | ||
| | ||
LL | let x = S; | ||
| - has type `S` which is not `Send` | ||
LL | yield; | ||
| ^^^^^ yield occurs here, with `x` maybe used later | ||
LL | }; | ||
| - `x` is later dropped here | ||
note: required by a bound in `assert_send` | ||
--> $DIR/trivial-drop-non-copy.rs:3:19 | ||
| | ||
LL | fn assert_send<T: Send>(_: T) {} | ||
| ^^^^ required by this bound in `assert_send` | ||
|
||
error: aborting due to previous error | ||
|
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,12 @@ | ||
// build-pass | ||
#![feature(generators)] | ||
|
||
fn assert_send<T: Send>(_: T) {} | ||
|
||
fn main() { | ||
let g = || { | ||
let x: *const usize = &0; | ||
yield; | ||
}; | ||
assert_send(g); | ||
} |