Skip to content

Commit 9333034

Browse files
committed
Update #[deriving] documentation.
Syntax and a few fixed bugs etc.
1 parent 486f60d commit 9333034

File tree

1 file changed

+28
-25
lines changed
  • src/libsyntax/ext/deriving/generic

1 file changed

+28
-25
lines changed

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
//! (e.g. `Option<T>`), the parameters are automatically given the
2222
//! current trait as a bound. (This includes separate type parameters
2323
//! 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`)
3125
//!
3226
//! The most important thing for implementers is the `Substructure` and
3327
//! `SubstructureFields` objects. The latter groups 5 possibilities of the
@@ -79,6 +73,15 @@
7973
//! enums (one for each variant). For empty struct and empty enum
8074
//! variants, it is represented as a count of 0.
8175
//!
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+
//!
8285
//! # Examples
8386
//!
8487
//! The following simplified `PartialEq` is used for in-code examples:
@@ -102,22 +105,22 @@
102105
//! When generating the `expr` for the `A` impl, the `SubstructureFields` is
103106
//!
104107
//! ```{.text}
105-
//! Struct(~[FieldInfo {
108+
//! Struct(vec![FieldInfo {
106109
//! span: <span of x>
107110
//! name: Some(<ident of x>),
108111
//! self_: <expr for &self.x>,
109-
//! other: ~[<expr for &other.x]
112+
//! other: vec![<expr for &other.x]
110113
//! }])
111114
//! ```
112115
//!
113116
//! For the `B` impl, called with `B(a)` and `B(b)`,
114117
//!
115118
//! ```{.text}
116-
//! Struct(~[FieldInfo {
119+
//! Struct(vec![FieldInfo {
117120
//! span: <span of `int`>,
118121
//! name: None,
119-
//! <expr for &a>
120-
//! ~[<expr for &b>]
122+
//! self_: <expr for &a>
123+
//! other: vec![<expr for &b>]
121124
//! }])
122125
//! ```
123126
//!
@@ -128,31 +131,31 @@
128131
//!
129132
//! ```{.text}
130133
//! EnumMatching(0, <ast::Variant for C0>,
131-
//! ~[FieldInfo {
134+
//! vec![FieldInfo {
132135
//! span: <span of int>
133136
//! name: None,
134137
//! self_: <expr for &a>,
135-
//! other: ~[<expr for &b>]
138+
//! other: vec![<expr for &b>]
136139
//! }])
137140
//! ```
138141
//!
139142
//! For `C1 {x}` and `C1 {x}`,
140143
//!
141144
//! ```{.text}
142145
//! EnumMatching(1, <ast::Variant for C1>,
143-
//! ~[FieldInfo {
146+
//! vec![FieldInfo {
144147
//! span: <span of x>
145148
//! name: Some(<ident of x>),
146149
//! self_: <expr for &self.x>,
147-
//! other: ~[<expr for &other.x>]
150+
//! other: vec![<expr for &other.x>]
148151
//! }])
149152
//! ```
150153
//!
151154
//! For `C0(a)` and `C1 {x}` ,
152155
//!
153156
//! ```{.text}
154157
//! EnumNonMatchingCollapsed(
155-
//! ~[<ident of self>, <ident of __arg_1>],
158+
//! vec![<ident of self>, <ident of __arg_1>],
156159
//! &[<ast::Variant for C0>, <ast::Variant for C1>],
157160
//! &[<ident for self index value>, <ident of __arg_1 index value>])
158161
//! ```
@@ -168,16 +171,16 @@
168171
//!
169172
//! ## Static
170173
//!
171-
//! A static method on the above would result in,
174+
//! A static method on the types above would result in,
172175
//!
173176
//! ```{.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>)]))
175178
//!
176-
//! StaticStruct(<ast::StructDef of B>, Unnamed(~[<span of x>]))
179+
//! StaticStruct(<ast::StructDef of B>, Unnamed(vec![<span of x>]))
177180
//!
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>)]))])
181184
//! ```
182185
183186
pub use self::StaticFields::*;
@@ -1378,8 +1381,8 @@ pub fn cs_fold<F>(use_foldl: bool,
13781381
/// process the collected results. i.e.
13791382
///
13801383
/// ```
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)])
13831386
/// ```
13841387
#[inline]
13851388
pub fn cs_same_method<F>(f: F,

0 commit comments

Comments
 (0)