]> git.lizzy.rs Git - rust.git/blob - src/test/ui/self/self-in-mut-slot-default-method.rs
Rollup merge of #105955 - Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses...
[rust.git] / src / test / ui / self / self-in-mut-slot-default-method.rs
1 // run-pass
2
3 struct X {
4     a: isize
5 }
6
7 trait Changer : Sized {
8     fn change(mut self) -> Self {
9         self.set_to(55);
10         self
11     }
12
13     fn change_again(mut self: Box<Self>) -> Box<Self> {
14         self.set_to(45);
15         self
16     }
17
18     fn set_to(&mut self, a: isize);
19 }
20
21 impl Changer for X {
22     fn set_to(&mut self, a: isize) {
23         self.a = a;
24     }
25 }
26
27 pub fn main() {
28     let x = X { a: 32 };
29     let new_x = x.change();
30     assert_eq!(new_x.a, 55);
31
32     let x: Box<_> = Box::new(new_x);
33     let new_x = x.change_again();
34     assert_eq!(new_x.a, 45);
35 }