|
21 | 21 | //! (e.g. `Option<T>`), the parameters are automatically given the |
22 | 22 | //! current trait as a bound. (This includes separate type parameters |
23 | 23 | //! and lifetimes for methods.) |
24 | | -//! - Additional bounds on the type parameters, e.g. the `Ord` instance |
25 | | -//! requires an explicit `PartialEq` bound at the |
26 | | -//! moment. (`TraitDef.additional_bounds`) |
27 | | -//! |
28 | | -//! Unsupported: FIXME #6257: calling methods on reference fields, |
29 | | -//! e.g. derive Eq/Ord/Clone don't work on `struct A(&int)`, |
30 | | -//! because of how the auto-dereferencing happens. |
| 24 | +//! - Additional bounds on the type parameters (`TraitDef.additional_bounds`) |
31 | 25 | //! |
32 | 26 | //! The most important thing for implementers is the `Substructure` and |
33 | 27 | //! `SubstructureFields` objects. The latter groups 5 possibilities of the |
|
79 | 73 | //! enums (one for each variant). For empty struct and empty enum |
80 | 74 | //! variants, it is represented as a count of 0. |
81 | 75 | //! |
| 76 | +//! # "`cs`" functions |
| 77 | +//! |
| 78 | +//! The `cs_...` functions ("combine substructure) are designed to |
| 79 | +//! make life easier by providing some pre-made recipes for common |
| 80 | +//! tasks; mostly calling the function being derived on all the |
| 81 | +//! arguments and then combining them back together in some way (or |
| 82 | +//! letting the user chose that). They are not meant to be the only |
| 83 | +//! way to handle the structures that this code creates. |
| 84 | +//! |
82 | 85 | //! # Examples |
83 | 86 | //! |
84 | 87 | //! The following simplified `PartialEq` is used for in-code examples: |
|
102 | 105 | //! When generating the `expr` for the `A` impl, the `SubstructureFields` is |
103 | 106 | //! |
104 | 107 | //! ```{.text} |
105 | | -//! Struct(~[FieldInfo { |
| 108 | +//! Struct(vec![FieldInfo { |
106 | 109 | //! span: <span of x> |
107 | 110 | //! name: Some(<ident of x>), |
108 | 111 | //! self_: <expr for &self.x>, |
109 | | -//! other: ~[<expr for &other.x] |
| 112 | +//! other: vec![<expr for &other.x] |
110 | 113 | //! }]) |
111 | 114 | //! ``` |
112 | 115 | //! |
113 | 116 | //! For the `B` impl, called with `B(a)` and `B(b)`, |
114 | 117 | //! |
115 | 118 | //! ```{.text} |
116 | | -//! Struct(~[FieldInfo { |
| 119 | +//! Struct(vec![FieldInfo { |
117 | 120 | //! span: <span of `int`>, |
118 | 121 | //! name: None, |
119 | | -//! <expr for &a> |
120 | | -//! ~[<expr for &b>] |
| 122 | +//! self_: <expr for &a> |
| 123 | +//! other: vec![<expr for &b>] |
121 | 124 | //! }]) |
122 | 125 | //! ``` |
123 | 126 | //! |
|
128 | 131 | //! |
129 | 132 | //! ```{.text} |
130 | 133 | //! EnumMatching(0, <ast::Variant for C0>, |
131 | | -//! ~[FieldInfo { |
| 134 | +//! vec![FieldInfo { |
132 | 135 | //! span: <span of int> |
133 | 136 | //! name: None, |
134 | 137 | //! self_: <expr for &a>, |
135 | | -//! other: ~[<expr for &b>] |
| 138 | +//! other: vec![<expr for &b>] |
136 | 139 | //! }]) |
137 | 140 | //! ``` |
138 | 141 | //! |
139 | 142 | //! For `C1 {x}` and `C1 {x}`, |
140 | 143 | //! |
141 | 144 | //! ```{.text} |
142 | 145 | //! EnumMatching(1, <ast::Variant for C1>, |
143 | | -//! ~[FieldInfo { |
| 146 | +//! vec![FieldInfo { |
144 | 147 | //! span: <span of x> |
145 | 148 | //! name: Some(<ident of x>), |
146 | 149 | //! self_: <expr for &self.x>, |
147 | | -//! other: ~[<expr for &other.x>] |
| 150 | +//! other: vec![<expr for &other.x>] |
148 | 151 | //! }]) |
149 | 152 | //! ``` |
150 | 153 | //! |
151 | 154 | //! For `C0(a)` and `C1 {x}` , |
152 | 155 | //! |
153 | 156 | //! ```{.text} |
154 | 157 | //! EnumNonMatchingCollapsed( |
155 | | -//! ~[<ident of self>, <ident of __arg_1>], |
| 158 | +//! vec![<ident of self>, <ident of __arg_1>], |
156 | 159 | //! &[<ast::Variant for C0>, <ast::Variant for C1>], |
157 | 160 | //! &[<ident for self index value>, <ident of __arg_1 index value>]) |
158 | 161 | //! ``` |
|
168 | 171 | //! |
169 | 172 | //! ## Static |
170 | 173 | //! |
171 | | -//! A static method on the above would result in, |
| 174 | +//! A static method on the types above would result in, |
172 | 175 | //! |
173 | 176 | //! ```{.text} |
174 | | -//! StaticStruct(<ast::StructDef of A>, Named(~[(<ident of x>, <span of x>)])) |
| 177 | +//! StaticStruct(<ast::StructDef of A>, Named(vec![(<ident of x>, <span of x>)])) |
175 | 178 | //! |
176 | | -//! StaticStruct(<ast::StructDef of B>, Unnamed(~[<span of x>])) |
| 179 | +//! StaticStruct(<ast::StructDef of B>, Unnamed(vec![<span of x>])) |
177 | 180 | //! |
178 | | -//! StaticEnum(<ast::EnumDef of C>, ~[(<ident of C0>, <span of C0>, Unnamed(~[<span of int>])), |
179 | | -//! (<ident of C1>, <span of C1>, |
180 | | -//! Named(~[(<ident of x>, <span of x>)]))]) |
| 181 | +//! StaticEnum(<ast::EnumDef of C>, |
| 182 | +//! vec![(<ident of C0>, <span of C0>, Unnamed(vec![<span of int>])), |
| 183 | +//! (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))]) |
181 | 184 | //! ``` |
182 | 185 |
|
183 | 186 | pub use self::StaticFields::*; |
@@ -1378,8 +1381,8 @@ pub fn cs_fold<F>(use_foldl: bool, |
1378 | 1381 | /// process the collected results. i.e. |
1379 | 1382 | /// |
1380 | 1383 | /// ``` |
1381 | | -/// f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1), |
1382 | | -/// self_2.method(__arg_1_2, __arg_2_2)]) |
| 1384 | +/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1), |
| 1385 | +/// self_2.method(__arg_1_2, __arg_2_2)]) |
1383 | 1386 | /// ``` |
1384 | 1387 | #[inline] |
1385 | 1388 | pub fn cs_same_method<F>(f: F, |
|
0 commit comments