blob: 86b0ea9db3cde14985decd0121857438278b41ca [file] [log] [blame]
David Tolnayb79ee962016-09-04 09:39:20 -07001use super::*;
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002use delimited::Delimited;
David Tolnayb79ee962016-09-04 09:39:20 -07003
Alex Crichton62a0a592017-05-22 13:58:53 -07004ast_enum_of_structs! {
David Tolnayc6b55bc2017-11-09 22:48:38 -08005 /// Things that can appear directly inside of a module.
6 pub enum Item {
David Tolnay570695e2017-06-03 16:15:13 -07007 /// An `extern crate` item, with optional original crate name.
Alex Crichton62a0a592017-05-22 13:58:53 -07008 ///
9 /// E.g. `extern crate foo` or `extern crate foo_bar as foo`
10 pub ExternCrate(ItemExternCrate {
David Tolnayc6b55bc2017-11-09 22:48:38 -080011 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070012 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070013 pub extern_token: tokens::Extern,
14 pub crate_token: tokens::Crate,
David Tolnay570695e2017-06-03 16:15:13 -070015 pub ident: Ident,
16 pub rename: Option<(tokens::As, Ident)>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070017 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -070018 }),
19 /// A use declaration (`use` or `pub use`) item.
20 ///
21 /// E.g. `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`
22 pub Use(ItemUse {
David Tolnayc6b55bc2017-11-09 22:48:38 -080023 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070024 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070025 pub use_token: tokens::Use,
Alex Crichton62a0a592017-05-22 13:58:53 -070026 pub path: Box<ViewPath>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070027 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -070028 }),
29 /// A static item (`static` or `pub static`).
30 ///
31 /// E.g. `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`
32 pub Static(ItemStatic {
David Tolnayc6b55bc2017-11-09 22:48:38 -080033 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070034 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070035 pub static_token: tokens::Static,
Alex Crichton62a0a592017-05-22 13:58:53 -070036 pub mutbl: Mutability,
David Tolnay570695e2017-06-03 16:15:13 -070037 pub ident: Ident,
38 pub colon_token: tokens::Colon,
39 pub ty: Box<Ty>,
40 pub eq_token: tokens::Eq,
Alex Crichton62a0a592017-05-22 13:58:53 -070041 pub expr: Box<Expr>,
David Tolnay570695e2017-06-03 16:15:13 -070042 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -070043 }),
44 /// A constant item (`const` or `pub const`).
45 ///
46 /// E.g. `const FOO: i32 = 42;`
47 pub Const(ItemConst {
David Tolnayc6b55bc2017-11-09 22:48:38 -080048 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070049 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070050 pub const_token: tokens::Const,
David Tolnay570695e2017-06-03 16:15:13 -070051 pub ident: Ident,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070052 pub colon_token: tokens::Colon,
Alex Crichton62a0a592017-05-22 13:58:53 -070053 pub ty: Box<Ty>,
David Tolnay570695e2017-06-03 16:15:13 -070054 pub eq_token: tokens::Eq,
Alex Crichton62a0a592017-05-22 13:58:53 -070055 pub expr: Box<Expr>,
David Tolnay570695e2017-06-03 16:15:13 -070056 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -070057 }),
58 /// A function declaration (`fn` or `pub fn`).
59 ///
60 /// E.g. `fn foo(bar: usize) -> usize { .. }`
61 pub Fn(ItemFn {
David Tolnayc6b55bc2017-11-09 22:48:38 -080062 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070063 pub vis: Visibility,
Alex Crichton62a0a592017-05-22 13:58:53 -070064 pub constness: Constness,
David Tolnay570695e2017-06-03 16:15:13 -070065 pub unsafety: Unsafety,
Alex Crichton62a0a592017-05-22 13:58:53 -070066 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -070067 pub decl: Box<FnDecl>,
68 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -070069 pub block: Box<Block>,
70 }),
71 /// A module declaration (`mod` or `pub mod`).
72 ///
73 /// E.g. `mod foo;` or `mod foo { .. }`
74 pub Mod(ItemMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -080075 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070076 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070077 pub mod_token: tokens::Mod,
David Tolnay570695e2017-06-03 16:15:13 -070078 pub ident: Ident,
79 pub content: Option<(tokens::Brace, Vec<Item>)>,
80 pub semi: Option<tokens::Semi>,
Alex Crichton62a0a592017-05-22 13:58:53 -070081 }),
82 /// An external module (`extern` or `pub extern`).
83 ///
84 /// E.g. `extern {}` or `extern "C" {}`
Alex Crichtonccbb45d2017-05-23 10:58:24 -070085 pub ForeignMod(ItemForeignMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -080086 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070087 pub abi: Abi,
David Tolnay570695e2017-06-03 16:15:13 -070088 pub brace_token: tokens::Brace,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070089 pub items: Vec<ForeignItem>,
90 }),
Alex Crichton62a0a592017-05-22 13:58:53 -070091 /// A type alias (`type` or `pub type`).
92 ///
93 /// E.g. `type Foo = Bar<u8>;`
94 pub Ty(ItemTy {
David Tolnayc6b55bc2017-11-09 22:48:38 -080095 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070096 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -070097 pub type_token: tokens::Type,
David Tolnay570695e2017-06-03 16:15:13 -070098 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -070099 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700100 pub eq_token: tokens::Eq,
101 pub ty: Box<Ty>,
102 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700103 }),
104 /// An enum definition (`enum` or `pub enum`).
105 ///
106 /// E.g. `enum Foo<A, B> { C<A>, D<B> }`
107 pub Enum(ItemEnum {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800108 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700109 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700110 pub enum_token: tokens::Enum,
David Tolnay570695e2017-06-03 16:15:13 -0700111 pub ident: Ident,
112 pub generics: Generics,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700113 pub brace_token: tokens::Brace,
114 pub variants: Delimited<Variant, tokens::Comma>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700115 }),
116 /// A struct definition (`struct` or `pub struct`).
117 ///
118 /// E.g. `struct Foo<A> { x: A }`
119 pub Struct(ItemStruct {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800120 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700121 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700122 pub struct_token: tokens::Struct,
David Tolnay570695e2017-06-03 16:15:13 -0700123 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700124 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700125 pub data: VariantData,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700126 pub semi_token: Option<tokens::Semi>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700127 }),
128 /// A union definition (`union` or `pub union`).
129 ///
130 /// E.g. `union Foo<A, B> { x: A, y: B }`
131 pub Union(ItemUnion {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800132 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700133 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700134 pub union_token: tokens::Union,
David Tolnay570695e2017-06-03 16:15:13 -0700135 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700136 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700137 pub data: VariantData,
Alex Crichton62a0a592017-05-22 13:58:53 -0700138 }),
139 /// A Trait declaration (`trait` or `pub trait`).
140 ///
141 /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }`
142 pub Trait(ItemTrait {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800143 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700144 pub vis: Visibility,
Alex Crichton62a0a592017-05-22 13:58:53 -0700145 pub unsafety: Unsafety,
David Tolnay570695e2017-06-03 16:15:13 -0700146 pub trait_token: tokens::Trait,
147 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700148 pub generics: Generics,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700149 pub colon_token: Option<tokens::Colon>,
150 pub supertraits: Delimited<TyParamBound, tokens::Add>,
151 pub brace_token: tokens::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700152 pub items: Vec<TraitItem>,
153 }),
154 /// Default trait implementation.
155 ///
156 /// E.g. `impl Trait for .. {}` or `impl<T> Trait<T> for .. {}`
157 pub DefaultImpl(ItemDefaultImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800158 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700159 pub unsafety: Unsafety,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700160 pub impl_token: tokens::Impl,
David Tolnay570695e2017-06-03 16:15:13 -0700161 pub path: Path,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700162 pub for_token: tokens::For,
163 pub dot2_token: tokens::Dot2,
164 pub brace_token: tokens::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700165 }),
166 /// An implementation.
167 ///
168 /// E.g. `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`
169 pub Impl(ItemImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800170 pub attrs: Vec<Attribute>,
Alex Crichtonf3d9ccc2017-08-28 09:40:13 -0700171 pub defaultness: Defaultness,
Alex Crichton62a0a592017-05-22 13:58:53 -0700172 pub unsafety: Unsafety,
David Tolnay570695e2017-06-03 16:15:13 -0700173 pub impl_token: tokens::Impl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700174 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700175 /// Trait this impl implements.
176 pub trait_: Option<(ImplPolarity, Path, tokens::For)>,
177 /// The Self type of the impl.
178 pub self_ty: Box<Ty>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700179 pub brace_token: tokens::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700180 pub items: Vec<ImplItem>,
181 }),
182 /// A macro invocation (which includes macro definition).
183 ///
184 /// E.g. `macro_rules! foo { .. }` or `foo!(..)`
David Tolnaydecf28d2017-11-11 11:56:45 -0800185 pub Macro(ItemMacro {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800186 pub attrs: Vec<Attribute>,
David Tolnay99a953d2017-11-11 12:51:43 -0800187 /// The `example` in `macro_rules! example { ... }`.
188 pub ident: Option<Ident>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800189 pub mac: Macro,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800190 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700191 }
David Tolnayb79ee962016-09-04 09:39:20 -0700192}
193
David Tolnay0e837402016-12-22 17:25:55 -0500194impl From<DeriveInput> for Item {
195 fn from(input: DeriveInput) -> Item {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800196 match input.body {
197 Body::Enum(data) => {
198 Item::Enum(ItemEnum {
199 attrs: input.attrs,
200 vis: input.vis,
201 enum_token: data.enum_token,
202 ident: input.ident,
203 generics: input.generics,
204 brace_token: data.brace_token,
205 variants: data.variants,
206 })
207 }
208 Body::Struct(data) => {
209 Item::Struct(ItemStruct {
210 attrs: input.attrs,
211 vis: input.vis,
212 struct_token: data.struct_token,
213 ident: input.ident,
214 generics: input.generics,
215 data: data.data,
216 semi_token: data.semi_token,
217 })
218 }
David Tolnay453cfd12016-10-23 11:00:14 -0700219 }
220 }
221}
222
Alex Crichton62a0a592017-05-22 13:58:53 -0700223ast_enum_of_structs! {
224 pub enum ViewPath {
225 /// `foo::bar::baz as quux`
226 ///
227 /// or just
228 ///
229 /// `foo::bar::baz` (with `as baz` implicitly on the right)
230 pub Simple(PathSimple {
231 pub path: Path,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700232 pub as_token: Option<tokens::As>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700233 pub rename: Option<Ident>,
234 }),
235
236 /// `foo::bar::*`
237 pub Glob(PathGlob {
238 pub path: Path,
Alex Crichtonaf9d2952017-08-27 10:19:54 -0700239 pub colon2_token: Option<tokens::Colon2>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700240 pub star_token: tokens::Star,
Alex Crichton62a0a592017-05-22 13:58:53 -0700241 }),
242
243 /// `foo::bar::{a, b, c}`
244 pub List(PathList {
245 pub path: Path,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700246 pub colon2_token: tokens::Colon2,
247 pub brace_token: tokens::Brace,
248 pub items: Delimited<PathListItem, tokens::Comma>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700249 }),
250 }
251}
252
253ast_struct! {
254 pub struct PathListItem {
255 pub name: Ident,
256 /// renamed in list, e.g. `use foo::{bar as baz};`
257 pub rename: Option<Ident>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700258 pub as_token: Option<tokens::As>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700259 }
260}
261
262ast_enum! {
Alex Crichton2e0229c2017-05-23 09:34:50 -0700263 #[cfg_attr(feature = "clone-impls", derive(Copy))]
Alex Crichton62a0a592017-05-22 13:58:53 -0700264 pub enum Constness {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700265 Const(tokens::Const),
Alex Crichton62a0a592017-05-22 13:58:53 -0700266 NotConst,
267 }
268}
269
270ast_enum! {
Alex Crichton2e0229c2017-05-23 09:34:50 -0700271 #[cfg_attr(feature = "clone-impls", derive(Copy))]
Alex Crichton62a0a592017-05-22 13:58:53 -0700272 pub enum Defaultness {
Alex Crichton954046c2017-05-30 21:49:42 -0700273 Default(tokens::Default_),
Alex Crichton62a0a592017-05-22 13:58:53 -0700274 Final,
275 }
276}
277
Alex Crichton62a0a592017-05-22 13:58:53 -0700278ast_enum_of_structs! {
279 /// An item within an `extern` block
David Tolnay8894f602017-11-11 12:11:04 -0800280 pub enum ForeignItem {
Alex Crichton62a0a592017-05-22 13:58:53 -0700281 /// A foreign function
282 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800283 pub attrs: Vec<Attribute>,
284 pub vis: Visibility,
285 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700286 pub decl: Box<FnDecl>,
David Tolnay8894f602017-11-11 12:11:04 -0800287 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700288 }),
289 /// A foreign static item (`static ext: u8`)
290 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800291 pub attrs: Vec<Attribute>,
292 pub vis: Visibility,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700293 pub static_token: tokens::Static,
Alex Crichton62a0a592017-05-22 13:58:53 -0700294 pub mutbl: Mutability,
David Tolnay8894f602017-11-11 12:11:04 -0800295 pub ident: Ident,
296 pub colon_token: tokens::Colon,
297 pub ty: Box<Ty>,
298 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700299 }),
300 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700301}
302
David Tolnayda705bd2017-11-10 21:58:05 -0800303ast_enum_of_structs! {
Alex Crichton62a0a592017-05-22 13:58:53 -0700304 /// Represents an item declaration within a trait declaration,
305 /// possibly including a default implementation. A trait item is
306 /// either required (meaning it doesn't have an implementation, just a
307 /// signature) or provided (meaning it has a default implementation).
David Tolnayda705bd2017-11-10 21:58:05 -0800308 pub enum TraitItem {
Alex Crichton62a0a592017-05-22 13:58:53 -0700309 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800310 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700311 pub const_token: tokens::Const,
David Tolnay570695e2017-06-03 16:15:13 -0700312 pub ident: Ident,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700313 pub colon_token: tokens::Colon,
Alex Crichton62a0a592017-05-22 13:58:53 -0700314 pub ty: Ty,
David Tolnay570695e2017-06-03 16:15:13 -0700315 pub default: Option<(tokens::Eq, Expr)>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700316 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700317 }),
318 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800319 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700320 pub sig: MethodSig,
321 pub default: Option<Block>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700322 pub semi_token: Option<tokens::Semi>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700323 }),
324 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800325 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700326 pub type_token: tokens::Type,
David Tolnay570695e2017-06-03 16:15:13 -0700327 pub ident: Ident,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700328 pub colon_token: Option<tokens::Colon>,
329 pub bounds: Delimited<TyParamBound, tokens::Add>,
David Tolnay570695e2017-06-03 16:15:13 -0700330 pub default: Option<(tokens::Eq, Ty)>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700331 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700332 }),
David Tolnaydecf28d2017-11-11 11:56:45 -0800333 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800334 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800335 pub mac: Macro,
David Tolnayda705bd2017-11-10 21:58:05 -0800336 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700337 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700338}
339
340ast_enum! {
Alex Crichton2e0229c2017-05-23 09:34:50 -0700341 #[cfg_attr(feature = "clone-impls", derive(Copy))]
Alex Crichton62a0a592017-05-22 13:58:53 -0700342 pub enum ImplPolarity {
343 /// `impl Trait for Type`
344 Positive,
345 /// `impl !Trait for Type`
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700346 Negative(tokens::Bang),
Alex Crichton62a0a592017-05-22 13:58:53 -0700347 }
348}
349
Alex Crichton62a0a592017-05-22 13:58:53 -0700350ast_enum_of_structs! {
David Tolnay857628c2017-11-11 12:25:31 -0800351 pub enum ImplItem {
Alex Crichton62a0a592017-05-22 13:58:53 -0700352 pub Const(ImplItemConst {
David Tolnay857628c2017-11-11 12:25:31 -0800353 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700354 pub vis: Visibility,
355 pub defaultness: Defaultness,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700356 pub const_token: tokens::Const,
David Tolnay570695e2017-06-03 16:15:13 -0700357 pub ident: Ident,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700358 pub colon_token: tokens::Colon,
Alex Crichton62a0a592017-05-22 13:58:53 -0700359 pub ty: Ty,
David Tolnay570695e2017-06-03 16:15:13 -0700360 pub eq_token: tokens::Eq,
Alex Crichton62a0a592017-05-22 13:58:53 -0700361 pub expr: Expr,
David Tolnay570695e2017-06-03 16:15:13 -0700362 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700363 }),
364 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800365 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700366 pub vis: Visibility,
367 pub defaultness: Defaultness,
Alex Crichton62a0a592017-05-22 13:58:53 -0700368 pub sig: MethodSig,
369 pub block: Block,
370 }),
371 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800372 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700373 pub vis: Visibility,
374 pub defaultness: Defaultness,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700375 pub type_token: tokens::Type,
David Tolnay570695e2017-06-03 16:15:13 -0700376 pub ident: Ident,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700377 pub eq_token: tokens::Eq,
Alex Crichton62a0a592017-05-22 13:58:53 -0700378 pub ty: Ty,
David Tolnay570695e2017-06-03 16:15:13 -0700379 pub semi_token: tokens::Semi,
Alex Crichton62a0a592017-05-22 13:58:53 -0700380 }),
David Tolnay857628c2017-11-11 12:25:31 -0800381 pub Macro(ImplItemMacro {
382 pub attrs: Vec<Attribute>,
383 pub mac: Macro,
384 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700385 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700386}
387
388ast_struct! {
389 /// Represents a method's signature in a trait declaration,
390 /// or in an implementation.
391 pub struct MethodSig {
Alex Crichton62a0a592017-05-22 13:58:53 -0700392 pub constness: Constness,
David Tolnay570695e2017-06-03 16:15:13 -0700393 pub unsafety: Unsafety,
Alex Crichton62a0a592017-05-22 13:58:53 -0700394 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700395 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700396 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700397 }
398}
399
400ast_struct! {
401 /// Header (not the body) of a function declaration.
David Tolnayf38cdf62016-09-23 19:07:09 -0700402 ///
Alex Crichton62a0a592017-05-22 13:58:53 -0700403 /// E.g. `fn foo(bar: baz)`
404 pub struct FnDecl {
Alex Crichton954046c2017-05-30 21:49:42 -0700405 pub fn_token: tokens::Fn_,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700406 pub paren_token: tokens::Paren,
407 pub inputs: Delimited<FnArg, tokens::Comma>,
David Tolnayf93b90d2017-11-11 19:21:26 -0800408 pub output: ReturnType,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700409 pub generics: Generics,
Alex Crichton62a0a592017-05-22 13:58:53 -0700410 pub variadic: bool,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700411 pub dot_tokens: Option<tokens::Dot3>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700412 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700413}
414
Alex Crichton62a0a592017-05-22 13:58:53 -0700415ast_enum_of_structs! {
416 /// An argument in a function header.
417 ///
418 /// E.g. `bar: usize` as in `fn foo(bar: usize)`
419 pub enum FnArg {
420 pub SelfRef(ArgSelfRef {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700421 pub and_token: tokens::And,
422 pub self_token: tokens::Self_,
Alex Crichton62a0a592017-05-22 13:58:53 -0700423 pub lifetime: Option<Lifetime>,
424 pub mutbl: Mutability,
425 }),
426 pub SelfValue(ArgSelf {
427 pub mutbl: Mutability,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700428 pub self_token: tokens::Self_,
Alex Crichton62a0a592017-05-22 13:58:53 -0700429 }),
430 pub Captured(ArgCaptured {
431 pub pat: Pat,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700432 pub colon_token: tokens::Colon,
Alex Crichton62a0a592017-05-22 13:58:53 -0700433 pub ty: Ty,
434 }),
435 pub Ignored(Ty),
436 }
David Tolnay62f374c2016-10-02 13:37:00 -0700437}
438
David Tolnayedf2b992016-09-23 20:43:45 -0700439#[cfg(feature = "parsing")]
440pub mod parsing {
441 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700442
Michael Layzell92639a52017-06-01 00:07:44 -0400443 use synom::Synom;
Alex Crichton954046c2017-05-30 21:49:42 -0700444 use synom::tokens::*;
445 use synom::tokens;
David Tolnay84aa0752016-10-02 23:01:13 -0700446
David Tolnay4c614be2017-11-10 00:02:38 -0800447 impl_synom!(Item "item" alt!(
448 syn!(ItemExternCrate) => { Item::ExternCrate }
449 |
450 syn!(ItemUse) => { Item::Use }
451 |
452 syn!(ItemStatic) => { Item::Static }
453 |
454 syn!(ItemConst) => { Item::Const }
455 |
456 syn!(ItemFn) => { Item::Fn }
457 |
458 syn!(ItemMod) => { Item::Mod }
459 |
460 syn!(ItemForeignMod) => { Item::ForeignMod }
461 |
462 syn!(ItemTy) => { Item::Ty }
463 |
464 syn!(ItemStruct) => { Item::Struct }
465 |
466 syn!(ItemEnum) => { Item::Enum }
467 |
468 syn!(ItemUnion) => { Item::Union }
469 |
470 syn!(ItemTrait) => { Item::Trait }
471 |
472 syn!(ItemDefaultImpl) => { Item::DefaultImpl }
473 |
474 syn!(ItemImpl) => { Item::Impl }
475 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800476 syn!(ItemMacro) => { Item::Macro }
David Tolnay4c614be2017-11-10 00:02:38 -0800477 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700478
David Tolnaydecf28d2017-11-11 11:56:45 -0800479 impl_synom!(ItemMacro "macro item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700480 attrs: many0!(call!(Attribute::parse_outer)) >>
481 what: syn!(Path) >>
482 bang: syn!(Bang) >>
David Tolnay570695e2017-06-03 16:15:13 -0700483 ident: option!(syn!(Ident)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700484 body: call!(::TokenTree::parse_delimited) >>
485 cond!(!body.is_braced(), syn!(Semi)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800486 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700487 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800488 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800489 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500490 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700491 bang_token: bang,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700492 tokens: vec![body],
David Tolnayc6b55bc2017-11-09 22:48:38 -0800493 },
David Tolnay4c614be2017-11-10 00:02:38 -0800494 })
David Tolnayedf2b992016-09-23 20:43:45 -0700495 ));
496
David Tolnay4c614be2017-11-10 00:02:38 -0800497 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700498 attrs: many0!(call!(Attribute::parse_outer)) >>
499 vis: syn!(Visibility) >>
500 extern_: syn!(Extern) >>
501 crate_: syn!(tokens::Crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700502 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700503 rename: option!(tuple!(syn!(As), syn!(Ident))) >>
504 semi: syn!(Semi) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800505 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700506 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800507 vis: vis,
508 extern_token: extern_,
509 crate_token: crate_,
510 ident: ident,
511 rename: rename,
512 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800513 })
David Tolnayedf2b992016-09-23 20:43:45 -0700514 ));
515
David Tolnay4c614be2017-11-10 00:02:38 -0800516 impl_synom!(ItemUse "use item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700517 attrs: many0!(call!(Attribute::parse_outer)) >>
518 vis: syn!(Visibility) >>
519 use_: syn!(Use) >>
520 what: syn!(ViewPath) >>
521 semi: syn!(Semi) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800522 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700523 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800524 vis: vis,
525 use_token: use_,
526 path: Box::new(what),
527 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800528 })
David Tolnay4a057422016-10-08 00:02:31 -0700529 ));
530
Alex Crichton954046c2017-05-30 21:49:42 -0700531 impl Synom for ViewPath {
Michael Layzell92639a52017-06-01 00:07:44 -0400532 named!(parse -> Self, alt!(
533 syn!(PathGlob) => { ViewPath::Glob }
534 |
535 syn!(PathList) => { ViewPath::List }
536 |
537 syn!(PathSimple) => { ViewPath::Simple } // must be last
538 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700539 }
David Tolnay4a057422016-10-08 00:02:31 -0700540
Alex Crichton954046c2017-05-30 21:49:42 -0700541 impl Synom for PathSimple {
Michael Layzell92639a52017-06-01 00:07:44 -0400542 named!(parse -> Self, do_parse!(
543 path: syn!(Path) >>
544 rename: option!(tuple!(syn!(As), syn!(Ident))) >>
545 (PathSimple {
546 path: path,
547 as_token: rename.as_ref().map(|p| As((p.0).0)),
548 rename: rename.map(|p| p.1),
549 })
550 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700551 }
David Tolnay4a057422016-10-08 00:02:31 -0700552
Alex Crichton954046c2017-05-30 21:49:42 -0700553 impl Synom for PathGlob {
Michael Layzell92639a52017-06-01 00:07:44 -0400554 named!(parse -> Self, do_parse!(
Alex Crichtonaf9d2952017-08-27 10:19:54 -0700555 path: option!(do_parse!(
556 path: syn!(Path) >>
557 colon2: syn!(Colon2) >>
558 (path, colon2)
559 )) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400560 star: syn!(Star) >>
Alex Crichtonaf9d2952017-08-27 10:19:54 -0700561 ({
562 match path {
563 Some((path, colon2)) => {
564 PathGlob {
565 path: path,
566 colon2_token: Some(colon2),
567 star_token: star,
568 }
569 }
570 None => {
571 PathGlob {
572 path: Path {
573 leading_colon: None,
574 segments: Default::default(),
575 },
576 colon2_token: None,
577 star_token: star,
578 }
579 }
580 }
Michael Layzell92639a52017-06-01 00:07:44 -0400581 })
582 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700583 }
David Tolnay4a057422016-10-08 00:02:31 -0700584
Alex Crichton954046c2017-05-30 21:49:42 -0700585 impl Synom for PathList {
Michael Layzell92639a52017-06-01 00:07:44 -0400586 named!(parse -> Self, alt!(
587 do_parse!(
588 path: syn!(Path) >>
589 colon2: syn!(Colon2) >>
590 items: braces!(call!(Delimited::parse_terminated)) >>
591 (PathList {
592 path: path,
593 items: items.0,
594 brace_token: items.1,
595 colon2_token: colon2,
596 })
597 )
598 |
599 do_parse!(
David Tolnay570695e2017-06-03 16:15:13 -0700600 colon: option!(syn!(Colon2)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400601 items: braces!(call!(Delimited::parse_terminated)) >>
602 (PathList {
603 path: Path {
Michael Layzell92639a52017-06-01 00:07:44 -0400604 leading_colon: None,
David Tolnay570695e2017-06-03 16:15:13 -0700605 segments: Delimited::new(),
Michael Layzell92639a52017-06-01 00:07:44 -0400606 },
David Tolnay570695e2017-06-03 16:15:13 -0700607 colon2_token: colon.unwrap_or_default(),
Michael Layzell92639a52017-06-01 00:07:44 -0400608 brace_token: items.1,
609 items: items.0,
610 })
611 )
612 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700613 }
David Tolnay4a057422016-10-08 00:02:31 -0700614
Alex Crichton954046c2017-05-30 21:49:42 -0700615 impl Synom for PathListItem {
Michael Layzell92639a52017-06-01 00:07:44 -0400616 named!(parse -> Self, do_parse!(
617 name: alt!(
618 syn!(Ident)
619 |
620 map!(syn!(Self_), Into::into)
621 ) >>
622 rename: option!(tuple!(syn!(As), syn!(Ident))) >>
623 (PathListItem {
624 name: name,
625 as_token: rename.as_ref().map(|p| As((p.0).0)),
626 rename: rename.map(|p| p.1),
627 })
628 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700629 }
David Tolnay4a057422016-10-08 00:02:31 -0700630
David Tolnay4c614be2017-11-10 00:02:38 -0800631 impl_synom!(ItemStatic "static item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700632 attrs: many0!(call!(Attribute::parse_outer)) >>
633 vis: syn!(Visibility) >>
634 static_: syn!(Static) >>
635 mutability: syn!(Mutability) >>
David Tolnay570695e2017-06-03 16:15:13 -0700636 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700637 colon: syn!(Colon) >>
638 ty: syn!(Ty) >>
639 eq: syn!(Eq) >>
640 value: syn!(Expr) >>
641 semi: syn!(Semi) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800642 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700643 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800644 vis: vis,
645 static_token: static_,
646 mutbl: mutability,
647 ident: ident,
648 colon_token: colon,
649 ty: Box::new(ty),
650 eq_token: eq,
651 expr: Box::new(value),
652 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800653 })
David Tolnay47a877c2016-10-01 16:50:55 -0700654 ));
655
David Tolnay4c614be2017-11-10 00:02:38 -0800656 impl_synom!(ItemConst "const item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700657 attrs: many0!(call!(Attribute::parse_outer)) >>
658 vis: syn!(Visibility) >>
659 const_: syn!(Const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700660 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700661 colon: syn!(Colon) >>
662 ty: syn!(Ty) >>
663 eq: syn!(Eq) >>
664 value: syn!(Expr) >>
665 semi: syn!(Semi) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800666 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700667 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800668 vis: vis,
669 const_token: const_,
670 ident: ident,
671 colon_token: colon,
672 ty: Box::new(ty),
673 eq_token: eq,
674 expr: Box::new(value),
675 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800676 })
David Tolnay47a877c2016-10-01 16:50:55 -0700677 ));
678
David Tolnay4c614be2017-11-10 00:02:38 -0800679 impl_synom!(ItemFn "fn item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700680 outer_attrs: many0!(call!(Attribute::parse_outer)) >>
681 vis: syn!(Visibility) >>
682 constness: syn!(Constness) >>
683 unsafety: syn!(Unsafety) >>
684 abi: option!(syn!(Abi)) >>
685 fn_: syn!(Fn_) >>
David Tolnay570695e2017-06-03 16:15:13 -0700686 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700687 generics: syn!(Generics) >>
688 inputs: parens!(Delimited::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800689 ret: syn!(ReturnType) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700690 where_clause: syn!(WhereClause) >>
691 inner_attrs_stmts: braces!(tuple!(
692 many0!(call!(Attribute::parse_inner)),
693 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -0400694 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800695 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -0700696 attrs: {
697 let mut attrs = outer_attrs;
Alex Crichton954046c2017-05-30 21:49:42 -0700698 attrs.extend((inner_attrs_stmts.0).0);
David Tolnay3b9783a2016-10-29 22:37:09 -0700699 attrs
700 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800701 vis: vis,
702 constness: constness,
703 unsafety: unsafety,
704 abi: abi,
705 decl: Box::new(FnDecl {
706 dot_tokens: None,
707 fn_token: fn_,
708 paren_token: inputs.1,
709 inputs: inputs.0,
710 output: ret,
711 variadic: false,
712 generics: Generics {
713 where_clause: where_clause,
714 .. generics
715 },
716 }),
717 ident: ident,
718 block: Box::new(Block {
719 brace_token: inner_attrs_stmts.1,
720 stmts: (inner_attrs_stmts.0).1,
721 }),
David Tolnay4c614be2017-11-10 00:02:38 -0800722 })
David Tolnay42602292016-10-01 22:25:45 -0700723 ));
724
Alex Crichton954046c2017-05-30 21:49:42 -0700725 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400726 named!(parse -> Self, alt!(
727 do_parse!(
728 and: syn!(And) >>
729 lt: option!(syn!(Lifetime)) >>
730 mutability: syn!(Mutability) >>
731 self_: syn!(Self_) >>
732 not!(syn!(Colon)) >>
733 (ArgSelfRef {
734 lifetime: lt,
735 mutbl: mutability,
736 and_token: and,
737 self_token: self_,
738 }.into())
739 )
740 |
741 do_parse!(
742 mutability: syn!(Mutability) >>
743 self_: syn!(Self_) >>
744 not!(syn!(Colon)) >>
745 (ArgSelf {
746 mutbl: mutability,
747 self_token: self_,
748 }.into())
749 )
750 |
751 do_parse!(
752 pat: syn!(Pat) >>
753 colon: syn!(Colon) >>
754 ty: syn!(Ty) >>
755 (ArgCaptured {
756 pat: pat,
757 ty: ty,
758 colon_token: colon,
759 }.into())
760 )
761 |
762 syn!(Ty) => { FnArg::Ignored }
763 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700764 }
David Tolnay62f374c2016-10-02 13:37:00 -0700765
David Tolnay4c614be2017-11-10 00:02:38 -0800766 impl_synom!(ItemMod "mod item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700767 outer_attrs: many0!(call!(Attribute::parse_outer)) >>
768 vis: syn!(Visibility) >>
769 mod_: syn!(Mod) >>
David Tolnay570695e2017-06-03 16:15:13 -0700770 ident: syn!(Ident) >>
771 content_semi: alt!(
772 syn!(Semi) => {|semi| (
773 Vec::new(),
774 None,
775 Some(semi),
776 )}
David Tolnay37d10332016-10-13 20:51:04 -0700777 |
Alex Crichton954046c2017-05-30 21:49:42 -0700778 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -0700779 tuple!(
Alex Crichton954046c2017-05-30 21:49:42 -0700780 many0!(call!(Attribute::parse_inner)),
781 many0!(syn!(Item))
Michael Layzell416724e2017-05-24 21:12:34 -0400782 )
David Tolnay570695e2017-06-03 16:15:13 -0700783 ) => {|((inner_attrs, items), brace)| (
784 inner_attrs,
785 Some((brace, items)),
786 None,
787 )}
David Tolnay37d10332016-10-13 20:51:04 -0700788 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800789 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -0700790 attrs: {
791 let mut attrs = outer_attrs;
792 attrs.extend(content_semi.0);
793 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -0700794 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800795 vis: vis,
796 mod_token: mod_,
797 ident: ident,
798 content: content_semi.1,
799 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -0800800 })
David Tolnay35902302016-10-06 01:11:08 -0700801 ));
802
David Tolnay4c614be2017-11-10 00:02:38 -0800803 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700804 attrs: many0!(call!(Attribute::parse_outer)) >>
805 abi: syn!(Abi) >>
806 items: braces!(many0!(syn!(ForeignItem))) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800807 (ItemForeignMod {
David Tolnay35902302016-10-06 01:11:08 -0700808 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800809 abi: abi,
810 brace_token: items.1,
811 items: items.0,
David Tolnay4c614be2017-11-10 00:02:38 -0800812 })
David Tolnay35902302016-10-06 01:11:08 -0700813 ));
814
David Tolnay8894f602017-11-11 12:11:04 -0800815 impl_synom!(ForeignItem "foreign item" alt!(
816 syn!(ForeignItemFn) => { ForeignItem::Fn }
817 |
818 syn!(ForeignItemStatic) => { ForeignItem::Static }
819 ));
David Tolnay35902302016-10-06 01:11:08 -0700820
David Tolnay8894f602017-11-11 12:11:04 -0800821 impl_synom!(ForeignItemFn "foreign function" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700822 attrs: many0!(call!(Attribute::parse_outer)) >>
823 vis: syn!(Visibility) >>
824 fn_: syn!(Fn_) >>
David Tolnay570695e2017-06-03 16:15:13 -0700825 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700826 generics: syn!(Generics) >>
827 inputs: parens!(do_parse!(
828 args: call!(Delimited::parse_terminated) >>
829 variadic: cond!(args.is_empty() || args.trailing_delim(),
830 option!(syn!(Dot3))) >>
831 (args, variadic)
832 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800833 ret: syn!(ReturnType) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700834 where_clause: syn!(WhereClause) >>
835 semi: syn!(Semi) >>
836 ({
837 let ((inputs, variadic), parens) = inputs;
838 let variadic = variadic.and_then(|v| v);
David Tolnay8894f602017-11-11 12:11:04 -0800839 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -0700840 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -0700841 attrs: attrs,
842 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -0800843 decl: Box::new(FnDecl {
844 fn_token: fn_,
845 paren_token: parens,
846 inputs: inputs,
847 variadic: variadic.is_some(),
848 dot_tokens: variadic,
849 output: ret,
850 generics: Generics {
851 where_clause: where_clause,
852 .. generics
853 },
854 }),
Alex Crichton954046c2017-05-30 21:49:42 -0700855 vis: vis,
856 }
David Tolnay35902302016-10-06 01:11:08 -0700857 })
858 ));
859
David Tolnay8894f602017-11-11 12:11:04 -0800860 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700861 attrs: many0!(call!(Attribute::parse_outer)) >>
862 vis: syn!(Visibility) >>
863 static_: syn!(Static) >>
864 mutability: syn!(Mutability) >>
David Tolnay570695e2017-06-03 16:15:13 -0700865 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700866 colon: syn!(Colon) >>
867 ty: syn!(Ty) >>
868 semi: syn!(Semi) >>
David Tolnay8894f602017-11-11 12:11:04 -0800869 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -0700870 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -0700871 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -0700872 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -0800873 ty: Box::new(ty),
874 mutbl: mutability,
875 static_token: static_,
876 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -0700877 vis: vis,
878 })
879 ));
880
David Tolnay4c614be2017-11-10 00:02:38 -0800881 impl_synom!(ItemTy "type item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700882 attrs: many0!(call!(Attribute::parse_outer)) >>
883 vis: syn!(Visibility) >>
884 type_: syn!(Type) >>
David Tolnay570695e2017-06-03 16:15:13 -0700885 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700886 generics: syn!(Generics) >>
887 where_clause: syn!(WhereClause) >>
888 eq: syn!(Eq) >>
889 ty: syn!(Ty) >>
890 semi: syn!(Semi) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800891 (ItemTy {
David Tolnay3cf52982016-10-01 17:11:37 -0700892 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800893 vis: vis,
894 type_token: type_,
895 ident: ident,
896 generics: Generics {
897 where_clause: where_clause,
898 ..generics
899 },
900 eq_token: eq,
901 ty: Box::new(ty),
902 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800903 })
David Tolnay3cf52982016-10-01 17:11:37 -0700904 ));
905
David Tolnay4c614be2017-11-10 00:02:38 -0800906 impl_synom!(ItemStruct "struct item" switch!(
907 map!(syn!(DeriveInput), Into::into),
908 Item::Struct(item) => value!(item)
909 |
910 _ => reject!()
911 ));
David Tolnay42602292016-10-01 22:25:45 -0700912
David Tolnay4c614be2017-11-10 00:02:38 -0800913 impl_synom!(ItemEnum "enum item" switch!(
914 map!(syn!(DeriveInput), Into::into),
915 Item::Enum(item) => value!(item)
916 |
917 _ => reject!()
918 ));
919
920 impl_synom!(ItemUnion "union item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700921 attrs: many0!(call!(Attribute::parse_outer)) >>
922 vis: syn!(Visibility) >>
923 union_: syn!(Union) >>
David Tolnay570695e2017-06-03 16:15:13 -0700924 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700925 generics: syn!(Generics) >>
926 where_clause: syn!(WhereClause) >>
927 fields: braces!(call!(Delimited::parse_terminated_with,
928 Field::parse_struct)) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800929 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -0700930 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800931 vis: vis,
932 union_token: union_,
933 ident: ident,
934 generics: Generics {
935 where_clause: where_clause,
936 .. generics
937 },
938 data: VariantData::Struct(fields.0, fields.1),
David Tolnay4c614be2017-11-10 00:02:38 -0800939 })
David Tolnay2f9fa632016-10-03 22:08:48 -0700940 ));
941
David Tolnay4c614be2017-11-10 00:02:38 -0800942 impl_synom!(ItemTrait "trait item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700943 attrs: many0!(call!(Attribute::parse_outer)) >>
944 vis: syn!(Visibility) >>
945 unsafety: syn!(Unsafety) >>
946 trait_: syn!(Trait) >>
David Tolnay570695e2017-06-03 16:15:13 -0700947 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700948 generics: syn!(Generics) >>
949 colon: option!(syn!(Colon)) >>
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700950 bounds: cond!(colon.is_some(),
Alex Crichton954046c2017-05-30 21:49:42 -0700951 call!(Delimited::parse_separated_nonempty)
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700952 ) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700953 where_clause: syn!(WhereClause) >>
954 body: braces!(many0!(syn!(TraitItem))) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800955 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -0700956 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800957 vis: vis,
958 unsafety: unsafety,
959 trait_token: trait_,
960 ident: ident,
961 generics: Generics {
962 where_clause: where_clause,
963 .. generics
964 },
965 colon_token: colon,
966 supertraits: bounds.unwrap_or_default(),
967 brace_token: body.1,
968 items: body.0,
David Tolnay4c614be2017-11-10 00:02:38 -0800969 })
David Tolnay0aecb732016-10-03 23:03:50 -0700970 ));
971
David Tolnay4c614be2017-11-10 00:02:38 -0800972 impl_synom!(ItemDefaultImpl "default impl item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -0700973 attrs: many0!(call!(Attribute::parse_outer)) >>
974 unsafety: syn!(Unsafety) >>
975 impl_: syn!(Impl) >>
976 path: syn!(Path) >>
977 for_: syn!(For) >>
978 dot2: syn!(Dot2) >>
979 braces: braces!(epsilon!()) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800980 (ItemDefaultImpl {
David Tolnayf94e2362016-10-04 00:29:51 -0700981 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800982 unsafety: unsafety,
983 impl_token: impl_,
984 path: path,
985 for_token: for_,
986 dot2_token: dot2,
987 brace_token: braces.1,
David Tolnay4c614be2017-11-10 00:02:38 -0800988 })
David Tolnayf94e2362016-10-04 00:29:51 -0700989 ));
990
David Tolnayda705bd2017-11-10 21:58:05 -0800991 impl_synom!(TraitItem "trait item" alt!(
992 syn!(TraitItemConst) => { TraitItem::Const }
993 |
994 syn!(TraitItemMethod) => { TraitItem::Method }
995 |
996 syn!(TraitItemType) => { TraitItem::Type }
997 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800998 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -0800999 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001000
David Tolnayda705bd2017-11-10 21:58:05 -08001001 impl_synom!(TraitItemConst "const trait item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001002 attrs: many0!(call!(Attribute::parse_outer)) >>
1003 const_: syn!(Const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001004 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001005 colon: syn!(Colon) >>
1006 ty: syn!(Ty) >>
David Tolnay570695e2017-06-03 16:15:13 -07001007 default: option!(tuple!(syn!(Eq), syn!(Expr))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001008 semi: syn!(Semi) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001009 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001010 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001011 const_token: const_,
1012 ident: ident,
1013 colon_token: colon,
1014 ty: ty,
1015 default: default,
1016 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001017 })
1018 ));
1019
David Tolnayda705bd2017-11-10 21:58:05 -08001020 impl_synom!(TraitItemMethod "method trait item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001021 outer_attrs: many0!(call!(Attribute::parse_outer)) >>
1022 constness: syn!(Constness) >>
1023 unsafety: syn!(Unsafety) >>
1024 abi: option!(syn!(Abi)) >>
1025 fn_: syn!(Fn_) >>
David Tolnay570695e2017-06-03 16:15:13 -07001026 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001027 generics: syn!(Generics) >>
1028 inputs: parens!(call!(Delimited::parse_terminated)) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001029 ret: syn!(ReturnType) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001030 where_clause: syn!(WhereClause) >>
1031 body: option!(braces!(
1032 tuple!(many0!(call!(Attribute::parse_inner)),
1033 call!(Block::parse_within))
David Tolnay5859df12016-10-29 22:49:54 -07001034 )) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001035 semi: cond!(body.is_none(), syn!(Semi)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001036 ({
1037 let (inner_attrs, stmts) = match body {
Alex Crichton954046c2017-05-30 21:49:42 -07001038 Some(((inner_attrs, stmts), b)) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001039 None => (Vec::new(), None),
1040 };
David Tolnayda705bd2017-11-10 21:58:05 -08001041 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001042 attrs: {
1043 let mut attrs = outer_attrs;
1044 attrs.extend(inner_attrs);
1045 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001046 },
David Tolnayda705bd2017-11-10 21:58:05 -08001047 sig: MethodSig {
1048 constness: constness,
1049 unsafety: unsafety,
1050 abi: abi,
1051 ident: ident,
1052 decl: FnDecl {
1053 inputs: inputs.0,
1054 output: ret,
1055 variadic: false,
1056 fn_token: fn_,
1057 paren_token: inputs.1,
1058 dot_tokens: None,
1059 generics: Generics {
1060 where_clause: where_clause,
1061 .. generics
David Tolnay5859df12016-10-29 22:49:54 -07001062 },
1063 },
David Tolnayda705bd2017-11-10 21:58:05 -08001064 },
1065 default: stmts.map(|stmts| {
1066 Block {
1067 stmts: stmts.0,
1068 brace_token: stmts.1,
1069 }
1070 }),
1071 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001072 }
David Tolnay0aecb732016-10-03 23:03:50 -07001073 })
1074 ));
1075
David Tolnayda705bd2017-11-10 21:58:05 -08001076 impl_synom!(TraitItemType "trait item type" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001077 attrs: many0!(call!(Attribute::parse_outer)) >>
1078 type_: syn!(Type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001079 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001080 colon: option!(syn!(Colon)) >>
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001081 bounds: cond!(colon.is_some(),
Alex Crichton954046c2017-05-30 21:49:42 -07001082 call!(Delimited::parse_separated_nonempty)
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001083 ) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001084 default: option!(tuple!(syn!(Eq), syn!(Ty))) >>
1085 semi: syn!(Semi) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001086 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001087 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001088 type_token: type_,
1089 ident: ident,
1090 colon_token: colon,
1091 bounds: bounds.unwrap_or_default(),
1092 default: default,
1093 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001094 })
1095 ));
1096
David Tolnaydecf28d2017-11-11 11:56:45 -08001097 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001098 attrs: many0!(call!(Attribute::parse_outer)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001099 mac: syn!(Macro) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001100 cond!(!mac.is_braced(), syn!(Semi)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001101 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001102 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001103 mac: mac,
David Tolnay0aecb732016-10-03 23:03:50 -07001104 })
1105 ));
1106
David Tolnay4c614be2017-11-10 00:02:38 -08001107 impl_synom!(ItemImpl "impl item" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001108 attrs: many0!(call!(Attribute::parse_outer)) >>
Alex Crichtonf3d9ccc2017-08-28 09:40:13 -07001109 defaultness: syn!(Defaultness) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001110 unsafety: syn!(Unsafety) >>
1111 impl_: syn!(Impl) >>
1112 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001113 polarity_path: alt!(
1114 do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001115 polarity: syn!(ImplPolarity) >>
1116 path: syn!(Path) >>
1117 for_: syn!(For) >>
David Tolnay570695e2017-06-03 16:15:13 -07001118 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001119 )
1120 |
David Tolnay570695e2017-06-03 16:15:13 -07001121 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001122 ) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001123 self_ty: syn!(Ty) >>
1124 where_clause: syn!(WhereClause) >>
1125 body: braces!(many0!(syn!(ImplItem))) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001126 (ItemImpl {
David Tolnay4c9be372016-10-06 00:47:37 -07001127 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001128 defaultness: defaultness,
1129 unsafety: unsafety,
1130 impl_token: impl_,
1131 generics: Generics {
1132 where_clause: where_clause,
1133 .. generics
1134 },
1135 trait_: polarity_path,
1136 self_ty: Box::new(self_ty),
1137 brace_token: body.1,
1138 items: body.0,
David Tolnay4c614be2017-11-10 00:02:38 -08001139 })
David Tolnay4c9be372016-10-06 00:47:37 -07001140 ));
1141
David Tolnay857628c2017-11-11 12:25:31 -08001142 impl_synom!(ImplItem "item in impl block" alt!(
1143 syn!(ImplItemConst) => { ImplItem::Const }
1144 |
1145 syn!(ImplItemMethod) => { ImplItem::Method }
1146 |
1147 syn!(ImplItemType) => { ImplItem::Type }
1148 |
1149 syn!(ImplItemMacro) => { ImplItem::Macro }
1150 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001151
David Tolnay857628c2017-11-11 12:25:31 -08001152 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001153 attrs: many0!(call!(Attribute::parse_outer)) >>
1154 vis: syn!(Visibility) >>
1155 defaultness: syn!(Defaultness) >>
1156 const_: syn!(Const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001157 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001158 colon: syn!(Colon) >>
1159 ty: syn!(Ty) >>
1160 eq: syn!(Eq) >>
1161 value: syn!(Expr) >>
1162 semi: syn!(Semi) >>
David Tolnay857628c2017-11-11 12:25:31 -08001163 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001164 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001165 vis: vis,
1166 defaultness: defaultness,
1167 const_token: const_,
1168 ident: ident,
1169 colon_token: colon,
1170 ty: ty,
1171 eq_token: eq,
1172 expr: value,
1173 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001174 })
1175 ));
1176
David Tolnay857628c2017-11-11 12:25:31 -08001177 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001178 outer_attrs: many0!(call!(Attribute::parse_outer)) >>
1179 vis: syn!(Visibility) >>
1180 defaultness: syn!(Defaultness) >>
1181 constness: syn!(Constness) >>
1182 unsafety: syn!(Unsafety) >>
1183 abi: option!(syn!(Abi)) >>
1184 fn_: syn!(Fn_) >>
David Tolnay570695e2017-06-03 16:15:13 -07001185 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001186 generics: syn!(Generics) >>
1187 inputs: parens!(call!(Delimited::parse_terminated)) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001188 ret: syn!(ReturnType) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001189 where_clause: syn!(WhereClause) >>
1190 inner_attrs_stmts: braces!(tuple!(
1191 many0!(call!(Attribute::parse_inner)),
1192 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -04001193 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001194 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001195 attrs: {
1196 let mut attrs = outer_attrs;
Alex Crichton954046c2017-05-30 21:49:42 -07001197 attrs.extend((inner_attrs_stmts.0).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001198 attrs
1199 },
David Tolnay857628c2017-11-11 12:25:31 -08001200 vis: vis,
1201 defaultness: defaultness,
1202 sig: MethodSig {
1203 constness: constness,
1204 unsafety: unsafety,
1205 abi: abi,
1206 ident: ident,
1207 decl: FnDecl {
1208 fn_token: fn_,
1209 paren_token: inputs.1,
1210 inputs: inputs.0,
1211 output: ret,
1212 variadic: false,
1213 generics: Generics {
1214 where_clause: where_clause,
1215 .. generics
David Tolnay4c9be372016-10-06 00:47:37 -07001216 },
David Tolnay857628c2017-11-11 12:25:31 -08001217 dot_tokens: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001218 },
David Tolnay857628c2017-11-11 12:25:31 -08001219 },
1220 block: Block {
1221 brace_token: inner_attrs_stmts.1,
1222 stmts: (inner_attrs_stmts.0).1,
1223 },
David Tolnay4c9be372016-10-06 00:47:37 -07001224 })
1225 ));
1226
David Tolnay857628c2017-11-11 12:25:31 -08001227 impl_synom!(ImplItemType "type in impl block" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001228 attrs: many0!(call!(Attribute::parse_outer)) >>
1229 vis: syn!(Visibility) >>
1230 defaultness: syn!(Defaultness) >>
1231 type_: syn!(Type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001232 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001233 eq: syn!(Eq) >>
1234 ty: syn!(Ty) >>
1235 semi: syn!(Semi) >>
David Tolnay857628c2017-11-11 12:25:31 -08001236 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001237 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001238 vis: vis,
1239 defaultness: defaultness,
1240 type_token: type_,
1241 ident: ident,
1242 eq_token: eq,
1243 ty: ty,
1244 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001245 })
1246 ));
1247
David Tolnay857628c2017-11-11 12:25:31 -08001248 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
Alex Crichton954046c2017-05-30 21:49:42 -07001249 attrs: many0!(call!(Attribute::parse_outer)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001250 mac: syn!(Macro) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001251 cond!(!mac.is_braced(), syn!(Semi)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001252 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001253 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001254 mac: mac,
David Tolnay4c9be372016-10-06 00:47:37 -07001255 })
1256 ));
1257
Alex Crichton954046c2017-05-30 21:49:42 -07001258 impl Synom for ImplPolarity {
Michael Layzell92639a52017-06-01 00:07:44 -04001259 named!(parse -> Self, alt!(
1260 syn!(Bang) => { ImplPolarity::Negative }
1261 |
1262 epsilon!() => { |_| ImplPolarity::Positive }
1263 ));
Alex Crichton954046c2017-05-30 21:49:42 -07001264 }
David Tolnay4c9be372016-10-06 00:47:37 -07001265
Alex Crichton954046c2017-05-30 21:49:42 -07001266 impl Synom for Constness {
Michael Layzell92639a52017-06-01 00:07:44 -04001267 named!(parse -> Self, alt!(
1268 syn!(Const) => { Constness::Const }
1269 |
1270 epsilon!() => { |_| Constness::NotConst }
1271 ));
Alex Crichton954046c2017-05-30 21:49:42 -07001272 }
David Tolnay42602292016-10-01 22:25:45 -07001273
Alex Crichton954046c2017-05-30 21:49:42 -07001274 impl Synom for Defaultness {
Michael Layzell92639a52017-06-01 00:07:44 -04001275 named!(parse -> Self, alt!(
1276 syn!(Default_) => { Defaultness::Default }
1277 |
1278 epsilon!() => { |_| Defaultness::Final }
1279 ));
Alex Crichton954046c2017-05-30 21:49:42 -07001280 }
David Tolnayedf2b992016-09-23 20:43:45 -07001281}
David Tolnay4a51dc72016-10-01 00:40:31 -07001282
1283#[cfg(feature = "printing")]
1284mod printing {
1285 use super::*;
1286 use attr::FilterAttrs;
David Tolnay47a877c2016-10-01 16:50:55 -07001287 use data::VariantData;
David Tolnay4a51dc72016-10-01 00:40:31 -07001288 use quote::{Tokens, ToTokens};
1289
David Tolnay1bfa7332017-11-11 12:41:20 -08001290 impl ToTokens for ItemExternCrate {
David Tolnay4a51dc72016-10-01 00:40:31 -07001291 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001292 tokens.append_all(self.attrs.outer());
1293 self.vis.to_tokens(tokens);
1294 self.extern_token.to_tokens(tokens);
1295 self.crate_token.to_tokens(tokens);
1296 self.ident.to_tokens(tokens);
1297 if let Some((ref as_token, ref rename)) = self.rename {
1298 as_token.to_tokens(tokens);
1299 rename.to_tokens(tokens);
1300 }
1301 self.semi_token.to_tokens(tokens);
1302 }
1303 }
1304
1305 impl ToTokens for ItemUse {
1306 fn to_tokens(&self, tokens: &mut Tokens) {
1307 tokens.append_all(self.attrs.outer());
1308 self.vis.to_tokens(tokens);
1309 self.use_token.to_tokens(tokens);
1310 self.path.to_tokens(tokens);
1311 self.semi_token.to_tokens(tokens);
1312 }
1313 }
1314
1315 impl ToTokens for ItemStatic {
1316 fn to_tokens(&self, tokens: &mut Tokens) {
1317 tokens.append_all(self.attrs.outer());
1318 self.vis.to_tokens(tokens);
1319 self.static_token.to_tokens(tokens);
1320 self.mutbl.to_tokens(tokens);
1321 self.ident.to_tokens(tokens);
1322 self.colon_token.to_tokens(tokens);
1323 self.ty.to_tokens(tokens);
1324 self.eq_token.to_tokens(tokens);
1325 self.expr.to_tokens(tokens);
1326 self.semi_token.to_tokens(tokens);
1327 }
1328 }
1329
1330 impl ToTokens for ItemConst {
1331 fn to_tokens(&self, tokens: &mut Tokens) {
1332 tokens.append_all(self.attrs.outer());
1333 self.vis.to_tokens(tokens);
1334 self.const_token.to_tokens(tokens);
1335 self.ident.to_tokens(tokens);
1336 self.colon_token.to_tokens(tokens);
1337 self.ty.to_tokens(tokens);
1338 self.eq_token.to_tokens(tokens);
1339 self.expr.to_tokens(tokens);
1340 self.semi_token.to_tokens(tokens);
1341 }
1342 }
1343
1344 impl ToTokens for ItemFn {
1345 fn to_tokens(&self, tokens: &mut Tokens) {
1346 tokens.append_all(self.attrs.outer());
1347 self.vis.to_tokens(tokens);
1348 self.constness.to_tokens(tokens);
1349 self.unsafety.to_tokens(tokens);
1350 self.abi.to_tokens(tokens);
1351 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1352 self.block.brace_token.surround(tokens, |tokens| {
1353 tokens.append_all(self.attrs.inner());
1354 tokens.append_all(&self.block.stmts);
1355 });
1356 }
1357 }
1358
1359 impl ToTokens for ItemMod {
1360 fn to_tokens(&self, tokens: &mut Tokens) {
1361 tokens.append_all(self.attrs.outer());
1362 self.vis.to_tokens(tokens);
1363 self.mod_token.to_tokens(tokens);
1364 self.ident.to_tokens(tokens);
1365 if let Some((ref brace, ref items)) = self.content {
1366 brace.surround(tokens, |tokens| {
1367 tokens.append_all(self.attrs.inner());
1368 tokens.append_all(items);
1369 });
1370 } else {
1371 TokensOrDefault(&self.semi).to_tokens(tokens);
1372 }
1373 }
1374 }
1375
1376 impl ToTokens for ItemForeignMod {
1377 fn to_tokens(&self, tokens: &mut Tokens) {
1378 tokens.append_all(self.attrs.outer());
1379 self.abi.to_tokens(tokens);
1380 self.brace_token.surround(tokens, |tokens| {
1381 tokens.append_all(&self.items);
1382 });
1383 }
1384 }
1385
1386 impl ToTokens for ItemTy {
1387 fn to_tokens(&self, tokens: &mut Tokens) {
1388 tokens.append_all(self.attrs.outer());
1389 self.vis.to_tokens(tokens);
1390 self.type_token.to_tokens(tokens);
1391 self.ident.to_tokens(tokens);
1392 self.generics.to_tokens(tokens);
1393 self.generics.where_clause.to_tokens(tokens);
1394 self.eq_token.to_tokens(tokens);
1395 self.ty.to_tokens(tokens);
1396 self.semi_token.to_tokens(tokens);
1397 }
1398 }
1399
1400 impl ToTokens for ItemEnum {
1401 fn to_tokens(&self, tokens: &mut Tokens) {
1402 tokens.append_all(self.attrs.outer());
1403 self.vis.to_tokens(tokens);
1404 self.enum_token.to_tokens(tokens);
1405 self.ident.to_tokens(tokens);
1406 self.generics.to_tokens(tokens);
1407 self.generics.where_clause.to_tokens(tokens);
1408 self.brace_token.surround(tokens, |tokens| {
1409 self.variants.to_tokens(tokens);
1410 });
1411 }
1412 }
1413
1414 impl ToTokens for ItemStruct {
1415 fn to_tokens(&self, tokens: &mut Tokens) {
1416 tokens.append_all(self.attrs.outer());
1417 self.vis.to_tokens(tokens);
1418 self.struct_token.to_tokens(tokens);
1419 self.ident.to_tokens(tokens);
1420 self.generics.to_tokens(tokens);
1421 match self.data {
1422 VariantData::Struct(..) => {
1423 self.generics.where_clause.to_tokens(tokens);
1424 self.data.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001425 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001426 VariantData::Tuple(..) => {
1427 self.data.to_tokens(tokens);
1428 self.generics.where_clause.to_tokens(tokens);
1429 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001430 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001431 VariantData::Unit => {
1432 self.generics.where_clause.to_tokens(tokens);
1433 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001434 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001435 }
1436 }
1437 }
1438
1439 impl ToTokens for ItemUnion {
1440 fn to_tokens(&self, tokens: &mut Tokens) {
1441 tokens.append_all(self.attrs.outer());
1442 self.vis.to_tokens(tokens);
1443 self.union_token.to_tokens(tokens);
1444 self.ident.to_tokens(tokens);
1445 self.generics.to_tokens(tokens);
1446 self.generics.where_clause.to_tokens(tokens);
1447 // XXX: Should we handle / complain when using a
1448 // non-VariantData::Struct Variant in Union?
1449 self.data.to_tokens(tokens);
1450 }
1451 }
1452
1453 impl ToTokens for ItemTrait {
1454 fn to_tokens(&self, tokens: &mut Tokens) {
1455 tokens.append_all(self.attrs.outer());
1456 self.vis.to_tokens(tokens);
1457 self.unsafety.to_tokens(tokens);
1458 self.trait_token.to_tokens(tokens);
1459 self.ident.to_tokens(tokens);
1460 self.generics.to_tokens(tokens);
1461 if !self.supertraits.is_empty() {
1462 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1463 self.supertraits.to_tokens(tokens);
1464 }
1465 self.generics.where_clause.to_tokens(tokens);
1466 self.brace_token.surround(tokens, |tokens| {
1467 tokens.append_all(&self.items);
1468 });
1469 }
1470 }
1471
1472 impl ToTokens for ItemDefaultImpl {
1473 fn to_tokens(&self, tokens: &mut Tokens) {
1474 tokens.append_all(self.attrs.outer());
1475 self.unsafety.to_tokens(tokens);
1476 self.impl_token.to_tokens(tokens);
1477 self.path.to_tokens(tokens);
1478 self.for_token.to_tokens(tokens);
1479 self.dot2_token.to_tokens(tokens);
1480 self.brace_token.surround(tokens, |_tokens| {});
1481 }
1482 }
1483
1484 impl ToTokens for ItemImpl {
1485 fn to_tokens(&self, tokens: &mut Tokens) {
1486 tokens.append_all(self.attrs.outer());
1487 self.defaultness.to_tokens(tokens);
1488 self.unsafety.to_tokens(tokens);
1489 self.impl_token.to_tokens(tokens);
1490 self.generics.to_tokens(tokens);
1491 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1492 polarity.to_tokens(tokens);
1493 path.to_tokens(tokens);
1494 for_token.to_tokens(tokens);
1495 }
1496 self.self_ty.to_tokens(tokens);
1497 self.generics.where_clause.to_tokens(tokens);
1498 self.brace_token.surround(tokens, |tokens| {
1499 tokens.append_all(&self.items);
1500 });
1501 }
1502 }
1503
1504 impl ToTokens for ItemMacro {
1505 fn to_tokens(&self, tokens: &mut Tokens) {
1506 tokens.append_all(self.attrs.outer());
1507 self.mac.path.to_tokens(tokens);
1508 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001509 self.ident.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001510 tokens.append_all(&self.mac.tokens);
1511 if !self.mac.is_braced() {
1512 tokens::Semi::default().to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001513 }
1514 }
1515 }
David Tolnay42602292016-10-01 22:25:45 -07001516
Alex Crichton62a0a592017-05-22 13:58:53 -07001517 impl ToTokens for PathSimple {
David Tolnay4a057422016-10-08 00:02:31 -07001518 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichton62a0a592017-05-22 13:58:53 -07001519 self.path.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001520 if self.rename.is_some() {
Alex Crichton259ee532017-07-14 06:51:02 -07001521 TokensOrDefault(&self.as_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001522 self.rename.to_tokens(tokens);
1523 }
David Tolnay4a057422016-10-08 00:02:31 -07001524 }
1525 }
1526
Alex Crichton62a0a592017-05-22 13:58:53 -07001527 impl ToTokens for PathGlob {
1528 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonaf9d2952017-08-27 10:19:54 -07001529 if self.path.segments.len() > 0 {
1530 self.path.to_tokens(tokens);
1531 TokensOrDefault(&self.colon2_token).to_tokens(tokens);
1532 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001533 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001534 }
1535 }
1536
1537 impl ToTokens for PathList {
1538 fn to_tokens(&self, tokens: &mut Tokens) {
1539 self.path.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001540 self.colon2_token.to_tokens(tokens);
1541 self.brace_token.surround(tokens, |tokens| {
1542 self.items.to_tokens(tokens);
1543 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001544 }
1545 }
1546
David Tolnay4a057422016-10-08 00:02:31 -07001547 impl ToTokens for PathListItem {
1548 fn to_tokens(&self, tokens: &mut Tokens) {
1549 self.name.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001550 if self.rename.is_some() {
Alex Crichton259ee532017-07-14 06:51:02 -07001551 TokensOrDefault(&self.as_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001552 self.rename.to_tokens(tokens);
1553 }
David Tolnay4a057422016-10-08 00:02:31 -07001554 }
1555 }
1556
David Tolnay1bfa7332017-11-11 12:41:20 -08001557 impl ToTokens for TraitItemConst {
David Tolnayca085422016-10-04 00:12:38 -07001558 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001559 tokens.append_all(self.attrs.outer());
1560 self.const_token.to_tokens(tokens);
1561 self.ident.to_tokens(tokens);
1562 self.colon_token.to_tokens(tokens);
1563 self.ty.to_tokens(tokens);
1564 if let Some((ref eq_token, ref default)) = self.default {
1565 eq_token.to_tokens(tokens);
1566 default.to_tokens(tokens);
1567 }
1568 self.semi_token.to_tokens(tokens);
1569 }
1570 }
1571
1572 impl ToTokens for TraitItemMethod {
1573 fn to_tokens(&self, tokens: &mut Tokens) {
1574 tokens.append_all(self.attrs.outer());
1575 self.sig.to_tokens(tokens);
1576 match self.default {
1577 Some(ref block) => {
1578 block.brace_token.surround(tokens, |tokens| {
1579 tokens.append_all(self.attrs.inner());
1580 tokens.append_all(&block.stmts);
1581 });
David Tolnayca085422016-10-04 00:12:38 -07001582 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001583 None => {
1584 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001585 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001586 }
1587 }
1588 }
1589
1590 impl ToTokens for TraitItemType {
1591 fn to_tokens(&self, tokens: &mut Tokens) {
1592 tokens.append_all(self.attrs.outer());
1593 self.type_token.to_tokens(tokens);
1594 self.ident.to_tokens(tokens);
1595 if !self.bounds.is_empty() {
1596 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1597 self.bounds.to_tokens(tokens);
1598 }
1599 if let Some((ref eq_token, ref default)) = self.default {
1600 eq_token.to_tokens(tokens);
1601 default.to_tokens(tokens);
1602 }
1603 self.semi_token.to_tokens(tokens);
1604 }
1605 }
1606
1607 impl ToTokens for TraitItemMacro {
1608 fn to_tokens(&self, tokens: &mut Tokens) {
1609 tokens.append_all(self.attrs.outer());
1610 self.mac.to_tokens(tokens);
1611 if !self.mac.is_braced() {
1612 tokens::Semi::default().to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001613 }
1614 }
1615 }
1616
David Tolnay857628c2017-11-11 12:25:31 -08001617 impl ToTokens for ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001618 fn to_tokens(&self, tokens: &mut Tokens) {
1619 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08001620 self.vis.to_tokens(tokens);
1621 self.defaultness.to_tokens(tokens);
1622 self.const_token.to_tokens(tokens);
1623 self.ident.to_tokens(tokens);
1624 self.colon_token.to_tokens(tokens);
1625 self.ty.to_tokens(tokens);
1626 self.eq_token.to_tokens(tokens);
1627 self.expr.to_tokens(tokens);
1628 self.semi_token.to_tokens(tokens);
1629 }
1630 }
1631
1632 impl ToTokens for ImplItemMethod {
1633 fn to_tokens(&self, tokens: &mut Tokens) {
1634 tokens.append_all(self.attrs.outer());
1635 self.vis.to_tokens(tokens);
1636 self.defaultness.to_tokens(tokens);
1637 self.sig.to_tokens(tokens);
1638 self.block.brace_token.surround(tokens, |tokens| {
1639 tokens.append_all(self.attrs.inner());
1640 tokens.append_all(&self.block.stmts);
1641 });
1642 }
1643 }
1644
1645 impl ToTokens for ImplItemType {
1646 fn to_tokens(&self, tokens: &mut Tokens) {
1647 tokens.append_all(self.attrs.outer());
1648 self.vis.to_tokens(tokens);
1649 self.defaultness.to_tokens(tokens);
1650 self.type_token.to_tokens(tokens);
1651 self.ident.to_tokens(tokens);
1652 self.eq_token.to_tokens(tokens);
1653 self.ty.to_tokens(tokens);
1654 self.semi_token.to_tokens(tokens);
1655 }
1656 }
1657
1658 impl ToTokens for ImplItemMacro {
1659 fn to_tokens(&self, tokens: &mut Tokens) {
1660 tokens.append_all(self.attrs.outer());
1661 self.mac.to_tokens(tokens);
1662 if !self.mac.is_braced() {
1663 // FIXME needs a span
1664 tokens::Semi::default().to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07001665 }
1666 }
1667 }
1668
David Tolnay8894f602017-11-11 12:11:04 -08001669 impl ToTokens for ForeignItemFn {
David Tolnay35902302016-10-06 01:11:08 -07001670 fn to_tokens(&self, tokens: &mut Tokens) {
1671 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001672 self.vis.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001673 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1674 self.semi_token.to_tokens(tokens);
1675 }
1676 }
1677
1678 impl ToTokens for ForeignItemStatic {
1679 fn to_tokens(&self, tokens: &mut Tokens) {
1680 tokens.append_all(self.attrs.outer());
1681 self.vis.to_tokens(tokens);
1682 self.static_token.to_tokens(tokens);
1683 self.mutbl.to_tokens(tokens);
1684 self.ident.to_tokens(tokens);
1685 self.colon_token.to_tokens(tokens);
1686 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001687 self.semi_token.to_tokens(tokens);
1688 }
1689 }
1690
David Tolnay570695e2017-06-03 16:15:13 -07001691 impl ToTokens for MethodSig {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001692 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay570695e2017-06-03 16:15:13 -07001693 self.constness.to_tokens(tokens);
1694 self.unsafety.to_tokens(tokens);
1695 self.abi.to_tokens(tokens);
1696 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001697 }
1698 }
1699
David Tolnay570695e2017-06-03 16:15:13 -07001700 struct NamedDecl<'a>(&'a FnDecl, Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001701
1702 impl<'a> ToTokens for NamedDecl<'a> {
1703 fn to_tokens(&self, tokens: &mut Tokens) {
1704 self.0.fn_token.to_tokens(tokens);
1705 self.1.to_tokens(tokens);
1706 self.0.generics.to_tokens(tokens);
1707 self.0.paren_token.surround(tokens, |tokens| {
1708 self.0.inputs.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001709
1710 if self.0.variadic {
1711 if !self.0.inputs.empty_or_trailing() {
1712 tokens::Comma::default().to_tokens(tokens);
1713 }
Alex Crichton259ee532017-07-14 06:51:02 -07001714 TokensOrDefault(&self.0.dot_tokens).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001715 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001716 });
1717 self.0.output.to_tokens(tokens);
1718 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07001719 }
1720 }
1721
Alex Crichton62a0a592017-05-22 13:58:53 -07001722 impl ToTokens for ArgSelfRef {
David Tolnay62f374c2016-10-02 13:37:00 -07001723 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001724 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001725 self.lifetime.to_tokens(tokens);
1726 self.mutbl.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001727 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001728 }
1729 }
1730
1731 impl ToTokens for ArgSelf {
1732 fn to_tokens(&self, tokens: &mut Tokens) {
1733 self.mutbl.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001734 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001735 }
1736 }
1737
1738 impl ToTokens for ArgCaptured {
1739 fn to_tokens(&self, tokens: &mut Tokens) {
1740 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001741 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001742 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07001743 }
1744 }
1745
David Tolnay42602292016-10-01 22:25:45 -07001746 impl ToTokens for Constness {
1747 fn to_tokens(&self, tokens: &mut Tokens) {
1748 match *self {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001749 Constness::Const(ref t) => t.to_tokens(tokens),
David Tolnaydaaf7742016-10-03 11:11:43 -07001750 Constness::NotConst => {
1751 // nothing
1752 }
David Tolnay42602292016-10-01 22:25:45 -07001753 }
1754 }
1755 }
1756
David Tolnay4c9be372016-10-06 00:47:37 -07001757 impl ToTokens for Defaultness {
1758 fn to_tokens(&self, tokens: &mut Tokens) {
1759 match *self {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001760 Defaultness::Default(ref t) => t.to_tokens(tokens),
David Tolnay4c9be372016-10-06 00:47:37 -07001761 Defaultness::Final => {
1762 // nothing
1763 }
1764 }
1765 }
1766 }
1767
1768 impl ToTokens for ImplPolarity {
1769 fn to_tokens(&self, tokens: &mut Tokens) {
1770 match *self {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001771 ImplPolarity::Negative(ref t) => t.to_tokens(tokens),
David Tolnay4c9be372016-10-06 00:47:37 -07001772 ImplPolarity::Positive => {
1773 // nothing
1774 }
1775 }
1776 }
1777 }
David Tolnay4a51dc72016-10-01 00:40:31 -07001778}