diff options
| author | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-05 09:13:28 +0100 |
|---|---|---|
| committer | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-11 09:32:08 +0000 |
| commit | cf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch) | |
| tree | 40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/generator/clone-impl-async.rs | |
| parent | ca855e6e42787ecd062d81d53336fe6788ef51a9 (diff) | |
| download | rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip | |
Move /src/test to /tests
Diffstat (limited to 'tests/ui/generator/clone-impl-async.rs')
| -rw-r--r-- | tests/ui/generator/clone-impl-async.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/ui/generator/clone-impl-async.rs b/tests/ui/generator/clone-impl-async.rs new file mode 100644 index 00000000000..9e9b59d3633 --- /dev/null +++ b/tests/ui/generator/clone-impl-async.rs @@ -0,0 +1,70 @@ +// 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 : Copy` is not satisfied + check_clone(&inner_non_clone); + //~^ ERROR : Clone` is not satisfied + + let non_clone = NonClone; + let outer_non_clone = async move { + drop(non_clone); + }; + check_copy(&outer_non_clone); + //~^ ERROR : Copy` is not satisfied + check_clone(&outer_non_clone); + //~^ ERROR : Clone` is not satisfied + + let maybe_copy_clone = async move {}; + check_copy(&maybe_copy_clone); + //~^ ERROR : Copy` is not satisfied + check_clone(&maybe_copy_clone); + //~^ ERROR : Clone` is not satisfied + + let inner_non_clone_fn = the_inner_non_clone_fn(); + check_copy(&inner_non_clone_fn); + //~^ ERROR : Copy` is not satisfied + check_clone(&inner_non_clone_fn); + //~^ ERROR : Clone` is not satisfied + + let outer_non_clone_fn = the_outer_non_clone_fn(NonClone); + check_copy(&outer_non_clone_fn); + //~^ ERROR : Copy` is not satisfied + check_clone(&outer_non_clone_fn); + //~^ ERROR : Clone` is not satisfied + + let maybe_copy_clone_fn = the_maybe_copy_clone_fn(); + check_copy(&maybe_copy_clone_fn); + //~^ ERROR : Copy` is not satisfied + check_clone(&maybe_copy_clone_fn); + //~^ ERROR : 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) {} |
