]> git.lizzy.rs Git - rust.git/blob - src/test/ui/self/object-safety-sized-self-by-value-self.rs
Update ui tests
[rust.git] / src / test / ui / self / object-safety-sized-self-by-value-self.rs
1 // run-pass
2 #![allow(unused_mut)]
3 // Check that a trait is still object-safe (and usable) if it has
4 // methods with by-value self so long as they require `Self : Sized`.
5
6
7 trait Counter {
8     fn tick(&mut self) -> u32;
9     fn get(self) -> u32 where Self : Sized;
10 }
11
12 struct CCounter {
13     c: u32
14 }
15
16 impl Counter for CCounter {
17     fn tick(&mut self) -> u32 { self.c += 1; self.c }
18     fn get(self) -> u32 where Self : Sized { self.c }
19 }
20
21 fn tick1<C:Counter>(mut c: C) -> u32 {
22     tick2(&mut c);
23     c.get()
24 }
25
26 fn tick2(c: &mut dyn Counter) {
27     tick3(c);
28 }
29
30 fn tick3<C:?Sized+Counter>(c: &mut C) {
31     c.tick();
32     c.tick();
33 }
34
35 fn main() {
36     let mut c = CCounter { c: 0 };
37     let value = tick1(c);
38     assert_eq!(value, 2);
39 }