about summary refs log tree commit diff
path: root/tests/ui/ergonomic-clones/closure/spawn-thread.rs
blob: 289d446c6e6f746ff429147176a3075132b151e4 (plain)
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
//@ revisions: edition2018 edition2024
//@ [edition2018] edition: 2018
//@ [edition2024] edition: 2024
//@ [edition2024] check-pass

#![feature(ergonomic_clones)]
#![allow(incomplete_features)]

use std::sync::Arc;

fn foo() {
    // The type is a tuple and doesn't implement UseCloned
    let x = (Arc::new("foo".to_owned()), Arc::new(vec![1, 2, 3]), Arc::new(1));
    for _ in 0..10 {
        let handler = std::thread::spawn(use || {
            //[edition2018]~^ ERROR use of moved value: `x` [E0382]
            drop((x.0, x.1, x.2));
        });
        handler.join().unwrap();
    }
}

fn bar() {
    let x = Arc::new("foo".to_owned());
    let y = Arc::new(vec![1, 2, 3]);
    let z = Arc::new(1);

    for _ in 0..10 {
        let handler = std::thread::spawn(use || {
            drop((x, y, z));
        });
        handler.join().unwrap();
    }
}

fn baz() {
    use std::sync::Arc;
    use std::thread;

    let five = Arc::new(5);

    for _ in 0..10 {
        let handler = thread::spawn(use || {
            println!("{five:?}");
        });
        handler.join().unwrap();
    }
}

fn main() {}