blob: 84bf67815d4276c6e7c1d0ef3606882a635860fa [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// Copyright 2018 Syn Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
David Tolnayb79ee962016-09-04 09:39:20 -07009use super::*;
David Tolnay3cfd1d32018-01-03 00:22:08 -080010use derive::{Data, DeriveInput};
David Tolnayf2cfd722017-12-31 18:02:51 -050011use punctuated::Punctuated;
David Tolnay61037c62018-01-05 16:21:03 -080012use proc_macro2::TokenStream;
13use token::{Brace, Paren};
David Tolnay9c76bcb2017-12-26 23:14:59 -050014
15#[cfg(feature = "extra-traits")]
David Tolnayc43b44e2017-12-30 23:55:54 -050016use tt::TokenStreamHelper;
David Tolnay9c76bcb2017-12-26 23:14:59 -050017#[cfg(feature = "extra-traits")]
18use std::hash::{Hash, Hasher};
David Tolnayb79ee962016-09-04 09:39:20 -070019
Alex Crichton62a0a592017-05-22 13:58:53 -070020ast_enum_of_structs! {
David Tolnay2b214082018-01-07 01:30:18 -080021 /// Things that can appear directly inside of a module or scope.
David Tolnay614a0142018-01-07 10:25:43 -080022 ///
David Tolnay461d98e2018-01-07 11:07:19 -080023 /// *This type is available if Syn is built with the `"full"` feature.*
24 ///
David Tolnay614a0142018-01-07 10:25:43 -080025 /// # Syntax tree enum
26 ///
27 /// This type is a [syntax tree enum].
28 ///
29 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayc6b55bc2017-11-09 22:48:38 -080030 pub enum Item {
David Tolnay2b214082018-01-07 01:30:18 -080031 /// An `extern crate` item: `extern crate serde`.
David Tolnay461d98e2018-01-07 11:07:19 -080032 ///
33 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070034 pub ExternCrate(ItemExternCrate {
David Tolnayc6b55bc2017-11-09 22:48:38 -080035 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070036 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080037 pub extern_token: Token![extern],
38 pub crate_token: Token![crate],
David Tolnay570695e2017-06-03 16:15:13 -070039 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080040 pub rename: Option<(Token![as], Ident)>,
41 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070042 }),
David Tolnay2b214082018-01-07 01:30:18 -080043
44 /// A use declaration: `use std::collections::HashMap`.
David Tolnay461d98e2018-01-07 11:07:19 -080045 ///
46 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070047 pub Use(ItemUse {
David Tolnayc6b55bc2017-11-09 22:48:38 -080048 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070049 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080050 pub use_token: Token![use],
David Tolnay5f332a92017-12-26 00:42:45 -050051 pub leading_colon: Option<Token![::]>,
David Tolnayf2cfd722017-12-31 18:02:51 -050052 pub prefix: Punctuated<Ident, Token![::]>,
David Tolnay5f332a92017-12-26 00:42:45 -050053 pub tree: UseTree,
David Tolnayf8db7ba2017-11-11 22:52:16 -080054 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070055 }),
David Tolnay2b214082018-01-07 01:30:18 -080056
57 /// A static item: `static BIKE: Shed = Shed(42)`.
David Tolnay461d98e2018-01-07 11:07:19 -080058 ///
59 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070060 pub Static(ItemStatic {
David Tolnayc6b55bc2017-11-09 22:48:38 -080061 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070062 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080063 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -050064 pub mutability: Option<Token![mut]>,
David Tolnay570695e2017-06-03 16:15:13 -070065 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080066 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080067 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080068 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070069 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080070 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070071 }),
David Tolnay2b214082018-01-07 01:30:18 -080072
73 /// A constant item: `const MAX: u16 = 65535`.
David Tolnay461d98e2018-01-07 11:07:19 -080074 ///
75 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070076 pub Const(ItemConst {
David Tolnayc6b55bc2017-11-09 22:48:38 -080077 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070078 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080079 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -070080 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080081 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080082 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080083 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070084 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080085 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070086 }),
David Tolnay2b214082018-01-07 01:30:18 -080087
David Tolnay461d98e2018-01-07 11:07:19 -080088 /// A free-standing function: `fn process(n: usize) -> Result<()> { ...
89 /// }`.
90 ///
91 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070092 pub Fn(ItemFn {
David Tolnayc6b55bc2017-11-09 22:48:38 -080093 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070094 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -050095 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -050096 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070097 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -070098 pub ident: Ident,
David Tolnay4a3f59a2017-12-28 21:21:12 -050099 pub decl: Box<FnDecl>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700100 pub block: Box<Block>,
101 }),
David Tolnay2b214082018-01-07 01:30:18 -0800102
103 /// A module or module declaration: `mod m` or `mod m { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800104 ///
105 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700106 pub Mod(ItemMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800107 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700108 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800109 pub mod_token: Token![mod],
David Tolnay570695e2017-06-03 16:15:13 -0700110 pub ident: Ident,
David Tolnay32954ef2017-12-26 22:43:16 -0500111 pub content: Option<(token::Brace, Vec<Item>)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800112 pub semi: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700113 }),
David Tolnay2b214082018-01-07 01:30:18 -0800114
115 /// A block of foreign items: `extern "C" { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800116 ///
117 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700118 pub ForeignMod(ItemForeignMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800119 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700120 pub abi: Abi,
David Tolnay32954ef2017-12-26 22:43:16 -0500121 pub brace_token: token::Brace,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700122 pub items: Vec<ForeignItem>,
123 }),
David Tolnay2b214082018-01-07 01:30:18 -0800124
125 /// A type alias: `type Result<T> = std::result::Result<T, MyError>`.
David Tolnay461d98e2018-01-07 11:07:19 -0800126 ///
127 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800128 pub Type(ItemType {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800129 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700130 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800131 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700132 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700133 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800134 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800135 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800136 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700137 }),
David Tolnay2b214082018-01-07 01:30:18 -0800138
139 /// A struct definition: `struct Foo<A> { x: A }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800140 ///
141 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaye3d41b72017-12-31 15:24:00 -0500142 pub Struct(ItemStruct {
143 pub attrs: Vec<Attribute>,
144 pub vis: Visibility,
145 pub struct_token: Token![struct],
146 pub ident: Ident,
147 pub generics: Generics,
148 pub fields: Fields,
149 pub semi_token: Option<Token![;]>,
150 }),
David Tolnay2b214082018-01-07 01:30:18 -0800151
152 /// An enum definition: `enum Foo<A, B> { C<A>, D<B> }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800153 ///
154 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700155 pub Enum(ItemEnum {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800156 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700157 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800158 pub enum_token: Token![enum],
David Tolnay570695e2017-06-03 16:15:13 -0700159 pub ident: Ident,
160 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500161 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500162 pub variants: Punctuated<Variant, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700163 }),
David Tolnay2b214082018-01-07 01:30:18 -0800164
165 /// A union definition: `union Foo<A, B> { x: A, y: B }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800166 ///
167 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700168 pub Union(ItemUnion {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800169 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700170 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800171 pub union_token: Token![union],
David Tolnay570695e2017-06-03 16:15:13 -0700172 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700173 pub generics: Generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500174 pub fields: FieldsNamed,
Alex Crichton62a0a592017-05-22 13:58:53 -0700175 }),
David Tolnay2b214082018-01-07 01:30:18 -0800176
177 /// A trait definition: `pub trait Iterator { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800178 ///
179 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700180 pub Trait(ItemTrait {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800181 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700182 pub vis: Visibility,
David Tolnay9b258702017-12-29 02:24:41 -0500183 pub unsafety: Option<Token![unsafe]>,
Nika Layzell0dc6e632017-11-18 12:55:25 -0500184 pub auto_token: Option<Token![auto]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800185 pub trait_token: Token![trait],
David Tolnay570695e2017-06-03 16:15:13 -0700186 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700187 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800188 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500189 pub supertraits: Punctuated<TypeParamBound, Token![+]>,
David Tolnay32954ef2017-12-26 22:43:16 -0500190 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700191 pub items: Vec<TraitItem>,
192 }),
David Tolnay2b214082018-01-07 01:30:18 -0800193
194 /// An impl block providing trait or associated items: `impl<A> Trait
195 /// for Data<A> { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800196 ///
197 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700198 pub Impl(ItemImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800199 pub attrs: Vec<Attribute>,
David Tolnay360a6342017-12-29 02:22:11 -0500200 pub defaultness: Option<Token![default]>,
David Tolnay9b258702017-12-29 02:24:41 -0500201 pub unsafety: Option<Token![unsafe]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800202 pub impl_token: Token![impl],
Alex Crichton62a0a592017-05-22 13:58:53 -0700203 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700204 /// Trait this impl implements.
David Tolnay360a6342017-12-29 02:22:11 -0500205 pub trait_: Option<(Option<Token![!]>, Path, Token![for])>,
David Tolnay570695e2017-06-03 16:15:13 -0700206 /// The Self type of the impl.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800207 pub self_ty: Box<Type>,
David Tolnay32954ef2017-12-26 22:43:16 -0500208 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700209 pub items: Vec<ImplItem>,
210 }),
David Tolnay2b214082018-01-07 01:30:18 -0800211
212 /// A macro invocation, which includes `macro_rules!` definitions.
David Tolnay461d98e2018-01-07 11:07:19 -0800213 ///
214 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800215 pub Macro(ItemMacro {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800216 pub attrs: Vec<Attribute>,
David Tolnay99a953d2017-11-11 12:51:43 -0800217 /// The `example` in `macro_rules! example { ... }`.
218 pub ident: Option<Ident>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800219 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500220 pub semi_token: Option<Token![;]>,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800221 }),
David Tolnay2b214082018-01-07 01:30:18 -0800222
223 /// A 2.0-style declarative macro introduced by the `macro` keyword.
David Tolnay461d98e2018-01-07 11:07:19 -0800224 ///
225 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay9c76bcb2017-12-26 23:14:59 -0500226 pub Macro2(ItemMacro2 #manual_extra_traits {
David Tolnay500d8322017-12-18 00:32:51 -0800227 pub attrs: Vec<Attribute>,
228 pub vis: Visibility,
229 pub macro_token: Token![macro],
230 pub ident: Ident,
David Tolnayab919512017-12-30 23:31:51 -0500231 pub paren_token: Paren,
232 pub args: TokenStream,
233 pub brace_token: Brace,
234 pub body: TokenStream,
David Tolnay500d8322017-12-18 00:32:51 -0800235 }),
David Tolnay2b214082018-01-07 01:30:18 -0800236
237 /// Tokens forming an item not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800238 ///
239 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500240 pub Verbatim(ItemVerbatim #manual_extra_traits {
241 pub tts: TokenStream,
242 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700243 }
David Tolnayb79ee962016-09-04 09:39:20 -0700244}
245
David Tolnay9c76bcb2017-12-26 23:14:59 -0500246#[cfg(feature = "extra-traits")]
247impl Eq for ItemMacro2 {}
248
249#[cfg(feature = "extra-traits")]
250impl PartialEq for ItemMacro2 {
251 fn eq(&self, other: &Self) -> bool {
David Tolnay51382052017-12-27 13:46:21 -0500252 self.attrs == other.attrs && self.vis == other.vis && self.macro_token == other.macro_token
David Tolnayab919512017-12-30 23:31:51 -0500253 && self.ident == other.ident && self.paren_token == other.paren_token
254 && TokenStreamHelper(&self.args) == TokenStreamHelper(&other.args)
255 && self.brace_token == other.brace_token
256 && TokenStreamHelper(&self.body) == TokenStreamHelper(&other.body)
David Tolnay9c76bcb2017-12-26 23:14:59 -0500257 }
258}
259
260#[cfg(feature = "extra-traits")]
261impl Hash for ItemMacro2 {
262 fn hash<H>(&self, state: &mut H)
David Tolnay51382052017-12-27 13:46:21 -0500263 where
264 H: Hasher,
David Tolnay9c76bcb2017-12-26 23:14:59 -0500265 {
266 self.attrs.hash(state);
267 self.vis.hash(state);
268 self.macro_token.hash(state);
269 self.ident.hash(state);
David Tolnayab919512017-12-30 23:31:51 -0500270 self.paren_token.hash(state);
271 TokenStreamHelper(&self.args).hash(state);
272 self.brace_token.hash(state);
273 TokenStreamHelper(&self.body).hash(state);
David Tolnay9c76bcb2017-12-26 23:14:59 -0500274 }
275}
276
David Tolnay2ae520a2017-12-29 11:19:50 -0500277#[cfg(feature = "extra-traits")]
278impl Eq for ItemVerbatim {}
279
280#[cfg(feature = "extra-traits")]
281impl PartialEq for ItemVerbatim {
282 fn eq(&self, other: &Self) -> bool {
283 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
284 }
285}
286
287#[cfg(feature = "extra-traits")]
288impl Hash for ItemVerbatim {
289 fn hash<H>(&self, state: &mut H)
290 where
291 H: Hasher,
292 {
293 TokenStreamHelper(&self.tts).hash(state);
294 }
295}
296
David Tolnay0e837402016-12-22 17:25:55 -0500297impl From<DeriveInput> for Item {
298 fn from(input: DeriveInput) -> Item {
David Tolnaye3d41b72017-12-31 15:24:00 -0500299 match input.data {
300 Data::Struct(data) => Item::Struct(ItemStruct {
301 attrs: input.attrs,
302 vis: input.vis,
303 struct_token: data.struct_token,
304 ident: input.ident,
305 generics: input.generics,
306 fields: data.fields,
307 semi_token: data.semi_token,
308 }),
309 Data::Enum(data) => Item::Enum(ItemEnum {
David Tolnay51382052017-12-27 13:46:21 -0500310 attrs: input.attrs,
311 vis: input.vis,
312 enum_token: data.enum_token,
313 ident: input.ident,
314 generics: input.generics,
315 brace_token: data.brace_token,
316 variants: data.variants,
317 }),
David Tolnaye3d41b72017-12-31 15:24:00 -0500318 Data::Union(data) => Item::Union(ItemUnion {
David Tolnay51382052017-12-27 13:46:21 -0500319 attrs: input.attrs,
320 vis: input.vis,
David Tolnaye3d41b72017-12-31 15:24:00 -0500321 union_token: data.union_token,
David Tolnay51382052017-12-27 13:46:21 -0500322 ident: input.ident,
323 generics: input.generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500324 fields: data.fields,
David Tolnay51382052017-12-27 13:46:21 -0500325 }),
David Tolnay453cfd12016-10-23 11:00:14 -0700326 }
327 }
328}
329
Alex Crichton62a0a592017-05-22 13:58:53 -0700330ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800331 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
David Tolnay614a0142018-01-07 10:25:43 -0800332 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800333 /// *This type is available if Syn is built with the `"full"` feature.*
334 ///
David Tolnay614a0142018-01-07 10:25:43 -0800335 /// # Syntax tree enum
336 ///
337 /// This type is a [syntax tree enum].
338 ///
339 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay5f332a92017-12-26 00:42:45 -0500340 pub enum UseTree {
David Tolnay05658502018-01-07 09:56:37 -0800341 /// An identifier imported by a `use` item: `Type` or `Type as Renamed`.
David Tolnay461d98e2018-01-07 11:07:19 -0800342 ///
343 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500344 pub Path(UsePath {
345 pub ident: Ident,
346 pub rename: Option<(Token![as], Ident)>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700347 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800348
David Tolnay05658502018-01-07 09:56:37 -0800349 /// A glob import in a `use` item: `*`.
David Tolnay461d98e2018-01-07 11:07:19 -0800350 ///
351 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500352 pub Glob(UseGlob {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800353 pub star_token: Token![*],
Alex Crichton62a0a592017-05-22 13:58:53 -0700354 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800355
David Tolnay05658502018-01-07 09:56:37 -0800356 /// A braced list of imports in a `use` item: `{A, B, C}`.
David Tolnay461d98e2018-01-07 11:07:19 -0800357 ///
358 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500359 pub List(UseList {
David Tolnay32954ef2017-12-26 22:43:16 -0500360 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500361 pub items: Punctuated<UseTree, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700362 }),
363 }
364}
365
Alex Crichton62a0a592017-05-22 13:58:53 -0700366ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800367 /// An item within an `extern` block.
David Tolnay614a0142018-01-07 10:25:43 -0800368 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800369 /// *This type is available if Syn is built with the `"full"` feature.*
370 ///
David Tolnay614a0142018-01-07 10:25:43 -0800371 /// # Syntax tree enum
372 ///
373 /// This type is a [syntax tree enum].
374 ///
375 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay8894f602017-11-11 12:11:04 -0800376 pub enum ForeignItem {
David Tolnayebb72722018-01-07 01:14:13 -0800377 /// A foreign function in an `extern` block.
David Tolnay461d98e2018-01-07 11:07:19 -0800378 ///
379 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700380 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800381 pub attrs: Vec<Attribute>,
382 pub vis: Visibility,
383 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700384 pub decl: Box<FnDecl>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800385 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700386 }),
David Tolnayebb72722018-01-07 01:14:13 -0800387
388 /// A foreign static item in an `extern` block: `static ext: u8`.
David Tolnay461d98e2018-01-07 11:07:19 -0800389 ///
390 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700391 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800392 pub attrs: Vec<Attribute>,
393 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800394 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -0500395 pub mutability: Option<Token![mut]>,
David Tolnay8894f602017-11-11 12:11:04 -0800396 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800397 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800398 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800399 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700400 }),
David Tolnayebb72722018-01-07 01:14:13 -0800401
402 /// A foreign type in an `extern` block: `type void`.
David Tolnay461d98e2018-01-07 11:07:19 -0800403 ///
404 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay199bcbb2017-11-12 10:33:52 -0800405 pub Type(ForeignItemType {
406 pub attrs: Vec<Attribute>,
407 pub vis: Visibility,
408 pub type_token: Token![type],
409 pub ident: Ident,
410 pub semi_token: Token![;],
411 }),
David Tolnayebb72722018-01-07 01:14:13 -0800412
413 /// Tokens in an `extern` block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800414 ///
415 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500416 pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
417 pub tts: TokenStream,
418 }),
419 }
420}
421
422#[cfg(feature = "extra-traits")]
423impl Eq for ForeignItemVerbatim {}
424
425#[cfg(feature = "extra-traits")]
426impl PartialEq for ForeignItemVerbatim {
427 fn eq(&self, other: &Self) -> bool {
428 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
429 }
430}
431
432#[cfg(feature = "extra-traits")]
433impl Hash for ForeignItemVerbatim {
434 fn hash<H>(&self, state: &mut H)
435 where
436 H: Hasher,
437 {
438 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700439 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700440}
441
David Tolnayda705bd2017-11-10 21:58:05 -0800442ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800443 /// An item declaration within the definition of a trait.
David Tolnay614a0142018-01-07 10:25:43 -0800444 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800445 /// *This type is available if Syn is built with the `"full"` feature.*
446 ///
David Tolnay614a0142018-01-07 10:25:43 -0800447 /// # Syntax tree enum
448 ///
449 /// This type is a [syntax tree enum].
450 ///
451 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayda705bd2017-11-10 21:58:05 -0800452 pub enum TraitItem {
David Tolnayebb72722018-01-07 01:14:13 -0800453 /// An associated constant within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800454 ///
455 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700456 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800457 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800458 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700459 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800460 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800461 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800462 pub default: Option<(Token![=], Expr)>,
463 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700464 }),
David Tolnayebb72722018-01-07 01:14:13 -0800465
466 /// A trait method within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800467 ///
468 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700469 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800470 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700471 pub sig: MethodSig,
472 pub default: Option<Block>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800473 pub semi_token: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700474 }),
David Tolnayebb72722018-01-07 01:14:13 -0800475
476 /// An associated type within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800477 ///
478 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700479 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800480 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800481 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700482 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500483 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800484 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500485 pub bounds: Punctuated<TypeParamBound, Token![+]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800486 pub default: Option<(Token![=], Type)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800487 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700488 }),
David Tolnayebb72722018-01-07 01:14:13 -0800489
490 /// A macro invocation within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800491 ///
492 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800493 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800494 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800495 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500496 pub semi_token: Option<Token![;]>,
David Tolnayda705bd2017-11-10 21:58:05 -0800497 }),
David Tolnayebb72722018-01-07 01:14:13 -0800498
499 /// Tokens within the definition of a trait not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800500 ///
501 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500502 pub Verbatim(TraitItemVerbatim #manual_extra_traits {
503 pub tts: TokenStream,
504 }),
505 }
506}
507
508#[cfg(feature = "extra-traits")]
509impl Eq for TraitItemVerbatim {}
510
511#[cfg(feature = "extra-traits")]
512impl PartialEq for TraitItemVerbatim {
513 fn eq(&self, other: &Self) -> bool {
514 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
515 }
516}
517
518#[cfg(feature = "extra-traits")]
519impl Hash for TraitItemVerbatim {
520 fn hash<H>(&self, state: &mut H)
521 where
522 H: Hasher,
523 {
524 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700525 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700526}
527
Alex Crichton62a0a592017-05-22 13:58:53 -0700528ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800529 /// An item within an impl block.
David Tolnay614a0142018-01-07 10:25:43 -0800530 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800531 /// *This type is available if Syn is built with the `"full"` feature.*
532 ///
David Tolnay614a0142018-01-07 10:25:43 -0800533 /// # Syntax tree enum
534 ///
535 /// This type is a [syntax tree enum].
536 ///
537 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay857628c2017-11-11 12:25:31 -0800538 pub enum ImplItem {
David Tolnayebb72722018-01-07 01:14:13 -0800539 /// An associated constant within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800540 ///
541 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700542 pub Const(ImplItemConst {
David Tolnay857628c2017-11-11 12:25:31 -0800543 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700544 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500545 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800546 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700547 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800548 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800549 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800550 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -0700551 pub expr: Expr,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800552 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700553 }),
David Tolnayebb72722018-01-07 01:14:13 -0800554
555 /// A method within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800556 ///
557 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700558 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800559 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700560 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500561 pub defaultness: Option<Token![default]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700562 pub sig: MethodSig,
563 pub block: Block,
564 }),
David Tolnayebb72722018-01-07 01:14:13 -0800565
566 /// An associated type within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800567 ///
568 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700569 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800570 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700571 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500572 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800573 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700574 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500575 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800576 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800577 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800578 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700579 }),
David Tolnayebb72722018-01-07 01:14:13 -0800580
581 /// A macro invocation within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800582 ///
583 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay857628c2017-11-11 12:25:31 -0800584 pub Macro(ImplItemMacro {
585 pub attrs: Vec<Attribute>,
586 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500587 pub semi_token: Option<Token![;]>,
David Tolnay857628c2017-11-11 12:25:31 -0800588 }),
David Tolnayebb72722018-01-07 01:14:13 -0800589
590 /// Tokens within an impl block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800591 ///
592 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500593 pub Verbatim(ImplItemVerbatim #manual_extra_traits {
594 pub tts: TokenStream,
595 }),
596 }
597}
598
599#[cfg(feature = "extra-traits")]
600impl Eq for ImplItemVerbatim {}
601
602#[cfg(feature = "extra-traits")]
603impl PartialEq for ImplItemVerbatim {
604 fn eq(&self, other: &Self) -> bool {
605 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
606 }
607}
608
609#[cfg(feature = "extra-traits")]
610impl Hash for ImplItemVerbatim {
611 fn hash<H>(&self, state: &mut H)
612 where
613 H: Hasher,
614 {
615 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700616 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700617}
618
619ast_struct! {
David Tolnay05658502018-01-07 09:56:37 -0800620 /// A method's signature in a trait or implementation: `unsafe fn
621 /// initialize(&self)`.
David Tolnay461d98e2018-01-07 11:07:19 -0800622 ///
623 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700624 pub struct MethodSig {
David Tolnay360a6342017-12-29 02:22:11 -0500625 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -0500626 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700627 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700628 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700629 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700630 }
631}
632
633ast_struct! {
David Tolnayebb72722018-01-07 01:14:13 -0800634 /// Header of a function declaration, without including the body.
David Tolnay461d98e2018-01-07 11:07:19 -0800635 ///
636 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700637 pub struct FnDecl {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800638 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500639 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500640 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -0500641 pub inputs: Punctuated<FnArg, Token![,]>,
David Tolnayd2836e22017-12-27 23:13:00 -0500642 pub variadic: Option<Token![...]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500643 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700644 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700645}
646
Alex Crichton62a0a592017-05-22 13:58:53 -0700647ast_enum_of_structs! {
David Tolnayc0435192018-01-07 11:46:08 -0800648 /// An argument in a function signature: the `n: usize` in `fn f(n: usize)`.
David Tolnay614a0142018-01-07 10:25:43 -0800649 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800650 /// *This type is available if Syn is built with the `"full"` feature.*
651 ///
David Tolnay614a0142018-01-07 10:25:43 -0800652 /// # Syntax tree enum
653 ///
654 /// This type is a [syntax tree enum].
655 ///
656 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700657 pub enum FnArg {
David Tolnay3f559052018-01-06 23:59:48 -0800658 /// Self captured by reference in a function signature: `&self` or `&mut
659 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800660 ///
661 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700662 pub SelfRef(ArgSelfRef {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800663 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -0700664 pub lifetime: Option<Lifetime>,
David Tolnay24237fb2017-12-29 02:15:26 -0500665 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500666 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700667 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800668
David Tolnay3f559052018-01-06 23:59:48 -0800669 /// Self captured by value in a function signature: `self` or `mut
670 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800671 ///
672 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700673 pub SelfValue(ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500674 pub mutability: Option<Token![mut]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800675 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700676 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800677
David Tolnay3f559052018-01-06 23:59:48 -0800678 /// An explicitly typed pattern captured by a function signature.
David Tolnay461d98e2018-01-07 11:07:19 -0800679 ///
680 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700681 pub Captured(ArgCaptured {
682 pub pat: Pat,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800683 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800684 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700685 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800686
David Tolnay3f559052018-01-06 23:59:48 -0800687 /// A pattern whose type is inferred captured by a function signature.
David Tolnay80ed55f2017-12-27 22:54:40 -0500688 pub Inferred(Pat),
David Tolnay3f559052018-01-06 23:59:48 -0800689 /// A type not bound to any pattern in a function signature.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800690 pub Ignored(Type),
Alex Crichton62a0a592017-05-22 13:58:53 -0700691 }
David Tolnay62f374c2016-10-02 13:37:00 -0700692}
693
David Tolnayedf2b992016-09-23 20:43:45 -0700694#[cfg(feature = "parsing")]
695pub mod parsing {
696 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700697
David Tolnaydfc886b2018-01-06 08:03:09 -0800698 use buffer::Cursor;
699 use synom::{PResult, Synom};
David Tolnay84aa0752016-10-02 23:01:13 -0700700
David Tolnay4c614be2017-11-10 00:02:38 -0800701 impl_synom!(Item "item" alt!(
702 syn!(ItemExternCrate) => { Item::ExternCrate }
703 |
704 syn!(ItemUse) => { Item::Use }
705 |
706 syn!(ItemStatic) => { Item::Static }
707 |
708 syn!(ItemConst) => { Item::Const }
709 |
710 syn!(ItemFn) => { Item::Fn }
711 |
712 syn!(ItemMod) => { Item::Mod }
713 |
714 syn!(ItemForeignMod) => { Item::ForeignMod }
715 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800716 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800717 |
718 syn!(ItemStruct) => { Item::Struct }
719 |
720 syn!(ItemEnum) => { Item::Enum }
721 |
722 syn!(ItemUnion) => { Item::Union }
723 |
724 syn!(ItemTrait) => { Item::Trait }
725 |
David Tolnay03342952017-12-29 11:52:00 -0500726 call!(deprecated_default_impl) => { Item::Verbatim }
David Tolnay4c614be2017-11-10 00:02:38 -0800727 |
728 syn!(ItemImpl) => { Item::Impl }
729 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800730 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800731 |
732 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800733 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700734
David Tolnaydecf28d2017-11-11 11:56:45 -0800735 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500736 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700737 what: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800738 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700739 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500740 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500741 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800742 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700743 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800744 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800745 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500746 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700747 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500748 delimiter: body.0,
749 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800750 },
David Tolnay57292da2017-12-27 21:03:33 -0500751 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800752 })
David Tolnayedf2b992016-09-23 20:43:45 -0700753 ));
754
David Tolnay500d8322017-12-18 00:32:51 -0800755 // TODO: figure out the actual grammar; is body required to be braced?
756 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500757 attrs: many0!(Attribute::parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800758 vis: syn!(Visibility) >>
759 macro_: keyword!(macro) >>
760 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500761 args: call!(tt::parenthesized) >>
762 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800763 (ItemMacro2 {
764 attrs: attrs,
765 vis: vis,
766 macro_token: macro_,
767 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500768 paren_token: args.0,
769 args: args.1,
770 brace_token: body.0,
771 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800772 })
773 ));
774
David Tolnay4c614be2017-11-10 00:02:38 -0800775 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500776 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700777 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800778 extern_: keyword!(extern) >>
779 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700780 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800781 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
782 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800783 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700784 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800785 vis: vis,
786 extern_token: extern_,
787 crate_token: crate_,
788 ident: ident,
789 rename: rename,
790 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800791 })
David Tolnayedf2b992016-09-23 20:43:45 -0700792 ));
793
David Tolnay4c614be2017-11-10 00:02:38 -0800794 impl_synom!(ItemUse "use item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500795 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700796 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800797 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500798 leading_colon: option!(punct!(::)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500799 mut prefix: call!(Punctuated::parse_terminated_with, use_prefix) >>
David Tolnay8edcef12017-12-28 12:06:52 -0500800 tree: switch!(value!(prefix.empty_or_trailing()),
David Tolnay5f332a92017-12-26 00:42:45 -0500801 true => syn!(UseTree)
802 |
David Tolnay8edcef12017-12-28 12:06:52 -0500803 false => alt!(
804 tuple!(keyword!(as), syn!(Ident)) => {
805 |rename| UseTree::Path(UsePath {
David Tolnay56080682018-01-06 14:01:52 -0800806 ident: prefix.pop().unwrap().into_value(),
David Tolnay8edcef12017-12-28 12:06:52 -0500807 rename: Some(rename),
808 })
809 }
David Tolnay5f332a92017-12-26 00:42:45 -0500810 |
David Tolnay8edcef12017-12-28 12:06:52 -0500811 epsilon!() => {
812 |_| UseTree::Path(UsePath {
David Tolnay56080682018-01-06 14:01:52 -0800813 ident: prefix.pop().unwrap().into_value(),
David Tolnay8edcef12017-12-28 12:06:52 -0500814 rename: None,
815 })
816 }
David Tolnay5f332a92017-12-26 00:42:45 -0500817 )
818 ) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800819 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800820 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700821 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800822 vis: vis,
823 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500824 leading_colon: leading_colon,
825 prefix: prefix,
826 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800827 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800828 })
David Tolnay4a057422016-10-08 00:02:31 -0700829 ));
830
David Tolnay5f332a92017-12-26 00:42:45 -0500831 named!(use_prefix -> Ident, alt!(
832 syn!(Ident)
833 |
834 keyword!(self) => { Into::into }
835 |
836 keyword!(super) => { Into::into }
837 |
838 keyword!(crate) => { Into::into }
839 ));
840
841 impl_synom!(UseTree "use tree" alt!(
842 syn!(UsePath) => { UseTree::Path }
843 |
844 syn!(UseGlob) => { UseTree::Glob }
845 |
846 syn!(UseList) => { UseTree::List }
847 ));
848
849 impl_synom!(UsePath "use path" do_parse!(
850 ident: alt!(
851 syn!(Ident)
Michael Layzell92639a52017-06-01 00:07:44 -0400852 |
David Tolnay5f332a92017-12-26 00:42:45 -0500853 keyword!(self) => { Into::into }
854 ) >>
855 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
856 (UsePath {
857 ident: ident,
858 rename: rename,
859 })
860 ));
David Tolnay4a057422016-10-08 00:02:31 -0700861
David Tolnay5f332a92017-12-26 00:42:45 -0500862 impl_synom!(UseGlob "use glob" do_parse!(
863 star: punct!(*) >>
864 (UseGlob {
865 star_token: star,
866 })
867 ));
David Tolnay4a057422016-10-08 00:02:31 -0700868
David Tolnay5f332a92017-12-26 00:42:45 -0500869 impl_synom!(UseList "use list" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500870 list: braces!(Punctuated::parse_terminated) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500871 (UseList {
David Tolnay8875fca2017-12-31 13:52:37 -0500872 brace_token: list.0,
873 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500874 })
875 ));
David Tolnay4a057422016-10-08 00:02:31 -0700876
David Tolnay4c614be2017-11-10 00:02:38 -0800877 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500878 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700879 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800880 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500881 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700882 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800883 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800884 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800885 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700886 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800887 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800888 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700889 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800890 vis: vis,
891 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500892 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800893 ident: ident,
894 colon_token: colon,
895 ty: Box::new(ty),
896 eq_token: eq,
897 expr: Box::new(value),
898 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800899 })
David Tolnay47a877c2016-10-01 16:50:55 -0700900 ));
901
David Tolnay4c614be2017-11-10 00:02:38 -0800902 impl_synom!(ItemConst "const item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500903 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700904 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800905 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700906 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800907 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800908 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800909 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700910 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800911 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800912 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700913 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800914 vis: vis,
915 const_token: const_,
916 ident: ident,
917 colon_token: colon,
918 ty: Box::new(ty),
919 eq_token: eq,
920 expr: Box::new(value),
921 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800922 })
David Tolnay47a877c2016-10-01 16:50:55 -0700923 ));
924
David Tolnay4c614be2017-11-10 00:02:38 -0800925 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500926 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700927 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -0500928 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500929 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700930 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800931 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -0700932 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700933 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500934 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800935 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -0500936 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700937 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -0500938 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -0700939 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -0400940 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800941 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -0700942 attrs: {
943 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -0500944 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -0700945 attrs
946 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800947 vis: vis,
948 constness: constness,
949 unsafety: unsafety,
950 abi: abi,
951 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800952 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500953 paren_token: inputs.0,
954 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800955 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -0500956 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800957 generics: Generics {
958 where_clause: where_clause,
959 .. generics
960 },
961 }),
962 ident: ident,
963 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -0500964 brace_token: inner_attrs_stmts.0,
965 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800966 }),
David Tolnay4c614be2017-11-10 00:02:38 -0800967 })
David Tolnay42602292016-10-01 22:25:45 -0700968 ));
969
Alex Crichton954046c2017-05-30 21:49:42 -0700970 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400971 named!(parse -> Self, alt!(
972 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800973 and: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400974 lt: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500975 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800976 self_: keyword!(self) >>
977 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400978 (ArgSelfRef {
979 lifetime: lt,
David Tolnay24237fb2017-12-29 02:15:26 -0500980 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400981 and_token: and,
982 self_token: self_,
983 }.into())
984 )
985 |
986 do_parse!(
David Tolnay24237fb2017-12-29 02:15:26 -0500987 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800988 self_: keyword!(self) >>
989 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400990 (ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500991 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400992 self_token: self_,
993 }.into())
994 )
995 |
996 do_parse!(
997 pat: syn!(Pat) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800998 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800999 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001000 (ArgCaptured {
1001 pat: pat,
1002 ty: ty,
1003 colon_token: colon,
1004 }.into())
1005 )
1006 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001007 syn!(Type) => { FnArg::Ignored }
Michael Layzell92639a52017-06-01 00:07:44 -04001008 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001009
1010 fn description() -> Option<&'static str> {
1011 Some("function argument")
1012 }
Alex Crichton954046c2017-05-30 21:49:42 -07001013 }
David Tolnay62f374c2016-10-02 13:37:00 -07001014
David Tolnay4c614be2017-11-10 00:02:38 -08001015 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001016 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001017 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001018 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -07001019 ident: syn!(Ident) >>
1020 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001021 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -07001022 Vec::new(),
1023 None,
1024 Some(semi),
1025 )}
David Tolnay37d10332016-10-13 20:51:04 -07001026 |
Alex Crichton954046c2017-05-30 21:49:42 -07001027 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -07001028 tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001029 many0!(Attribute::parse_inner),
1030 many0!(Item::parse)
Michael Layzell416724e2017-05-24 21:12:34 -04001031 )
David Tolnay8875fca2017-12-31 13:52:37 -05001032 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -07001033 inner_attrs,
1034 Some((brace, items)),
1035 None,
1036 )}
David Tolnay37d10332016-10-13 20:51:04 -07001037 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001038 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -07001039 attrs: {
1040 let mut attrs = outer_attrs;
1041 attrs.extend(content_semi.0);
1042 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -07001043 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001044 vis: vis,
1045 mod_token: mod_,
1046 ident: ident,
1047 content: content_semi.1,
1048 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -08001049 })
David Tolnay35902302016-10-06 01:11:08 -07001050 ));
1051
David Tolnay4c614be2017-11-10 00:02:38 -08001052 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001053 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001054 abi: syn!(Abi) >>
David Tolnay2c136452017-12-27 14:13:32 -05001055 items: braces!(many0!(ForeignItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001056 (ItemForeignMod {
David Tolnay35902302016-10-06 01:11:08 -07001057 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001058 abi: abi,
David Tolnay8875fca2017-12-31 13:52:37 -05001059 brace_token: items.0,
1060 items: items.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001061 })
David Tolnay35902302016-10-06 01:11:08 -07001062 ));
1063
David Tolnay8894f602017-11-11 12:11:04 -08001064 impl_synom!(ForeignItem "foreign item" alt!(
1065 syn!(ForeignItemFn) => { ForeignItem::Fn }
1066 |
1067 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -08001068 |
1069 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay8894f602017-11-11 12:11:04 -08001070 ));
David Tolnay35902302016-10-06 01:11:08 -07001071
David Tolnay8894f602017-11-11 12:11:04 -08001072 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001073 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001074 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001075 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001076 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001077 generics: syn!(Generics) >>
1078 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -05001079 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -05001080 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001081 (args, variadic)
1082 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001083 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001084 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001085 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001086 ({
David Tolnay8875fca2017-12-31 13:52:37 -05001087 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -08001088 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -07001089 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -07001090 attrs: attrs,
1091 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001092 decl: Box::new(FnDecl {
1093 fn_token: fn_,
1094 paren_token: parens,
1095 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001096 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001097 output: ret,
1098 generics: Generics {
1099 where_clause: where_clause,
1100 .. generics
1101 },
1102 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001103 vis: vis,
1104 }
David Tolnay35902302016-10-06 01:11:08 -07001105 })
1106 ));
1107
David Tolnay8894f602017-11-11 12:11:04 -08001108 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001109 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001110 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001111 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001112 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001113 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001114 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001115 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001116 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001117 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001118 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001119 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001120 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001121 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001122 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001123 static_token: static_,
1124 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001125 vis: vis,
1126 })
1127 ));
1128
David Tolnay199bcbb2017-11-12 10:33:52 -08001129 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001130 attrs: many0!(Attribute::parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001131 vis: syn!(Visibility) >>
1132 type_: keyword!(type) >>
1133 ident: syn!(Ident) >>
1134 semi: punct!(;) >>
1135 (ForeignItemType {
1136 attrs: attrs,
1137 vis: vis,
1138 type_token: type_,
1139 ident: ident,
1140 semi_token: semi,
1141 })
1142 ));
1143
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001144 impl_synom!(ItemType "type item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001145 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001146 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001147 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001148 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001149 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001150 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001151 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001152 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001153 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001154 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001155 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001156 vis: vis,
1157 type_token: type_,
1158 ident: ident,
1159 generics: Generics {
1160 where_clause: where_clause,
1161 ..generics
1162 },
1163 eq_token: eq,
1164 ty: Box::new(ty),
1165 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001166 })
David Tolnay3cf52982016-10-01 17:11:37 -07001167 ));
1168
David Tolnay4c614be2017-11-10 00:02:38 -08001169 impl_synom!(ItemStruct "struct item" switch!(
1170 map!(syn!(DeriveInput), Into::into),
1171 Item::Struct(item) => value!(item)
1172 |
1173 _ => reject!()
1174 ));
David Tolnay42602292016-10-01 22:25:45 -07001175
David Tolnay4c614be2017-11-10 00:02:38 -08001176 impl_synom!(ItemEnum "enum item" switch!(
1177 map!(syn!(DeriveInput), Into::into),
1178 Item::Enum(item) => value!(item)
1179 |
1180 _ => reject!()
1181 ));
1182
1183 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001184 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001185 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001186 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001187 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001188 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001189 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001190 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001191 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001192 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001193 vis: vis,
1194 union_token: union_,
1195 ident: ident,
1196 generics: Generics {
1197 where_clause: where_clause,
1198 .. generics
1199 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001200 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001201 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001202 ));
1203
David Tolnay4c614be2017-11-10 00:02:38 -08001204 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001205 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001206 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001207 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001208 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001209 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001210 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001211 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001212 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001213 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001214 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001215 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001216 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001217 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001218 vis: vis,
1219 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001220 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001221 trait_token: trait_,
1222 ident: ident,
1223 generics: Generics {
1224 where_clause: where_clause,
1225 .. generics
1226 },
1227 colon_token: colon,
1228 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001229 brace_token: body.0,
1230 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001231 })
David Tolnay0aecb732016-10-03 23:03:50 -07001232 ));
1233
David Tolnay03342952017-12-29 11:52:00 -05001234 fn grab_cursor(cursor: Cursor) -> PResult<Cursor> {
1235 Ok((cursor, cursor))
1236 }
1237
1238 named!(deprecated_default_impl -> ItemVerbatim, do_parse!(
1239 begin: call!(grab_cursor) >>
1240 many0!(Attribute::parse_outer) >>
1241 option!(keyword!(unsafe)) >>
1242 keyword!(impl) >>
1243 syn!(Path) >>
1244 keyword!(for) >>
1245 punct!(..) >>
1246 braces!(epsilon!()) >>
1247 end: call!(grab_cursor) >>
1248 ({
David Tolnay61037c62018-01-05 16:21:03 -08001249 let tts = begin.token_stream().into_iter().collect::<Vec<_>>();
David Tolnay03342952017-12-29 11:52:00 -05001250 let len = tts.len() - end.token_stream().into_iter().count();
1251 ItemVerbatim {
1252 tts: tts.into_iter().take(len).collect(),
1253 }
David Tolnay4c614be2017-11-10 00:02:38 -08001254 })
David Tolnayf94e2362016-10-04 00:29:51 -07001255 ));
1256
David Tolnayda705bd2017-11-10 21:58:05 -08001257 impl_synom!(TraitItem "trait item" alt!(
1258 syn!(TraitItemConst) => { TraitItem::Const }
1259 |
1260 syn!(TraitItemMethod) => { TraitItem::Method }
1261 |
1262 syn!(TraitItemType) => { TraitItem::Type }
1263 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001264 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001265 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001266
David Tolnayda705bd2017-11-10 21:58:05 -08001267 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001268 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001269 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001270 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001271 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001272 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001273 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1274 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001275 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001276 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001277 const_token: const_,
1278 ident: ident,
1279 colon_token: colon,
1280 ty: ty,
1281 default: default,
1282 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001283 })
1284 ));
1285
David Tolnayda705bd2017-11-10 21:58:05 -08001286 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001287 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001288 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001289 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001290 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001291 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001292 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001293 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001294 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001295 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001296 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001297 body: option!(braces!(
David Tolnay2c136452017-12-27 14:13:32 -05001298 tuple!(many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001299 call!(Block::parse_within))
David Tolnay5859df12016-10-29 22:49:54 -07001300 )) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001301 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001302 ({
1303 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001304 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001305 None => (Vec::new(), None),
1306 };
David Tolnayda705bd2017-11-10 21:58:05 -08001307 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001308 attrs: {
1309 let mut attrs = outer_attrs;
1310 attrs.extend(inner_attrs);
1311 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001312 },
David Tolnayda705bd2017-11-10 21:58:05 -08001313 sig: MethodSig {
1314 constness: constness,
1315 unsafety: unsafety,
1316 abi: abi,
1317 ident: ident,
1318 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001319 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001320 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001321 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001322 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001323 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001324 generics: Generics {
1325 where_clause: where_clause,
1326 .. generics
David Tolnay5859df12016-10-29 22:49:54 -07001327 },
1328 },
David Tolnayda705bd2017-11-10 21:58:05 -08001329 },
1330 default: stmts.map(|stmts| {
1331 Block {
1332 stmts: stmts.0,
1333 brace_token: stmts.1,
1334 }
1335 }),
1336 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001337 }
David Tolnay0aecb732016-10-03 23:03:50 -07001338 })
1339 ));
1340
David Tolnayda705bd2017-11-10 21:58:05 -08001341 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001342 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001343 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001344 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001345 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001346 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001347 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001348 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001349 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001350 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001351 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001352 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001353 type_token: type_,
1354 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001355 generics: Generics {
1356 where_clause: where_clause,
1357 .. generics
1358 },
David Tolnayda705bd2017-11-10 21:58:05 -08001359 colon_token: colon,
1360 bounds: bounds.unwrap_or_default(),
1361 default: default,
1362 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001363 })
1364 ));
1365
David Tolnaydecf28d2017-11-11 11:56:45 -08001366 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001367 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001368 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001369 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001370 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001371 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001372 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001373 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001374 })
1375 ));
1376
David Tolnay4c614be2017-11-10 00:02:38 -08001377 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001378 attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001379 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001380 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001381 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001382 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001383 polarity_path: alt!(
1384 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001385 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001386 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001387 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001388 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001389 )
1390 |
David Tolnay570695e2017-06-03 16:15:13 -07001391 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001392 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001393 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001394 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001395 body: braces!(many0!(ImplItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001396 (ItemImpl {
David Tolnay4c9be372016-10-06 00:47:37 -07001397 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001398 defaultness: defaultness,
1399 unsafety: unsafety,
1400 impl_token: impl_,
1401 generics: Generics {
1402 where_clause: where_clause,
1403 .. generics
1404 },
1405 trait_: polarity_path,
1406 self_ty: Box::new(self_ty),
David Tolnay8875fca2017-12-31 13:52:37 -05001407 brace_token: body.0,
1408 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001409 })
David Tolnay4c9be372016-10-06 00:47:37 -07001410 ));
1411
David Tolnay857628c2017-11-11 12:25:31 -08001412 impl_synom!(ImplItem "item in impl block" alt!(
1413 syn!(ImplItemConst) => { ImplItem::Const }
1414 |
1415 syn!(ImplItemMethod) => { ImplItem::Method }
1416 |
1417 syn!(ImplItemType) => { ImplItem::Type }
1418 |
1419 syn!(ImplItemMacro) => { ImplItem::Macro }
1420 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001421
David Tolnay857628c2017-11-11 12:25:31 -08001422 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001423 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001424 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001425 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001426 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001427 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001428 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001429 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001430 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001431 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001432 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001433 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001434 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001435 vis: vis,
1436 defaultness: defaultness,
1437 const_token: const_,
1438 ident: ident,
1439 colon_token: colon,
1440 ty: ty,
1441 eq_token: eq,
1442 expr: value,
1443 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001444 })
1445 ));
1446
David Tolnay857628c2017-11-11 12:25:31 -08001447 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001448 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001449 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001450 defaultness: option!(keyword!(default)) >>
1451 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001452 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001453 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001454 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001455 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001456 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001457 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001458 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001459 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001460 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001461 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001462 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -04001463 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001464 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001465 attrs: {
1466 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001467 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001468 attrs
1469 },
David Tolnay857628c2017-11-11 12:25:31 -08001470 vis: vis,
1471 defaultness: defaultness,
1472 sig: MethodSig {
1473 constness: constness,
1474 unsafety: unsafety,
1475 abi: abi,
1476 ident: ident,
1477 decl: FnDecl {
1478 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001479 paren_token: inputs.0,
1480 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001481 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001482 generics: Generics {
1483 where_clause: where_clause,
1484 .. generics
David Tolnay4c9be372016-10-06 00:47:37 -07001485 },
David Tolnayd2836e22017-12-27 23:13:00 -05001486 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001487 },
David Tolnay857628c2017-11-11 12:25:31 -08001488 },
1489 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001490 brace_token: inner_attrs_stmts.0,
1491 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001492 },
David Tolnay4c9be372016-10-06 00:47:37 -07001493 })
1494 ));
1495
David Tolnay857628c2017-11-11 12:25:31 -08001496 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001497 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001498 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001499 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001500 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001501 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001502 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001503 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001504 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001505 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001506 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001507 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001508 vis: vis,
1509 defaultness: defaultness,
1510 type_token: type_,
1511 ident: ident,
Nika Layzell591528a2017-12-05 12:47:37 -05001512 generics: generics,
David Tolnay857628c2017-11-11 12:25:31 -08001513 eq_token: eq,
1514 ty: ty,
1515 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001516 })
1517 ));
1518
David Tolnay857628c2017-11-11 12:25:31 -08001519 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001520 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001521 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001522 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001523 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001524 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001525 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001526 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001527 })
1528 ));
1529
David Tolnayab919512017-12-30 23:31:51 -05001530 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1531 match *delimiter {
1532 MacroDelimiter::Brace(_) => true,
1533 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001534 }
1535 }
David Tolnayedf2b992016-09-23 20:43:45 -07001536}
David Tolnay4a51dc72016-10-01 00:40:31 -07001537
1538#[cfg(feature = "printing")]
1539mod printing {
1540 use super::*;
1541 use attr::FilterAttrs;
David Tolnay51382052017-12-27 13:46:21 -05001542 use quote::{ToTokens, Tokens};
David Tolnay4a51dc72016-10-01 00:40:31 -07001543
David Tolnay1bfa7332017-11-11 12:41:20 -08001544 impl ToTokens for ItemExternCrate {
David Tolnay4a51dc72016-10-01 00:40:31 -07001545 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001546 tokens.append_all(self.attrs.outer());
1547 self.vis.to_tokens(tokens);
1548 self.extern_token.to_tokens(tokens);
1549 self.crate_token.to_tokens(tokens);
1550 self.ident.to_tokens(tokens);
1551 if let Some((ref as_token, ref rename)) = self.rename {
1552 as_token.to_tokens(tokens);
1553 rename.to_tokens(tokens);
1554 }
1555 self.semi_token.to_tokens(tokens);
1556 }
1557 }
1558
1559 impl ToTokens for ItemUse {
1560 fn to_tokens(&self, tokens: &mut Tokens) {
1561 tokens.append_all(self.attrs.outer());
1562 self.vis.to_tokens(tokens);
1563 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001564 self.leading_colon.to_tokens(tokens);
1565 self.prefix.to_tokens(tokens);
1566 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001567 self.semi_token.to_tokens(tokens);
1568 }
1569 }
1570
1571 impl ToTokens for ItemStatic {
1572 fn to_tokens(&self, tokens: &mut Tokens) {
1573 tokens.append_all(self.attrs.outer());
1574 self.vis.to_tokens(tokens);
1575 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001576 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001577 self.ident.to_tokens(tokens);
1578 self.colon_token.to_tokens(tokens);
1579 self.ty.to_tokens(tokens);
1580 self.eq_token.to_tokens(tokens);
1581 self.expr.to_tokens(tokens);
1582 self.semi_token.to_tokens(tokens);
1583 }
1584 }
1585
1586 impl ToTokens for ItemConst {
1587 fn to_tokens(&self, tokens: &mut Tokens) {
1588 tokens.append_all(self.attrs.outer());
1589 self.vis.to_tokens(tokens);
1590 self.const_token.to_tokens(tokens);
1591 self.ident.to_tokens(tokens);
1592 self.colon_token.to_tokens(tokens);
1593 self.ty.to_tokens(tokens);
1594 self.eq_token.to_tokens(tokens);
1595 self.expr.to_tokens(tokens);
1596 self.semi_token.to_tokens(tokens);
1597 }
1598 }
1599
1600 impl ToTokens for ItemFn {
1601 fn to_tokens(&self, tokens: &mut Tokens) {
1602 tokens.append_all(self.attrs.outer());
1603 self.vis.to_tokens(tokens);
1604 self.constness.to_tokens(tokens);
1605 self.unsafety.to_tokens(tokens);
1606 self.abi.to_tokens(tokens);
1607 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1608 self.block.brace_token.surround(tokens, |tokens| {
1609 tokens.append_all(self.attrs.inner());
1610 tokens.append_all(&self.block.stmts);
1611 });
1612 }
1613 }
1614
1615 impl ToTokens for ItemMod {
1616 fn to_tokens(&self, tokens: &mut Tokens) {
1617 tokens.append_all(self.attrs.outer());
1618 self.vis.to_tokens(tokens);
1619 self.mod_token.to_tokens(tokens);
1620 self.ident.to_tokens(tokens);
1621 if let Some((ref brace, ref items)) = self.content {
1622 brace.surround(tokens, |tokens| {
1623 tokens.append_all(self.attrs.inner());
1624 tokens.append_all(items);
1625 });
1626 } else {
1627 TokensOrDefault(&self.semi).to_tokens(tokens);
1628 }
1629 }
1630 }
1631
1632 impl ToTokens for ItemForeignMod {
1633 fn to_tokens(&self, tokens: &mut Tokens) {
1634 tokens.append_all(self.attrs.outer());
1635 self.abi.to_tokens(tokens);
1636 self.brace_token.surround(tokens, |tokens| {
1637 tokens.append_all(&self.items);
1638 });
1639 }
1640 }
1641
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001642 impl ToTokens for ItemType {
David Tolnay1bfa7332017-11-11 12:41:20 -08001643 fn to_tokens(&self, tokens: &mut Tokens) {
1644 tokens.append_all(self.attrs.outer());
1645 self.vis.to_tokens(tokens);
1646 self.type_token.to_tokens(tokens);
1647 self.ident.to_tokens(tokens);
1648 self.generics.to_tokens(tokens);
1649 self.generics.where_clause.to_tokens(tokens);
1650 self.eq_token.to_tokens(tokens);
1651 self.ty.to_tokens(tokens);
1652 self.semi_token.to_tokens(tokens);
1653 }
1654 }
1655
1656 impl ToTokens for ItemEnum {
1657 fn to_tokens(&self, tokens: &mut Tokens) {
1658 tokens.append_all(self.attrs.outer());
1659 self.vis.to_tokens(tokens);
1660 self.enum_token.to_tokens(tokens);
1661 self.ident.to_tokens(tokens);
1662 self.generics.to_tokens(tokens);
1663 self.generics.where_clause.to_tokens(tokens);
1664 self.brace_token.surround(tokens, |tokens| {
1665 self.variants.to_tokens(tokens);
1666 });
1667 }
1668 }
1669
1670 impl ToTokens for ItemStruct {
1671 fn to_tokens(&self, tokens: &mut Tokens) {
1672 tokens.append_all(self.attrs.outer());
1673 self.vis.to_tokens(tokens);
1674 self.struct_token.to_tokens(tokens);
1675 self.ident.to_tokens(tokens);
1676 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001677 match self.fields {
1678 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001679 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001680 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001681 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001682 Fields::Unnamed(ref fields) => {
1683 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001684 self.generics.where_clause.to_tokens(tokens);
1685 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001686 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001687 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001688 self.generics.where_clause.to_tokens(tokens);
1689 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001690 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001691 }
1692 }
1693 }
1694
1695 impl ToTokens for ItemUnion {
1696 fn to_tokens(&self, tokens: &mut Tokens) {
1697 tokens.append_all(self.attrs.outer());
1698 self.vis.to_tokens(tokens);
1699 self.union_token.to_tokens(tokens);
1700 self.ident.to_tokens(tokens);
1701 self.generics.to_tokens(tokens);
1702 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001703 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001704 }
1705 }
1706
1707 impl ToTokens for ItemTrait {
1708 fn to_tokens(&self, tokens: &mut Tokens) {
1709 tokens.append_all(self.attrs.outer());
1710 self.vis.to_tokens(tokens);
1711 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001712 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001713 self.trait_token.to_tokens(tokens);
1714 self.ident.to_tokens(tokens);
1715 self.generics.to_tokens(tokens);
1716 if !self.supertraits.is_empty() {
1717 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1718 self.supertraits.to_tokens(tokens);
1719 }
1720 self.generics.where_clause.to_tokens(tokens);
1721 self.brace_token.surround(tokens, |tokens| {
1722 tokens.append_all(&self.items);
1723 });
1724 }
1725 }
1726
David Tolnay1bfa7332017-11-11 12:41:20 -08001727 impl ToTokens for ItemImpl {
1728 fn to_tokens(&self, tokens: &mut Tokens) {
1729 tokens.append_all(self.attrs.outer());
1730 self.defaultness.to_tokens(tokens);
1731 self.unsafety.to_tokens(tokens);
1732 self.impl_token.to_tokens(tokens);
1733 self.generics.to_tokens(tokens);
1734 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1735 polarity.to_tokens(tokens);
1736 path.to_tokens(tokens);
1737 for_token.to_tokens(tokens);
1738 }
1739 self.self_ty.to_tokens(tokens);
1740 self.generics.where_clause.to_tokens(tokens);
1741 self.brace_token.surround(tokens, |tokens| {
1742 tokens.append_all(&self.items);
1743 });
1744 }
1745 }
1746
1747 impl ToTokens for ItemMacro {
1748 fn to_tokens(&self, tokens: &mut Tokens) {
1749 tokens.append_all(self.attrs.outer());
1750 self.mac.path.to_tokens(tokens);
1751 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001752 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001753 match self.mac.delimiter {
1754 MacroDelimiter::Paren(ref paren) => {
1755 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1756 }
1757 MacroDelimiter::Brace(ref brace) => {
1758 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1759 }
1760 MacroDelimiter::Bracket(ref bracket) => {
1761 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1762 }
1763 }
David Tolnay57292da2017-12-27 21:03:33 -05001764 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001765 }
1766 }
David Tolnay42602292016-10-01 22:25:45 -07001767
David Tolnay500d8322017-12-18 00:32:51 -08001768 impl ToTokens for ItemMacro2 {
1769 fn to_tokens(&self, tokens: &mut Tokens) {
1770 tokens.append_all(self.attrs.outer());
1771 self.vis.to_tokens(tokens);
1772 self.macro_token.to_tokens(tokens);
1773 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001774 self.paren_token.surround(tokens, |tokens| {
1775 self.args.to_tokens(tokens);
1776 });
1777 self.brace_token.surround(tokens, |tokens| {
1778 self.body.to_tokens(tokens);
1779 });
David Tolnay500d8322017-12-18 00:32:51 -08001780 }
1781 }
1782
David Tolnay2ae520a2017-12-29 11:19:50 -05001783 impl ToTokens for ItemVerbatim {
1784 fn to_tokens(&self, tokens: &mut Tokens) {
1785 self.tts.to_tokens(tokens);
1786 }
1787 }
1788
David Tolnay5f332a92017-12-26 00:42:45 -05001789 impl ToTokens for UsePath {
David Tolnay4a057422016-10-08 00:02:31 -07001790 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay5f332a92017-12-26 00:42:45 -05001791 self.ident.to_tokens(tokens);
1792 if let Some((ref as_token, ref rename)) = self.rename {
1793 as_token.to_tokens(tokens);
1794 rename.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001795 }
David Tolnay4a057422016-10-08 00:02:31 -07001796 }
1797 }
1798
David Tolnay5f332a92017-12-26 00:42:45 -05001799 impl ToTokens for UseGlob {
Alex Crichton62a0a592017-05-22 13:58:53 -07001800 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001801 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001802 }
1803 }
1804
David Tolnay5f332a92017-12-26 00:42:45 -05001805 impl ToTokens for UseList {
Alex Crichton62a0a592017-05-22 13:58:53 -07001806 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001807 self.brace_token.surround(tokens, |tokens| {
1808 self.items.to_tokens(tokens);
1809 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001810 }
1811 }
1812
David Tolnay1bfa7332017-11-11 12:41:20 -08001813 impl ToTokens for TraitItemConst {
David Tolnayca085422016-10-04 00:12:38 -07001814 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001815 tokens.append_all(self.attrs.outer());
1816 self.const_token.to_tokens(tokens);
1817 self.ident.to_tokens(tokens);
1818 self.colon_token.to_tokens(tokens);
1819 self.ty.to_tokens(tokens);
1820 if let Some((ref eq_token, ref default)) = self.default {
1821 eq_token.to_tokens(tokens);
1822 default.to_tokens(tokens);
1823 }
1824 self.semi_token.to_tokens(tokens);
1825 }
1826 }
1827
1828 impl ToTokens for TraitItemMethod {
1829 fn to_tokens(&self, tokens: &mut Tokens) {
1830 tokens.append_all(self.attrs.outer());
1831 self.sig.to_tokens(tokens);
1832 match self.default {
1833 Some(ref block) => {
1834 block.brace_token.surround(tokens, |tokens| {
1835 tokens.append_all(self.attrs.inner());
1836 tokens.append_all(&block.stmts);
1837 });
David Tolnayca085422016-10-04 00:12:38 -07001838 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001839 None => {
1840 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001841 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001842 }
1843 }
1844 }
1845
1846 impl ToTokens for TraitItemType {
1847 fn to_tokens(&self, tokens: &mut Tokens) {
1848 tokens.append_all(self.attrs.outer());
1849 self.type_token.to_tokens(tokens);
1850 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001851 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001852 if !self.bounds.is_empty() {
1853 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1854 self.bounds.to_tokens(tokens);
1855 }
Nika Layzell0183ca32017-12-05 15:24:01 -05001856 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001857 if let Some((ref eq_token, ref default)) = self.default {
1858 eq_token.to_tokens(tokens);
1859 default.to_tokens(tokens);
1860 }
1861 self.semi_token.to_tokens(tokens);
1862 }
1863 }
1864
1865 impl ToTokens for TraitItemMacro {
1866 fn to_tokens(&self, tokens: &mut Tokens) {
1867 tokens.append_all(self.attrs.outer());
1868 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001869 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001870 }
1871 }
1872
David Tolnay2ae520a2017-12-29 11:19:50 -05001873 impl ToTokens for TraitItemVerbatim {
1874 fn to_tokens(&self, tokens: &mut Tokens) {
1875 self.tts.to_tokens(tokens);
1876 }
1877 }
1878
David Tolnay857628c2017-11-11 12:25:31 -08001879 impl ToTokens for ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001880 fn to_tokens(&self, tokens: &mut Tokens) {
1881 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08001882 self.vis.to_tokens(tokens);
1883 self.defaultness.to_tokens(tokens);
1884 self.const_token.to_tokens(tokens);
1885 self.ident.to_tokens(tokens);
1886 self.colon_token.to_tokens(tokens);
1887 self.ty.to_tokens(tokens);
1888 self.eq_token.to_tokens(tokens);
1889 self.expr.to_tokens(tokens);
1890 self.semi_token.to_tokens(tokens);
1891 }
1892 }
1893
1894 impl ToTokens for ImplItemMethod {
1895 fn to_tokens(&self, tokens: &mut Tokens) {
1896 tokens.append_all(self.attrs.outer());
1897 self.vis.to_tokens(tokens);
1898 self.defaultness.to_tokens(tokens);
1899 self.sig.to_tokens(tokens);
1900 self.block.brace_token.surround(tokens, |tokens| {
1901 tokens.append_all(self.attrs.inner());
1902 tokens.append_all(&self.block.stmts);
1903 });
1904 }
1905 }
1906
1907 impl ToTokens for ImplItemType {
1908 fn to_tokens(&self, tokens: &mut Tokens) {
1909 tokens.append_all(self.attrs.outer());
1910 self.vis.to_tokens(tokens);
1911 self.defaultness.to_tokens(tokens);
1912 self.type_token.to_tokens(tokens);
1913 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001914 self.generics.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08001915 self.eq_token.to_tokens(tokens);
1916 self.ty.to_tokens(tokens);
1917 self.semi_token.to_tokens(tokens);
1918 }
1919 }
1920
1921 impl ToTokens for ImplItemMacro {
1922 fn to_tokens(&self, tokens: &mut Tokens) {
1923 tokens.append_all(self.attrs.outer());
1924 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001925 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07001926 }
1927 }
1928
David Tolnay2ae520a2017-12-29 11:19:50 -05001929 impl ToTokens for ImplItemVerbatim {
1930 fn to_tokens(&self, tokens: &mut Tokens) {
1931 self.tts.to_tokens(tokens);
1932 }
1933 }
1934
David Tolnay8894f602017-11-11 12:11:04 -08001935 impl ToTokens for ForeignItemFn {
David Tolnay35902302016-10-06 01:11:08 -07001936 fn to_tokens(&self, tokens: &mut Tokens) {
1937 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001938 self.vis.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001939 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1940 self.semi_token.to_tokens(tokens);
1941 }
1942 }
1943
1944 impl ToTokens for ForeignItemStatic {
1945 fn to_tokens(&self, tokens: &mut Tokens) {
1946 tokens.append_all(self.attrs.outer());
1947 self.vis.to_tokens(tokens);
1948 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001949 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001950 self.ident.to_tokens(tokens);
1951 self.colon_token.to_tokens(tokens);
1952 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001953 self.semi_token.to_tokens(tokens);
1954 }
1955 }
1956
David Tolnay199bcbb2017-11-12 10:33:52 -08001957 impl ToTokens for ForeignItemType {
1958 fn to_tokens(&self, tokens: &mut Tokens) {
1959 tokens.append_all(self.attrs.outer());
1960 self.vis.to_tokens(tokens);
1961 self.type_token.to_tokens(tokens);
1962 self.ident.to_tokens(tokens);
1963 self.semi_token.to_tokens(tokens);
1964 }
1965 }
1966
David Tolnay2ae520a2017-12-29 11:19:50 -05001967 impl ToTokens for ForeignItemVerbatim {
1968 fn to_tokens(&self, tokens: &mut Tokens) {
1969 self.tts.to_tokens(tokens);
1970 }
1971 }
1972
David Tolnay570695e2017-06-03 16:15:13 -07001973 impl ToTokens for MethodSig {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001974 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay570695e2017-06-03 16:15:13 -07001975 self.constness.to_tokens(tokens);
1976 self.unsafety.to_tokens(tokens);
1977 self.abi.to_tokens(tokens);
1978 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001979 }
1980 }
1981
David Tolnay570695e2017-06-03 16:15:13 -07001982 struct NamedDecl<'a>(&'a FnDecl, Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001983
1984 impl<'a> ToTokens for NamedDecl<'a> {
1985 fn to_tokens(&self, tokens: &mut Tokens) {
1986 self.0.fn_token.to_tokens(tokens);
1987 self.1.to_tokens(tokens);
1988 self.0.generics.to_tokens(tokens);
1989 self.0.paren_token.surround(tokens, |tokens| {
1990 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05001991 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
1992 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001993 }
David Tolnayd2836e22017-12-27 23:13:00 -05001994 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001995 });
1996 self.0.output.to_tokens(tokens);
1997 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07001998 }
1999 }
2000
Alex Crichton62a0a592017-05-22 13:58:53 -07002001 impl ToTokens for ArgSelfRef {
David Tolnay62f374c2016-10-02 13:37:00 -07002002 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002003 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002004 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002005 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002006 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002007 }
2008 }
2009
2010 impl ToTokens for ArgSelf {
2011 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay24237fb2017-12-29 02:15:26 -05002012 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002013 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002014 }
2015 }
2016
2017 impl ToTokens for ArgCaptured {
2018 fn to_tokens(&self, tokens: &mut Tokens) {
2019 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002020 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002021 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07002022 }
2023 }
David Tolnay4a51dc72016-10-01 00:40:31 -07002024}