File: clone-impl.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (93 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// gate-test-coroutine_clone
// Verifies that non-static coroutines can be cloned/copied if all their upvars and locals held
// across awaits can be cloned/copied.
//@compile-flags: --diagnostic-width=300

#![feature(coroutines, coroutine_clone, stmt_expr_attributes)]

struct NonClone;

fn test1() {
    let copyable: u32 = 123;
    let gen_copy_0 = #[coroutine]
    move || {
        yield;
        drop(copyable);
    };
    check_copy(&gen_copy_0);
    check_clone(&gen_copy_0);
}

fn test2() {
    let copyable: u32 = 123;
    let gen_copy_1 = #[coroutine]
    move || {
        /*
        let v = vec!['a'];
        let n = NonClone;
        drop(v);
        drop(n);
        */
        yield;
        let v = vec!['a'];
        let n = NonClone;
        drop(n);
        drop(copyable);
    };
    check_copy(&gen_copy_1);
    check_clone(&gen_copy_1);
}

fn test3() {
    let clonable_0: Vec<u32> = Vec::new();
    let gen_clone_0 = #[coroutine]
    move || {
        let v = vec!['a'];
        yield;
        drop(v);
        drop(clonable_0);
    };
    check_copy(&gen_clone_0);
    //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
    //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
    check_clone(&gen_clone_0);
}

fn test4() {
    let clonable_1: Vec<u32> = Vec::new();
    let gen_clone_1 = #[coroutine]
    move || {
        let v = vec!['a'];
        /*
        let n = NonClone;
        drop(n);
        */
        yield;
        let n = NonClone;
        drop(n);
        drop(v);
        drop(clonable_1);
    };
    check_copy(&gen_clone_1);
    //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
    //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
    check_clone(&gen_clone_1);
}

fn test5() {
    let non_clonable: NonClone = NonClone;
    let gen_non_clone = #[coroutine]
    move || {
        yield;
        drop(non_clonable);
    };
    check_copy(&gen_non_clone);
    //~^ ERROR the trait bound `NonClone: Copy` is not satisfied
    check_clone(&gen_non_clone);
    //~^ ERROR the trait bound `NonClone: Clone` is not satisfied
}

fn check_copy<T: Copy>(_x: &T) {}
fn check_clone<T: Clone>(_x: &T) {}

fn main() {}