]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/class-cast-to-trait.rs
Pin panic-in-drop=abort test to old pass manager
[rust.git] / src / test / ui / structs-enums / class-cast-to-trait.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_mut)]
4 #![allow(non_camel_case_types)]
5
6 // ignore-freebsd FIXME fails on BSD
7
8
9 trait noisy {
10   fn speak(&mut self);
11 }
12
13 struct cat {
14   meows: usize,
15   how_hungry: isize,
16   name: String,
17 }
18
19 impl noisy for cat {
20   fn speak(&mut self) { self.meow(); }
21 }
22
23 impl cat {
24   pub fn eat(&mut self) -> bool {
25     if self.how_hungry > 0 {
26         println!("OM NOM NOM");
27         self.how_hungry -= 2;
28         return true;
29     }
30     else {
31         println!("Not hungry!");
32         return false;
33     }
34   }
35 }
36
37 impl cat {
38     fn meow(&mut self) {
39       println!("Meow");
40       self.meows += 1;
41       if self.meows % 5 == 0 {
42           self.how_hungry += 1;
43       }
44     }
45 }
46
47 fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
48     cat {
49         meows: in_x,
50         how_hungry: in_y,
51         name: in_name
52     }
53 }
54
55
56 pub fn main() {
57     let mut nyan = cat(0, 2, "nyan".to_string());
58     let mut nyan: &mut dyn noisy = &mut nyan;
59     nyan.speak();
60 }