-
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.
Auto merge of #101673 - crlf0710:generator_clone, r=oli-obk
Allow generators to impl Clone/Copy Revives #95137. It's a pity that the original pr didn't land because the implementation is almost complete! All credits goes to `@canndrew,` and i just resolved the merge conflicts and updated the feature gate version number. r? `@oli-obk`
- Loading branch information
Showing
11 changed files
with
642 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
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
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,71 @@ | ||
// edition:2021 | ||
// gate-test-generator_clone | ||
// Verifies that feature(generator_clone) doesn't allow async blocks to be cloned/copied. | ||
|
||
#![feature(generators, generator_clone)] | ||
|
||
use std::future::ready; | ||
|
||
struct NonClone; | ||
|
||
fn main() { | ||
let inner_non_clone = async { | ||
let non_clone = NonClone; | ||
let () = ready(()).await; | ||
drop(non_clone); | ||
}; | ||
check_copy(&inner_non_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&inner_non_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
|
||
let non_clone = NonClone; | ||
let outer_non_clone = async move { | ||
drop(non_clone); | ||
}; | ||
check_copy(&outer_non_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&outer_non_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
|
||
let maybe_copy_clone = async move {}; | ||
check_copy(&maybe_copy_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&maybe_copy_clone); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
|
||
let inner_non_clone_fn = the_inner_non_clone_fn(); | ||
check_copy(&inner_non_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&inner_non_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
|
||
let outer_non_clone_fn = the_outer_non_clone_fn(NonClone); | ||
check_copy(&outer_non_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&outer_non_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
|
||
let maybe_copy_clone_fn = the_maybe_copy_clone_fn(); | ||
check_copy(&maybe_copy_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied | ||
check_clone(&maybe_copy_clone_fn); | ||
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied | ||
} | ||
|
||
async fn the_inner_non_clone_fn() { | ||
let non_clone = NonClone; | ||
let () = ready(()).await; | ||
drop(non_clone); | ||
} | ||
|
||
async fn the_outer_non_clone_fn(non_clone: NonClone) { | ||
let () = ready(()).await; | ||
drop(non_clone); | ||
} | ||
|
||
async fn the_maybe_copy_clone_fn() { | ||
} | ||
|
||
fn check_copy<T: Copy>(_x: &T) {} | ||
fn check_clone<T: Clone>(_x: &T) {} |
Oops, something went wrong.