]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/coverage/generics.rs
Merge remote-tracking branch 'origin/master' into mpk/add-long-error-message-for...
[rust.git] / src / test / run-make / coverage / generics.rs
1 #![allow(unused_assignments)]
2 // expect-exit-status-1
3
4 struct Firework<T> where T: Copy + std::fmt::Display {
5     strength: T,
6 }
7
8 impl<T> Firework<T> where T: Copy + std::fmt::Display {
9     #[inline(always)]
10     fn set_strength(&mut self, new_strength: T) {
11         self.strength = new_strength;
12     }
13 }
14
15 impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display {
16     #[inline(always)]
17     fn drop(&mut self) {
18         println!("BOOM times {}!!!", self.strength);
19     }
20 }
21
22 fn main() -> Result<(),u8> {
23     let mut firecracker = Firework { strength: 1 };
24     firecracker.set_strength(2);
25
26     let mut tnt = Firework { strength: 100.1 };
27     tnt.set_strength(200.1);
28     tnt.set_strength(300.3);
29
30     if true {
31         println!("Exiting with error...");
32         return Err(1);
33     }
34
35
36
37
38
39     let _ = Firework { strength: 1000 };
40
41     Ok(())
42 }
43
44 // Expected program output:
45 //   Exiting with error...
46 //   BOOM times 100!!!
47 //   BOOM times 1!!!
48 //   Error: 1