]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-rvalues-mutable.rs
Rollup merge of #106798 - scottmcm:signum-via-cmp, r=Mark-Simulacrum
[rust.git] / tests / ui / borrowck / borrowck-rvalues-mutable.rs
1 // run-pass
2
3 struct Counter {
4     value: usize
5 }
6
7 impl Counter {
8     fn new(v: usize) -> Counter {
9         Counter {value: v}
10     }
11
12     fn inc<'a>(&'a mut self) -> &'a mut Counter {
13         self.value += 1;
14         self
15     }
16
17     fn get(&self) -> usize {
18         self.value
19     }
20
21     fn get_and_inc(&mut self) -> usize {
22         let v = self.value;
23         self.value += 1;
24         v
25     }
26 }
27
28 pub fn main() {
29     let v = Counter::new(22).get_and_inc();
30     assert_eq!(v, 22);
31
32     let v = Counter::new(22).inc().inc().get();
33     assert_eq!(v, 24);
34 }