]> git.lizzy.rs Git - rust.git/blob - tests/ui/moves/move-fn-self-receiver.rs
Auto merge of #106520 - ehuss:update-mdbook, r=Mark-Simulacrum
[rust.git] / tests / ui / moves / move-fn-self-receiver.rs
1 use std::pin::Pin;
2 use std::rc::Rc;
3 use std::ops::Add;
4
5 struct Foo;
6
7 impl Add for Foo {
8     type Output = ();
9     fn add(self, _rhs: Self) -> () {}
10 }
11
12 impl Foo {
13     fn use_self(self) {}
14     fn use_box_self(self: Box<Self>) {}
15     fn use_pin_box_self(self: Pin<Box<Self>>) {}
16     fn use_rc_self(self: Rc<Self>) {}
17     fn use_mut_self(&mut self) -> &mut Self { self }
18 }
19
20 struct Container(Vec<bool>);
21
22 impl Container {
23     fn custom_into_iter(self) -> impl Iterator<Item = bool> {
24         self.0.into_iter()
25     }
26 }
27
28 fn move_out(val: Container) {
29     val.0.into_iter().next();
30     val.0; //~ ERROR use of moved
31
32     let foo = Foo;
33     foo.use_self();
34     foo; //~ ERROR use of moved
35
36     let second_foo = Foo;
37     second_foo.use_self();
38     second_foo; //~ ERROR use of moved
39
40     let boxed_foo = Box::new(Foo);
41     boxed_foo.use_box_self();
42     boxed_foo; //~ ERROR use of moved
43
44     let pin_box_foo = Box::pin(Foo);
45     pin_box_foo.use_pin_box_self();
46     pin_box_foo; //~ ERROR use of moved
47
48     let mut mut_foo = Foo;
49     let ret = mut_foo.use_mut_self();
50     mut_foo; //~ ERROR cannot move out
51     ret;
52
53     let rc_foo = Rc::new(Foo);
54     rc_foo.use_rc_self();
55     rc_foo; //~ ERROR use of moved
56
57     let foo_add = Foo;
58     foo_add + Foo;
59     foo_add; //~ ERROR use of moved
60
61     let implicit_into_iter = vec![true];
62     for _val in implicit_into_iter {}
63     implicit_into_iter; //~ ERROR use of moved
64
65     let explicit_into_iter = vec![true];
66     for _val in explicit_into_iter.into_iter() {}
67     explicit_into_iter; //~ ERROR use of moved
68
69     let container = Container(vec![]);
70     for _val in container.custom_into_iter() {}
71     container; //~ ERROR use of moved
72
73     let foo2 = Foo;
74     loop {
75         foo2.use_self(); //~ ERROR use of moved
76     }
77 }
78
79 fn main() {}