Debian Codegraph @

gcc/testsuite/rust/compile/torture/traits10.rs

raw
1 #[lang = "sized"]
2 pub trait Sized {}
3
4 #[lang = "clone"]
5 pub trait Clone: Sized {
6 fn clone(&self) -> Self;
7
8 fn clone_from(&mut self, source: &Self) {
9 *self = source.clone()
10 }
11 }
12
13 mod impls {
14 use super::Clone;
15
16 macro_rules! impl_clone {
17 ($($t:ty)*) => {
18 $(
19 impl Clone for $t {
20 fn clone(&self) -> Self {
21 *self
22 }
23 }
24 )*
25 }
26 }
27
28 impl_clone! {
29 usize u8 u16 u32 u64 // u128
30 isize i8 i16 i32 i64 // i128
31 f32 f64
32 bool char
33 }
34 }
35
36 #[lang = "copy"]
37 pub trait Copy: Clone {
38 // Empty.
39 }
40
41 mod copy_impls {
42 use super::Copy;
43
44 macro_rules! impl_copy {
45 ($($t:ty)*) => {
46 $(
47 impl Copy for $t {}
48 )*
49 }
50 }
51
52 impl_copy! {
53 usize u8 u16 u32 u64 // u128
54 isize i8 i16 i32 i64 // i128
55 f32 f64
56 bool char
57 }
58 }
59
60 trait Foo
61 where
62 Self: Sized,
63 {
64 fn get(self) -> i32;
65
66 fn test(self) -> i32 {
67 self.get()
68 }
69 }
70
71 struct Bar(i32);
72 impl Foo for Bar {
73 fn get(self) -> i32 {
74 self.0
75 }
76 }
77
78 fn main() {
79 let a;
80 a = Bar(123);
81
82 let b;
83 b = Bar::get(a);
84
85 let a;
86 a = Bar(123);
87
88 let b;
89 b = a.test();
90 }