blob: beb5a9e97cc770e4701dd8897dbe43f639efeffc [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 Tolnay61037c62018-01-05 16:21:03 -080011use proc_macro2::TokenStream;
David Tolnay94d2b792018-04-29 12:26:10 -070012use punctuated::Punctuated;
David Tolnay61037c62018-01-05 16:21:03 -080013use token::{Brace, Paren};
David Tolnay9c76bcb2017-12-26 23:14:59 -050014
15#[cfg(feature = "extra-traits")]
David Tolnay9c76bcb2017-12-26 23:14:59 -050016use std::hash::{Hash, Hasher};
David Tolnay94d2b792018-04-29 12:26:10 -070017#[cfg(feature = "extra-traits")]
18use tt::TokenStreamHelper;
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 Tolnay5f332a92017-12-26 00:42:45 -050052 pub tree: UseTree,
David Tolnayf8db7ba2017-11-11 22:52:16 -080053 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070054 }),
David Tolnay2b214082018-01-07 01:30:18 -080055
56 /// A static item: `static BIKE: Shed = Shed(42)`.
David Tolnay461d98e2018-01-07 11:07:19 -080057 ///
58 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070059 pub Static(ItemStatic {
David Tolnayc6b55bc2017-11-09 22:48:38 -080060 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070061 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080062 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -050063 pub mutability: Option<Token![mut]>,
David Tolnay570695e2017-06-03 16:15:13 -070064 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080065 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080066 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080067 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070068 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080069 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070070 }),
David Tolnay2b214082018-01-07 01:30:18 -080071
72 /// A constant item: `const MAX: u16 = 65535`.
David Tolnay461d98e2018-01-07 11:07:19 -080073 ///
74 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070075 pub Const(ItemConst {
David Tolnayc6b55bc2017-11-09 22:48:38 -080076 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070077 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080078 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -070079 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080080 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080081 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080082 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070083 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080084 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070085 }),
David Tolnay2b214082018-01-07 01:30:18 -080086
David Tolnay461d98e2018-01-07 11:07:19 -080087 /// A free-standing function: `fn process(n: usize) -> Result<()> { ...
88 /// }`.
89 ///
90 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070091 pub Fn(ItemFn {
David Tolnayc6b55bc2017-11-09 22:48:38 -080092 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070093 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -050094 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -050095 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070096 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -070097 pub ident: Ident,
David Tolnay4a3f59a2017-12-28 21:21:12 -050098 pub decl: Box<FnDecl>,
Alex Crichton62a0a592017-05-22 13:58:53 -070099 pub block: Box<Block>,
100 }),
David Tolnay2b214082018-01-07 01:30:18 -0800101
102 /// A module or module declaration: `mod m` or `mod m { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800103 ///
104 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700105 pub Mod(ItemMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800106 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700107 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800108 pub mod_token: Token![mod],
David Tolnay570695e2017-06-03 16:15:13 -0700109 pub ident: Ident,
David Tolnay32954ef2017-12-26 22:43:16 -0500110 pub content: Option<(token::Brace, Vec<Item>)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800111 pub semi: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700112 }),
David Tolnay2b214082018-01-07 01:30:18 -0800113
114 /// A block of foreign items: `extern "C" { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800115 ///
116 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700117 pub ForeignMod(ItemForeignMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800118 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700119 pub abi: Abi,
David Tolnay32954ef2017-12-26 22:43:16 -0500120 pub brace_token: token::Brace,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700121 pub items: Vec<ForeignItem>,
122 }),
David Tolnay2b214082018-01-07 01:30:18 -0800123
124 /// A type alias: `type Result<T> = std::result::Result<T, MyError>`.
David Tolnay461d98e2018-01-07 11:07:19 -0800125 ///
126 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800127 pub Type(ItemType {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800128 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700129 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800130 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700131 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700132 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800133 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800134 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800135 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700136 }),
David Tolnay2b214082018-01-07 01:30:18 -0800137
138 /// A struct definition: `struct Foo<A> { x: A }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800139 ///
140 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaye3d41b72017-12-31 15:24:00 -0500141 pub Struct(ItemStruct {
142 pub attrs: Vec<Attribute>,
143 pub vis: Visibility,
144 pub struct_token: Token![struct],
145 pub ident: Ident,
146 pub generics: Generics,
147 pub fields: Fields,
148 pub semi_token: Option<Token![;]>,
149 }),
David Tolnay2b214082018-01-07 01:30:18 -0800150
151 /// An enum definition: `enum Foo<A, B> { C<A>, D<B> }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800152 ///
153 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700154 pub Enum(ItemEnum {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800155 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700156 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800157 pub enum_token: Token![enum],
David Tolnay570695e2017-06-03 16:15:13 -0700158 pub ident: Ident,
159 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500160 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500161 pub variants: Punctuated<Variant, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700162 }),
David Tolnay2b214082018-01-07 01:30:18 -0800163
164 /// A union definition: `union Foo<A, B> { x: A, y: B }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800165 ///
166 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700167 pub Union(ItemUnion {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800168 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700169 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800170 pub union_token: Token![union],
David Tolnay570695e2017-06-03 16:15:13 -0700171 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700172 pub generics: Generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500173 pub fields: FieldsNamed,
Alex Crichton62a0a592017-05-22 13:58:53 -0700174 }),
David Tolnay2b214082018-01-07 01:30:18 -0800175
176 /// A trait definition: `pub trait Iterator { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800177 ///
178 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700179 pub Trait(ItemTrait {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800180 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700181 pub vis: Visibility,
David Tolnay9b258702017-12-29 02:24:41 -0500182 pub unsafety: Option<Token![unsafe]>,
Nika Layzell0dc6e632017-11-18 12:55:25 -0500183 pub auto_token: Option<Token![auto]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800184 pub trait_token: Token![trait],
David Tolnay570695e2017-06-03 16:15:13 -0700185 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700186 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800187 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500188 pub supertraits: Punctuated<TypeParamBound, Token![+]>,
David Tolnay32954ef2017-12-26 22:43:16 -0500189 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700190 pub items: Vec<TraitItem>,
191 }),
David Tolnay2b214082018-01-07 01:30:18 -0800192
193 /// An impl block providing trait or associated items: `impl<A> Trait
194 /// for Data<A> { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800195 ///
196 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700197 pub Impl(ItemImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800198 pub attrs: Vec<Attribute>,
David Tolnay360a6342017-12-29 02:22:11 -0500199 pub defaultness: Option<Token![default]>,
David Tolnay9b258702017-12-29 02:24:41 -0500200 pub unsafety: Option<Token![unsafe]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800201 pub impl_token: Token![impl],
Alex Crichton62a0a592017-05-22 13:58:53 -0700202 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700203 /// Trait this impl implements.
David Tolnay360a6342017-12-29 02:22:11 -0500204 pub trait_: Option<(Option<Token![!]>, Path, Token![for])>,
David Tolnay570695e2017-06-03 16:15:13 -0700205 /// The Self type of the impl.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800206 pub self_ty: Box<Type>,
David Tolnay32954ef2017-12-26 22:43:16 -0500207 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700208 pub items: Vec<ImplItem>,
209 }),
David Tolnay2b214082018-01-07 01:30:18 -0800210
211 /// A macro invocation, which includes `macro_rules!` definitions.
David Tolnay461d98e2018-01-07 11:07:19 -0800212 ///
213 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800214 pub Macro(ItemMacro {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800215 pub attrs: Vec<Attribute>,
David Tolnay99a953d2017-11-11 12:51:43 -0800216 /// The `example` in `macro_rules! example { ... }`.
217 pub ident: Option<Ident>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800218 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500219 pub semi_token: Option<Token![;]>,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800220 }),
David Tolnay2b214082018-01-07 01:30:18 -0800221
222 /// A 2.0-style declarative macro introduced by the `macro` keyword.
David Tolnay461d98e2018-01-07 11:07:19 -0800223 ///
224 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay9c76bcb2017-12-26 23:14:59 -0500225 pub Macro2(ItemMacro2 #manual_extra_traits {
David Tolnay500d8322017-12-18 00:32:51 -0800226 pub attrs: Vec<Attribute>,
227 pub vis: Visibility,
228 pub macro_token: Token![macro],
229 pub ident: Ident,
David Tolnayab919512017-12-30 23:31:51 -0500230 pub paren_token: Paren,
231 pub args: TokenStream,
232 pub brace_token: Brace,
233 pub body: TokenStream,
David Tolnay500d8322017-12-18 00:32:51 -0800234 }),
David Tolnay2b214082018-01-07 01:30:18 -0800235
236 /// Tokens forming an item not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800237 ///
238 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500239 pub Verbatim(ItemVerbatim #manual_extra_traits {
240 pub tts: TokenStream,
241 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700242 }
David Tolnayb79ee962016-09-04 09:39:20 -0700243}
244
David Tolnay9c76bcb2017-12-26 23:14:59 -0500245#[cfg(feature = "extra-traits")]
246impl Eq for ItemMacro2 {}
247
248#[cfg(feature = "extra-traits")]
249impl PartialEq for ItemMacro2 {
250 fn eq(&self, other: &Self) -> bool {
David Tolnay51382052017-12-27 13:46:21 -0500251 self.attrs == other.attrs && self.vis == other.vis && self.macro_token == other.macro_token
David Tolnayab919512017-12-30 23:31:51 -0500252 && self.ident == other.ident && self.paren_token == other.paren_token
253 && TokenStreamHelper(&self.args) == TokenStreamHelper(&other.args)
254 && self.brace_token == other.brace_token
255 && TokenStreamHelper(&self.body) == TokenStreamHelper(&other.body)
David Tolnay9c76bcb2017-12-26 23:14:59 -0500256 }
257}
258
259#[cfg(feature = "extra-traits")]
260impl Hash for ItemMacro2 {
261 fn hash<H>(&self, state: &mut H)
David Tolnay51382052017-12-27 13:46:21 -0500262 where
263 H: Hasher,
David Tolnay9c76bcb2017-12-26 23:14:59 -0500264 {
265 self.attrs.hash(state);
266 self.vis.hash(state);
267 self.macro_token.hash(state);
268 self.ident.hash(state);
David Tolnayab919512017-12-30 23:31:51 -0500269 self.paren_token.hash(state);
270 TokenStreamHelper(&self.args).hash(state);
271 self.brace_token.hash(state);
272 TokenStreamHelper(&self.body).hash(state);
David Tolnay9c76bcb2017-12-26 23:14:59 -0500273 }
274}
275
David Tolnay2ae520a2017-12-29 11:19:50 -0500276#[cfg(feature = "extra-traits")]
277impl Eq for ItemVerbatim {}
278
279#[cfg(feature = "extra-traits")]
280impl PartialEq for ItemVerbatim {
281 fn eq(&self, other: &Self) -> bool {
282 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
283 }
284}
285
286#[cfg(feature = "extra-traits")]
287impl Hash for ItemVerbatim {
288 fn hash<H>(&self, state: &mut H)
289 where
290 H: Hasher,
291 {
292 TokenStreamHelper(&self.tts).hash(state);
293 }
294}
295
David Tolnay0e837402016-12-22 17:25:55 -0500296impl From<DeriveInput> for Item {
297 fn from(input: DeriveInput) -> Item {
David Tolnaye3d41b72017-12-31 15:24:00 -0500298 match input.data {
299 Data::Struct(data) => Item::Struct(ItemStruct {
300 attrs: input.attrs,
301 vis: input.vis,
302 struct_token: data.struct_token,
303 ident: input.ident,
304 generics: input.generics,
305 fields: data.fields,
306 semi_token: data.semi_token,
307 }),
308 Data::Enum(data) => Item::Enum(ItemEnum {
David Tolnay51382052017-12-27 13:46:21 -0500309 attrs: input.attrs,
310 vis: input.vis,
311 enum_token: data.enum_token,
312 ident: input.ident,
313 generics: input.generics,
314 brace_token: data.brace_token,
315 variants: data.variants,
316 }),
David Tolnaye3d41b72017-12-31 15:24:00 -0500317 Data::Union(data) => Item::Union(ItemUnion {
David Tolnay51382052017-12-27 13:46:21 -0500318 attrs: input.attrs,
319 vis: input.vis,
David Tolnaye3d41b72017-12-31 15:24:00 -0500320 union_token: data.union_token,
David Tolnay51382052017-12-27 13:46:21 -0500321 ident: input.ident,
322 generics: input.generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500323 fields: data.fields,
David Tolnay51382052017-12-27 13:46:21 -0500324 }),
David Tolnay453cfd12016-10-23 11:00:14 -0700325 }
326 }
327}
328
Alex Crichton62a0a592017-05-22 13:58:53 -0700329ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800330 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
David Tolnay614a0142018-01-07 10:25:43 -0800331 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800332 /// *This type is available if Syn is built with the `"full"` feature.*
333 ///
David Tolnay614a0142018-01-07 10:25:43 -0800334 /// # Syntax tree enum
335 ///
336 /// This type is a [syntax tree enum].
337 ///
338 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay5f332a92017-12-26 00:42:45 -0500339 pub enum UseTree {
David Tolnayd97a7d22018-03-31 19:17:01 +0200340 /// A path prefix of imports in a `use` item: `std::...`.
David Tolnay461d98e2018-01-07 11:07:19 -0800341 ///
342 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500343 pub Path(UsePath {
344 pub ident: Ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200345 pub colon2_token: Token![::],
346 pub tree: Box<UseTree>,
347 }),
348
349 /// An identifier imported by a `use` item: `HashMap`.
350 ///
351 /// *This type is available if Syn is built with the `"full"` feature.*
352 pub Name(UseName {
353 pub ident: Ident,
354 }),
355
356 /// An renamed identifier imported by a `use` item: `HashMap as Map`.
357 ///
358 /// *This type is available if Syn is built with the `"full"` feature.*
359 pub Rename(UseRename {
360 pub ident: Ident,
361 pub as_token: Token![as],
362 pub rename: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700363 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800364
David Tolnay05658502018-01-07 09:56:37 -0800365 /// A glob import in a `use` item: `*`.
David Tolnay461d98e2018-01-07 11:07:19 -0800366 ///
367 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500368 pub Glob(UseGlob {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800369 pub star_token: Token![*],
Alex Crichton62a0a592017-05-22 13:58:53 -0700370 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800371
David Tolnayd97a7d22018-03-31 19:17:01 +0200372 /// A braced group of imports in a `use` item: `{A, B, C}`.
David Tolnay461d98e2018-01-07 11:07:19 -0800373 ///
374 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayd97a7d22018-03-31 19:17:01 +0200375 pub Group(UseGroup {
David Tolnay32954ef2017-12-26 22:43:16 -0500376 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500377 pub items: Punctuated<UseTree, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700378 }),
379 }
380}
381
Alex Crichton62a0a592017-05-22 13:58:53 -0700382ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800383 /// An item within an `extern` block.
David Tolnay614a0142018-01-07 10:25:43 -0800384 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800385 /// *This type is available if Syn is built with the `"full"` feature.*
386 ///
David Tolnay614a0142018-01-07 10:25:43 -0800387 /// # Syntax tree enum
388 ///
389 /// This type is a [syntax tree enum].
390 ///
391 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay8894f602017-11-11 12:11:04 -0800392 pub enum ForeignItem {
David Tolnayebb72722018-01-07 01:14:13 -0800393 /// A foreign function in an `extern` block.
David Tolnay461d98e2018-01-07 11:07:19 -0800394 ///
395 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700396 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800397 pub attrs: Vec<Attribute>,
398 pub vis: Visibility,
399 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700400 pub decl: Box<FnDecl>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800401 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700402 }),
David Tolnayebb72722018-01-07 01:14:13 -0800403
404 /// A foreign static item in an `extern` block: `static ext: u8`.
David Tolnay461d98e2018-01-07 11:07:19 -0800405 ///
406 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700407 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800408 pub attrs: Vec<Attribute>,
409 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800410 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -0500411 pub mutability: Option<Token![mut]>,
David Tolnay8894f602017-11-11 12:11:04 -0800412 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800413 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800414 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800415 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700416 }),
David Tolnayebb72722018-01-07 01:14:13 -0800417
418 /// A foreign type in an `extern` block: `type void`.
David Tolnay461d98e2018-01-07 11:07:19 -0800419 ///
420 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay199bcbb2017-11-12 10:33:52 -0800421 pub Type(ForeignItemType {
422 pub attrs: Vec<Attribute>,
423 pub vis: Visibility,
424 pub type_token: Token![type],
425 pub ident: Ident,
426 pub semi_token: Token![;],
427 }),
David Tolnayebb72722018-01-07 01:14:13 -0800428
429 /// Tokens in an `extern` block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800430 ///
431 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500432 pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
433 pub tts: TokenStream,
434 }),
435 }
436}
437
438#[cfg(feature = "extra-traits")]
439impl Eq for ForeignItemVerbatim {}
440
441#[cfg(feature = "extra-traits")]
442impl PartialEq for ForeignItemVerbatim {
443 fn eq(&self, other: &Self) -> bool {
444 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
445 }
446}
447
448#[cfg(feature = "extra-traits")]
449impl Hash for ForeignItemVerbatim {
450 fn hash<H>(&self, state: &mut H)
451 where
452 H: Hasher,
453 {
454 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700455 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700456}
457
David Tolnayda705bd2017-11-10 21:58:05 -0800458ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800459 /// An item declaration within the definition of a trait.
David Tolnay614a0142018-01-07 10:25:43 -0800460 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800461 /// *This type is available if Syn is built with the `"full"` feature.*
462 ///
David Tolnay614a0142018-01-07 10:25:43 -0800463 /// # Syntax tree enum
464 ///
465 /// This type is a [syntax tree enum].
466 ///
467 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayda705bd2017-11-10 21:58:05 -0800468 pub enum TraitItem {
David Tolnayebb72722018-01-07 01:14:13 -0800469 /// An associated constant within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800470 ///
471 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700472 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800473 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800474 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700475 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800476 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800477 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800478 pub default: Option<(Token![=], Expr)>,
479 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700480 }),
David Tolnayebb72722018-01-07 01:14:13 -0800481
482 /// A trait method within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800483 ///
484 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700485 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800486 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700487 pub sig: MethodSig,
488 pub default: Option<Block>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800489 pub semi_token: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700490 }),
David Tolnayebb72722018-01-07 01:14:13 -0800491
492 /// An associated type within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800493 ///
494 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700495 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800496 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800497 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700498 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500499 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800500 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500501 pub bounds: Punctuated<TypeParamBound, Token![+]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800502 pub default: Option<(Token![=], Type)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800503 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700504 }),
David Tolnayebb72722018-01-07 01:14:13 -0800505
506 /// A macro invocation within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800507 ///
508 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800509 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800510 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800511 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500512 pub semi_token: Option<Token![;]>,
David Tolnayda705bd2017-11-10 21:58:05 -0800513 }),
David Tolnayebb72722018-01-07 01:14:13 -0800514
515 /// Tokens within the definition of a trait not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800516 ///
517 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500518 pub Verbatim(TraitItemVerbatim #manual_extra_traits {
519 pub tts: TokenStream,
520 }),
521 }
522}
523
524#[cfg(feature = "extra-traits")]
525impl Eq for TraitItemVerbatim {}
526
527#[cfg(feature = "extra-traits")]
528impl PartialEq for TraitItemVerbatim {
529 fn eq(&self, other: &Self) -> bool {
530 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
531 }
532}
533
534#[cfg(feature = "extra-traits")]
535impl Hash for TraitItemVerbatim {
536 fn hash<H>(&self, state: &mut H)
537 where
538 H: Hasher,
539 {
540 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700541 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700542}
543
Alex Crichton62a0a592017-05-22 13:58:53 -0700544ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800545 /// An item within an impl block.
David Tolnay614a0142018-01-07 10:25:43 -0800546 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800547 /// *This type is available if Syn is built with the `"full"` feature.*
548 ///
David Tolnay614a0142018-01-07 10:25:43 -0800549 /// # Syntax tree enum
550 ///
551 /// This type is a [syntax tree enum].
552 ///
553 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay857628c2017-11-11 12:25:31 -0800554 pub enum ImplItem {
David Tolnayebb72722018-01-07 01:14:13 -0800555 /// An associated constant 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 Const(ImplItemConst {
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]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800562 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700563 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800564 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800565 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800566 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -0700567 pub expr: Expr,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800568 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700569 }),
David Tolnayebb72722018-01-07 01:14:13 -0800570
571 /// A method within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800572 ///
573 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700574 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800575 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700576 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500577 pub defaultness: Option<Token![default]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700578 pub sig: MethodSig,
579 pub block: Block,
580 }),
David Tolnayebb72722018-01-07 01:14:13 -0800581
582 /// An associated type within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800583 ///
584 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700585 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800586 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700587 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500588 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800589 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700590 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500591 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800592 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800593 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800594 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700595 }),
David Tolnayebb72722018-01-07 01:14:13 -0800596
597 /// A macro invocation within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800598 ///
599 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay857628c2017-11-11 12:25:31 -0800600 pub Macro(ImplItemMacro {
601 pub attrs: Vec<Attribute>,
602 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500603 pub semi_token: Option<Token![;]>,
David Tolnay857628c2017-11-11 12:25:31 -0800604 }),
David Tolnayebb72722018-01-07 01:14:13 -0800605
606 /// Tokens within an impl block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800607 ///
608 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500609 pub Verbatim(ImplItemVerbatim #manual_extra_traits {
610 pub tts: TokenStream,
611 }),
612 }
613}
614
615#[cfg(feature = "extra-traits")]
616impl Eq for ImplItemVerbatim {}
617
618#[cfg(feature = "extra-traits")]
619impl PartialEq for ImplItemVerbatim {
620 fn eq(&self, other: &Self) -> bool {
621 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
622 }
623}
624
625#[cfg(feature = "extra-traits")]
626impl Hash for ImplItemVerbatim {
627 fn hash<H>(&self, state: &mut H)
628 where
629 H: Hasher,
630 {
631 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700632 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700633}
634
635ast_struct! {
David Tolnay05658502018-01-07 09:56:37 -0800636 /// A method's signature in a trait or implementation: `unsafe fn
637 /// initialize(&self)`.
David Tolnay461d98e2018-01-07 11:07:19 -0800638 ///
639 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700640 pub struct MethodSig {
David Tolnay360a6342017-12-29 02:22:11 -0500641 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -0500642 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700643 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700644 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700645 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700646 }
647}
648
649ast_struct! {
David Tolnayebb72722018-01-07 01:14:13 -0800650 /// Header of a function declaration, without including the body.
David Tolnay461d98e2018-01-07 11:07:19 -0800651 ///
652 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700653 pub struct FnDecl {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800654 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500655 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500656 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -0500657 pub inputs: Punctuated<FnArg, Token![,]>,
David Tolnayd2836e22017-12-27 23:13:00 -0500658 pub variadic: Option<Token![...]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500659 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700660 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700661}
662
Alex Crichton62a0a592017-05-22 13:58:53 -0700663ast_enum_of_structs! {
David Tolnayc0435192018-01-07 11:46:08 -0800664 /// An argument in a function signature: the `n: usize` in `fn f(n: usize)`.
David Tolnay614a0142018-01-07 10:25:43 -0800665 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800666 /// *This type is available if Syn is built with the `"full"` feature.*
667 ///
David Tolnay614a0142018-01-07 10:25:43 -0800668 /// # Syntax tree enum
669 ///
670 /// This type is a [syntax tree enum].
671 ///
672 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700673 pub enum FnArg {
David Tolnay3f559052018-01-06 23:59:48 -0800674 /// Self captured by reference in a function signature: `&self` or `&mut
675 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800676 ///
677 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700678 pub SelfRef(ArgSelfRef {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800679 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -0700680 pub lifetime: Option<Lifetime>,
David Tolnay24237fb2017-12-29 02:15:26 -0500681 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500682 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700683 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800684
David Tolnay3f559052018-01-06 23:59:48 -0800685 /// Self captured by value in a function signature: `self` or `mut
686 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800687 ///
688 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700689 pub SelfValue(ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500690 pub mutability: Option<Token![mut]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800691 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700692 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800693
David Tolnay3f559052018-01-06 23:59:48 -0800694 /// An explicitly typed pattern captured by a function signature.
David Tolnay461d98e2018-01-07 11:07:19 -0800695 ///
696 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700697 pub Captured(ArgCaptured {
698 pub pat: Pat,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800699 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800700 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700701 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800702
David Tolnay3f559052018-01-06 23:59:48 -0800703 /// A pattern whose type is inferred captured by a function signature.
David Tolnay80ed55f2017-12-27 22:54:40 -0500704 pub Inferred(Pat),
David Tolnay3f559052018-01-06 23:59:48 -0800705 /// A type not bound to any pattern in a function signature.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800706 pub Ignored(Type),
Alex Crichton62a0a592017-05-22 13:58:53 -0700707 }
David Tolnay62f374c2016-10-02 13:37:00 -0700708}
709
David Tolnayedf2b992016-09-23 20:43:45 -0700710#[cfg(feature = "parsing")]
711pub mod parsing {
712 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700713
David Tolnayb21b0342018-01-18 23:36:26 -0800714 use synom::Synom;
David Tolnay84aa0752016-10-02 23:01:13 -0700715
David Tolnay4c614be2017-11-10 00:02:38 -0800716 impl_synom!(Item "item" alt!(
717 syn!(ItemExternCrate) => { Item::ExternCrate }
718 |
719 syn!(ItemUse) => { Item::Use }
720 |
721 syn!(ItemStatic) => { Item::Static }
722 |
723 syn!(ItemConst) => { Item::Const }
724 |
725 syn!(ItemFn) => { Item::Fn }
726 |
727 syn!(ItemMod) => { Item::Mod }
728 |
729 syn!(ItemForeignMod) => { Item::ForeignMod }
730 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800731 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800732 |
733 syn!(ItemStruct) => { Item::Struct }
734 |
735 syn!(ItemEnum) => { Item::Enum }
736 |
737 syn!(ItemUnion) => { Item::Union }
738 |
739 syn!(ItemTrait) => { Item::Trait }
740 |
David Tolnay4c614be2017-11-10 00:02:38 -0800741 syn!(ItemImpl) => { Item::Impl }
742 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800743 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800744 |
745 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800746 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700747
David Tolnaydecf28d2017-11-11 11:56:45 -0800748 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500749 attrs: many0!(Attribute::parse_outer) >>
David Tolnayd69fc2b2018-01-23 09:39:14 -0800750 what: call!(Path::parse_mod_style) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800751 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700752 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500753 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500754 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800755 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700756 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800757 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800758 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500759 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700760 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500761 delimiter: body.0,
762 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800763 },
David Tolnay57292da2017-12-27 21:03:33 -0500764 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800765 })
David Tolnayedf2b992016-09-23 20:43:45 -0700766 ));
767
David Tolnay500d8322017-12-18 00:32:51 -0800768 // TODO: figure out the actual grammar; is body required to be braced?
769 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500770 attrs: many0!(Attribute::parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800771 vis: syn!(Visibility) >>
772 macro_: keyword!(macro) >>
773 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500774 args: call!(tt::parenthesized) >>
775 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800776 (ItemMacro2 {
777 attrs: attrs,
778 vis: vis,
779 macro_token: macro_,
780 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500781 paren_token: args.0,
782 args: args.1,
783 brace_token: body.0,
784 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800785 })
786 ));
787
David Tolnay4c614be2017-11-10 00:02:38 -0800788 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500789 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700790 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800791 extern_: keyword!(extern) >>
792 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700793 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800794 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
795 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800796 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700797 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800798 vis: vis,
799 extern_token: extern_,
800 crate_token: crate_,
801 ident: ident,
802 rename: rename,
803 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800804 })
David Tolnayedf2b992016-09-23 20:43:45 -0700805 ));
806
David Tolnay4c614be2017-11-10 00:02:38 -0800807 impl_synom!(ItemUse "use item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500808 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700809 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800810 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500811 leading_colon: option!(punct!(::)) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200812 tree: syn!(UseTree) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800813 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800814 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700815 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800816 vis: vis,
817 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500818 leading_colon: leading_colon,
David Tolnay5f332a92017-12-26 00:42:45 -0500819 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800820 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800821 })
David Tolnay4a057422016-10-08 00:02:31 -0700822 ));
823
David Tolnayd97a7d22018-03-31 19:17:01 +0200824 named!(use_element -> Ident, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500825 syn!(Ident)
826 |
827 keyword!(self) => { Into::into }
828 |
829 keyword!(super) => { Into::into }
830 |
831 keyword!(crate) => { Into::into }
832 ));
833
834 impl_synom!(UseTree "use tree" alt!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200835 syn!(UseRename) => { UseTree::Rename }
836 |
David Tolnay5f332a92017-12-26 00:42:45 -0500837 syn!(UsePath) => { UseTree::Path }
838 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200839 syn!(UseName) => { UseTree::Name }
840 |
David Tolnay5f332a92017-12-26 00:42:45 -0500841 syn!(UseGlob) => { UseTree::Glob }
842 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200843 syn!(UseGroup) => { UseTree::Group }
David Tolnay5f332a92017-12-26 00:42:45 -0500844 ));
845
846 impl_synom!(UsePath "use path" do_parse!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200847 ident: call!(use_element) >>
848 colon2_token: punct!(::) >>
849 tree: syn!(UseTree) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500850 (UsePath {
851 ident: ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200852 colon2_token: colon2_token,
853 tree: Box::new(tree),
854 })
855 ));
856
857 impl_synom!(UseName "use name" do_parse!(
858 ident: call!(use_element) >>
859 (UseName {
860 ident: ident,
861 })
862 ));
863
864 impl_synom!(UseRename "use rename" do_parse!(
865 ident: call!(use_element) >>
866 as_token: keyword!(as) >>
867 rename: syn!(Ident) >>
868 (UseRename {
869 ident: ident,
870 as_token: as_token,
David Tolnay5f332a92017-12-26 00:42:45 -0500871 rename: rename,
872 })
873 ));
David Tolnay4a057422016-10-08 00:02:31 -0700874
David Tolnay5f332a92017-12-26 00:42:45 -0500875 impl_synom!(UseGlob "use glob" do_parse!(
876 star: punct!(*) >>
877 (UseGlob {
878 star_token: star,
879 })
880 ));
David Tolnay4a057422016-10-08 00:02:31 -0700881
David Tolnayd97a7d22018-03-31 19:17:01 +0200882 impl_synom!(UseGroup "use group" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500883 list: braces!(Punctuated::parse_terminated) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200884 (UseGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500885 brace_token: list.0,
886 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500887 })
888 ));
David Tolnay4a057422016-10-08 00:02:31 -0700889
David Tolnay4c614be2017-11-10 00:02:38 -0800890 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500891 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700892 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800893 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500894 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700895 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800896 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800897 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800898 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700899 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800900 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800901 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700902 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800903 vis: vis,
904 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500905 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800906 ident: ident,
907 colon_token: colon,
908 ty: Box::new(ty),
909 eq_token: eq,
910 expr: Box::new(value),
911 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800912 })
David Tolnay47a877c2016-10-01 16:50:55 -0700913 ));
914
David Tolnay4c614be2017-11-10 00:02:38 -0800915 impl_synom!(ItemConst "const item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500916 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700917 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800918 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700919 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800920 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800921 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800922 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700923 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800924 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800925 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700926 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800927 vis: vis,
928 const_token: const_,
929 ident: ident,
930 colon_token: colon,
931 ty: Box::new(ty),
932 eq_token: eq,
933 expr: Box::new(value),
934 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800935 })
David Tolnay47a877c2016-10-01 16:50:55 -0700936 ));
937
David Tolnay4c614be2017-11-10 00:02:38 -0800938 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500939 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700940 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -0500941 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500942 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700943 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800944 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -0700945 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700946 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500947 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800948 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -0500949 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700950 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -0500951 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -0700952 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -0400953 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800954 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -0700955 attrs: {
956 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -0500957 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -0700958 attrs
959 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800960 vis: vis,
961 constness: constness,
962 unsafety: unsafety,
963 abi: abi,
964 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800965 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500966 paren_token: inputs.0,
967 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800968 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -0500969 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800970 generics: Generics {
971 where_clause: where_clause,
972 .. generics
973 },
974 }),
975 ident: ident,
976 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -0500977 brace_token: inner_attrs_stmts.0,
978 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800979 }),
David Tolnay4c614be2017-11-10 00:02:38 -0800980 })
David Tolnay42602292016-10-01 22:25:45 -0700981 ));
982
Alex Crichton954046c2017-05-30 21:49:42 -0700983 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400984 named!(parse -> Self, alt!(
985 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800986 and: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400987 lt: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500988 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800989 self_: keyword!(self) >>
990 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400991 (ArgSelfRef {
992 lifetime: lt,
David Tolnay24237fb2017-12-29 02:15:26 -0500993 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400994 and_token: and,
995 self_token: self_,
996 }.into())
997 )
998 |
999 do_parse!(
David Tolnay24237fb2017-12-29 02:15:26 -05001000 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001001 self_: keyword!(self) >>
1002 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001003 (ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -05001004 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -04001005 self_token: self_,
1006 }.into())
1007 )
1008 |
1009 do_parse!(
1010 pat: syn!(Pat) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001011 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001012 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001013 (ArgCaptured {
1014 pat: pat,
1015 ty: ty,
1016 colon_token: colon,
1017 }.into())
1018 )
1019 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001020 syn!(Type) => { FnArg::Ignored }
Michael Layzell92639a52017-06-01 00:07:44 -04001021 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001022
1023 fn description() -> Option<&'static str> {
1024 Some("function argument")
1025 }
Alex Crichton954046c2017-05-30 21:49:42 -07001026 }
David Tolnay62f374c2016-10-02 13:37:00 -07001027
David Tolnay4c614be2017-11-10 00:02:38 -08001028 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001029 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001030 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001031 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -07001032 ident: syn!(Ident) >>
1033 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001034 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -07001035 Vec::new(),
1036 None,
1037 Some(semi),
1038 )}
David Tolnay37d10332016-10-13 20:51:04 -07001039 |
Alex Crichton954046c2017-05-30 21:49:42 -07001040 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -07001041 tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001042 many0!(Attribute::parse_inner),
1043 many0!(Item::parse)
Michael Layzell416724e2017-05-24 21:12:34 -04001044 )
David Tolnay8875fca2017-12-31 13:52:37 -05001045 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -07001046 inner_attrs,
1047 Some((brace, items)),
1048 None,
1049 )}
David Tolnay37d10332016-10-13 20:51:04 -07001050 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001051 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -07001052 attrs: {
1053 let mut attrs = outer_attrs;
1054 attrs.extend(content_semi.0);
1055 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -07001056 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001057 vis: vis,
1058 mod_token: mod_,
1059 ident: ident,
1060 content: content_semi.1,
1061 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -08001062 })
David Tolnay35902302016-10-06 01:11:08 -07001063 ));
1064
David Tolnay4c614be2017-11-10 00:02:38 -08001065 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001066 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001067 abi: syn!(Abi) >>
David Tolnay2c136452017-12-27 14:13:32 -05001068 items: braces!(many0!(ForeignItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001069 (ItemForeignMod {
David Tolnay35902302016-10-06 01:11:08 -07001070 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001071 abi: abi,
David Tolnay8875fca2017-12-31 13:52:37 -05001072 brace_token: items.0,
1073 items: items.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001074 })
David Tolnay35902302016-10-06 01:11:08 -07001075 ));
1076
David Tolnay8894f602017-11-11 12:11:04 -08001077 impl_synom!(ForeignItem "foreign item" alt!(
1078 syn!(ForeignItemFn) => { ForeignItem::Fn }
1079 |
1080 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -08001081 |
1082 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay8894f602017-11-11 12:11:04 -08001083 ));
David Tolnay35902302016-10-06 01:11:08 -07001084
David Tolnay8894f602017-11-11 12:11:04 -08001085 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001086 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001087 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001088 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001089 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001090 generics: syn!(Generics) >>
1091 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -05001092 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -05001093 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001094 (args, variadic)
1095 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001096 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001097 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001098 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001099 ({
David Tolnay8875fca2017-12-31 13:52:37 -05001100 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -08001101 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -07001102 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -07001103 attrs: attrs,
1104 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001105 decl: Box::new(FnDecl {
1106 fn_token: fn_,
1107 paren_token: parens,
1108 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001109 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001110 output: ret,
1111 generics: Generics {
1112 where_clause: where_clause,
1113 .. generics
1114 },
1115 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001116 vis: vis,
1117 }
David Tolnay35902302016-10-06 01:11:08 -07001118 })
1119 ));
1120
David Tolnay8894f602017-11-11 12:11:04 -08001121 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001122 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001123 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001124 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001125 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001126 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001127 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001128 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001129 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001130 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001131 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001132 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001133 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001134 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001135 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001136 static_token: static_,
1137 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001138 vis: vis,
1139 })
1140 ));
1141
David Tolnay199bcbb2017-11-12 10:33:52 -08001142 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001143 attrs: many0!(Attribute::parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001144 vis: syn!(Visibility) >>
1145 type_: keyword!(type) >>
1146 ident: syn!(Ident) >>
1147 semi: punct!(;) >>
1148 (ForeignItemType {
1149 attrs: attrs,
1150 vis: vis,
1151 type_token: type_,
1152 ident: ident,
1153 semi_token: semi,
1154 })
1155 ));
1156
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001157 impl_synom!(ItemType "type item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001158 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001159 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001160 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001161 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001162 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001163 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001164 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001165 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001166 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001167 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001168 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001169 vis: vis,
1170 type_token: type_,
1171 ident: ident,
1172 generics: Generics {
1173 where_clause: where_clause,
1174 ..generics
1175 },
1176 eq_token: eq,
1177 ty: Box::new(ty),
1178 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001179 })
David Tolnay3cf52982016-10-01 17:11:37 -07001180 ));
1181
David Tolnay4c614be2017-11-10 00:02:38 -08001182 impl_synom!(ItemStruct "struct item" switch!(
1183 map!(syn!(DeriveInput), Into::into),
1184 Item::Struct(item) => value!(item)
1185 |
1186 _ => reject!()
1187 ));
David Tolnay42602292016-10-01 22:25:45 -07001188
David Tolnay4c614be2017-11-10 00:02:38 -08001189 impl_synom!(ItemEnum "enum item" switch!(
1190 map!(syn!(DeriveInput), Into::into),
1191 Item::Enum(item) => value!(item)
1192 |
1193 _ => reject!()
1194 ));
1195
1196 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001197 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001198 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001199 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001200 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001201 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001202 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001203 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001204 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001205 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001206 vis: vis,
1207 union_token: union_,
1208 ident: ident,
1209 generics: Generics {
1210 where_clause: where_clause,
1211 .. generics
1212 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001213 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001214 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001215 ));
1216
David Tolnay4c614be2017-11-10 00:02:38 -08001217 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001218 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001219 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001220 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001221 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001222 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001223 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001224 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001225 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001226 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001227 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001228 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001229 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001230 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001231 vis: vis,
1232 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001233 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001234 trait_token: trait_,
1235 ident: ident,
1236 generics: Generics {
1237 where_clause: where_clause,
1238 .. generics
1239 },
1240 colon_token: colon,
1241 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001242 brace_token: body.0,
1243 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001244 })
David Tolnay0aecb732016-10-03 23:03:50 -07001245 ));
1246
David Tolnayda705bd2017-11-10 21:58:05 -08001247 impl_synom!(TraitItem "trait item" alt!(
1248 syn!(TraitItemConst) => { TraitItem::Const }
1249 |
1250 syn!(TraitItemMethod) => { TraitItem::Method }
1251 |
1252 syn!(TraitItemType) => { TraitItem::Type }
1253 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001254 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001255 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001256
David Tolnayda705bd2017-11-10 21:58:05 -08001257 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001258 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001259 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001260 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001261 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001262 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001263 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1264 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001265 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001266 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001267 const_token: const_,
1268 ident: ident,
1269 colon_token: colon,
1270 ty: ty,
1271 default: default,
1272 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001273 })
1274 ));
1275
David Tolnayda705bd2017-11-10 21:58:05 -08001276 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001277 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001278 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001279 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001280 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001281 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001282 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001283 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001284 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001285 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001286 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001287 body: option!(braces!(
David Tolnay2c136452017-12-27 14:13:32 -05001288 tuple!(many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001289 call!(Block::parse_within))
David Tolnay5859df12016-10-29 22:49:54 -07001290 )) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001291 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001292 ({
1293 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001294 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001295 None => (Vec::new(), None),
1296 };
David Tolnayda705bd2017-11-10 21:58:05 -08001297 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001298 attrs: {
1299 let mut attrs = outer_attrs;
1300 attrs.extend(inner_attrs);
1301 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001302 },
David Tolnayda705bd2017-11-10 21:58:05 -08001303 sig: MethodSig {
1304 constness: constness,
1305 unsafety: unsafety,
1306 abi: abi,
1307 ident: ident,
1308 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001309 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001310 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001311 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001312 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001313 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001314 generics: Generics {
1315 where_clause: where_clause,
1316 .. generics
David Tolnay5859df12016-10-29 22:49:54 -07001317 },
1318 },
David Tolnayda705bd2017-11-10 21:58:05 -08001319 },
1320 default: stmts.map(|stmts| {
1321 Block {
1322 stmts: stmts.0,
1323 brace_token: stmts.1,
1324 }
1325 }),
1326 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001327 }
David Tolnay0aecb732016-10-03 23:03:50 -07001328 })
1329 ));
1330
David Tolnayda705bd2017-11-10 21:58:05 -08001331 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001332 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001333 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001334 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001335 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001336 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001337 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001338 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001339 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001340 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001341 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001342 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001343 type_token: type_,
1344 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001345 generics: Generics {
1346 where_clause: where_clause,
1347 .. generics
1348 },
David Tolnayda705bd2017-11-10 21:58:05 -08001349 colon_token: colon,
1350 bounds: bounds.unwrap_or_default(),
1351 default: default,
1352 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001353 })
1354 ));
1355
David Tolnaydecf28d2017-11-11 11:56:45 -08001356 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001357 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001358 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001359 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001360 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001361 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001362 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001363 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001364 })
1365 ));
1366
David Tolnay4c614be2017-11-10 00:02:38 -08001367 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnaycf3697a2018-03-31 20:51:15 +02001368 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001369 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001370 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001371 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001372 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001373 polarity_path: alt!(
1374 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001375 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001376 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001377 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001378 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001379 )
1380 |
David Tolnay570695e2017-06-03 16:15:13 -07001381 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001382 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001383 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001384 where_clause: option!(syn!(WhereClause)) >>
David Tolnaycf3697a2018-03-31 20:51:15 +02001385 inner: braces!(tuple!(
1386 many0!(Attribute::parse_inner),
1387 many0!(ImplItem::parse)
1388 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001389 (ItemImpl {
David Tolnaycf3697a2018-03-31 20:51:15 +02001390 attrs: {
1391 let mut attrs = outer_attrs;
1392 attrs.extend((inner.1).0);
1393 attrs
1394 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001395 defaultness: defaultness,
1396 unsafety: unsafety,
1397 impl_token: impl_,
1398 generics: Generics {
1399 where_clause: where_clause,
1400 .. generics
1401 },
1402 trait_: polarity_path,
1403 self_ty: Box::new(self_ty),
David Tolnaycf3697a2018-03-31 20:51:15 +02001404 brace_token: inner.0,
1405 items: (inner.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001406 })
David Tolnay4c9be372016-10-06 00:47:37 -07001407 ));
1408
David Tolnay857628c2017-11-11 12:25:31 -08001409 impl_synom!(ImplItem "item in impl block" alt!(
1410 syn!(ImplItemConst) => { ImplItem::Const }
1411 |
1412 syn!(ImplItemMethod) => { ImplItem::Method }
1413 |
1414 syn!(ImplItemType) => { ImplItem::Type }
1415 |
1416 syn!(ImplItemMacro) => { ImplItem::Macro }
1417 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001418
David Tolnay857628c2017-11-11 12:25:31 -08001419 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001420 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001421 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001422 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001423 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001424 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001425 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001426 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001427 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001428 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001429 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001430 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001431 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001432 vis: vis,
1433 defaultness: defaultness,
1434 const_token: const_,
1435 ident: ident,
1436 colon_token: colon,
1437 ty: ty,
1438 eq_token: eq,
1439 expr: value,
1440 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001441 })
1442 ));
1443
David Tolnay857628c2017-11-11 12:25:31 -08001444 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001445 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001446 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001447 defaultness: option!(keyword!(default)) >>
1448 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001449 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001450 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001451 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001452 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001453 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001454 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001455 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001456 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001457 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001458 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001459 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -04001460 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001461 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001462 attrs: {
1463 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001464 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001465 attrs
1466 },
David Tolnay857628c2017-11-11 12:25:31 -08001467 vis: vis,
1468 defaultness: defaultness,
1469 sig: MethodSig {
1470 constness: constness,
1471 unsafety: unsafety,
1472 abi: abi,
1473 ident: ident,
1474 decl: FnDecl {
1475 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001476 paren_token: inputs.0,
1477 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001478 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001479 generics: Generics {
1480 where_clause: where_clause,
1481 .. generics
David Tolnay4c9be372016-10-06 00:47:37 -07001482 },
David Tolnayd2836e22017-12-27 23:13:00 -05001483 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001484 },
David Tolnay857628c2017-11-11 12:25:31 -08001485 },
1486 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001487 brace_token: inner_attrs_stmts.0,
1488 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001489 },
David Tolnay4c9be372016-10-06 00:47:37 -07001490 })
1491 ));
1492
David Tolnay857628c2017-11-11 12:25:31 -08001493 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001494 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001495 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001496 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001497 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001498 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001499 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001500 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001501 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001502 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001503 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001504 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001505 vis: vis,
1506 defaultness: defaultness,
1507 type_token: type_,
1508 ident: ident,
Nika Layzell591528a2017-12-05 12:47:37 -05001509 generics: generics,
David Tolnay857628c2017-11-11 12:25:31 -08001510 eq_token: eq,
1511 ty: ty,
1512 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001513 })
1514 ));
1515
David Tolnay857628c2017-11-11 12:25:31 -08001516 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001517 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001518 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001519 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001520 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001521 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001522 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001523 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001524 })
1525 ));
1526
David Tolnayab919512017-12-30 23:31:51 -05001527 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1528 match *delimiter {
1529 MacroDelimiter::Brace(_) => true,
1530 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001531 }
1532 }
David Tolnayedf2b992016-09-23 20:43:45 -07001533}
David Tolnay4a51dc72016-10-01 00:40:31 -07001534
1535#[cfg(feature = "printing")]
1536mod printing {
1537 use super::*;
1538 use attr::FilterAttrs;
David Tolnay51382052017-12-27 13:46:21 -05001539 use quote::{ToTokens, Tokens};
David Tolnay4a51dc72016-10-01 00:40:31 -07001540
David Tolnay1bfa7332017-11-11 12:41:20 -08001541 impl ToTokens for ItemExternCrate {
David Tolnay4a51dc72016-10-01 00:40:31 -07001542 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001543 tokens.append_all(self.attrs.outer());
1544 self.vis.to_tokens(tokens);
1545 self.extern_token.to_tokens(tokens);
1546 self.crate_token.to_tokens(tokens);
1547 self.ident.to_tokens(tokens);
1548 if let Some((ref as_token, ref rename)) = self.rename {
1549 as_token.to_tokens(tokens);
1550 rename.to_tokens(tokens);
1551 }
1552 self.semi_token.to_tokens(tokens);
1553 }
1554 }
1555
1556 impl ToTokens for ItemUse {
1557 fn to_tokens(&self, tokens: &mut Tokens) {
1558 tokens.append_all(self.attrs.outer());
1559 self.vis.to_tokens(tokens);
1560 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001561 self.leading_colon.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001562 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001563 self.semi_token.to_tokens(tokens);
1564 }
1565 }
1566
1567 impl ToTokens for ItemStatic {
1568 fn to_tokens(&self, tokens: &mut Tokens) {
1569 tokens.append_all(self.attrs.outer());
1570 self.vis.to_tokens(tokens);
1571 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001572 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001573 self.ident.to_tokens(tokens);
1574 self.colon_token.to_tokens(tokens);
1575 self.ty.to_tokens(tokens);
1576 self.eq_token.to_tokens(tokens);
1577 self.expr.to_tokens(tokens);
1578 self.semi_token.to_tokens(tokens);
1579 }
1580 }
1581
1582 impl ToTokens for ItemConst {
1583 fn to_tokens(&self, tokens: &mut Tokens) {
1584 tokens.append_all(self.attrs.outer());
1585 self.vis.to_tokens(tokens);
1586 self.const_token.to_tokens(tokens);
1587 self.ident.to_tokens(tokens);
1588 self.colon_token.to_tokens(tokens);
1589 self.ty.to_tokens(tokens);
1590 self.eq_token.to_tokens(tokens);
1591 self.expr.to_tokens(tokens);
1592 self.semi_token.to_tokens(tokens);
1593 }
1594 }
1595
1596 impl ToTokens for ItemFn {
1597 fn to_tokens(&self, tokens: &mut Tokens) {
1598 tokens.append_all(self.attrs.outer());
1599 self.vis.to_tokens(tokens);
1600 self.constness.to_tokens(tokens);
1601 self.unsafety.to_tokens(tokens);
1602 self.abi.to_tokens(tokens);
1603 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1604 self.block.brace_token.surround(tokens, |tokens| {
1605 tokens.append_all(self.attrs.inner());
1606 tokens.append_all(&self.block.stmts);
1607 });
1608 }
1609 }
1610
1611 impl ToTokens for ItemMod {
1612 fn to_tokens(&self, tokens: &mut Tokens) {
1613 tokens.append_all(self.attrs.outer());
1614 self.vis.to_tokens(tokens);
1615 self.mod_token.to_tokens(tokens);
1616 self.ident.to_tokens(tokens);
1617 if let Some((ref brace, ref items)) = self.content {
1618 brace.surround(tokens, |tokens| {
1619 tokens.append_all(self.attrs.inner());
1620 tokens.append_all(items);
1621 });
1622 } else {
1623 TokensOrDefault(&self.semi).to_tokens(tokens);
1624 }
1625 }
1626 }
1627
1628 impl ToTokens for ItemForeignMod {
1629 fn to_tokens(&self, tokens: &mut Tokens) {
1630 tokens.append_all(self.attrs.outer());
1631 self.abi.to_tokens(tokens);
1632 self.brace_token.surround(tokens, |tokens| {
1633 tokens.append_all(&self.items);
1634 });
1635 }
1636 }
1637
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001638 impl ToTokens for ItemType {
David Tolnay1bfa7332017-11-11 12:41:20 -08001639 fn to_tokens(&self, tokens: &mut Tokens) {
1640 tokens.append_all(self.attrs.outer());
1641 self.vis.to_tokens(tokens);
1642 self.type_token.to_tokens(tokens);
1643 self.ident.to_tokens(tokens);
1644 self.generics.to_tokens(tokens);
1645 self.generics.where_clause.to_tokens(tokens);
1646 self.eq_token.to_tokens(tokens);
1647 self.ty.to_tokens(tokens);
1648 self.semi_token.to_tokens(tokens);
1649 }
1650 }
1651
1652 impl ToTokens for ItemEnum {
1653 fn to_tokens(&self, tokens: &mut Tokens) {
1654 tokens.append_all(self.attrs.outer());
1655 self.vis.to_tokens(tokens);
1656 self.enum_token.to_tokens(tokens);
1657 self.ident.to_tokens(tokens);
1658 self.generics.to_tokens(tokens);
1659 self.generics.where_clause.to_tokens(tokens);
1660 self.brace_token.surround(tokens, |tokens| {
1661 self.variants.to_tokens(tokens);
1662 });
1663 }
1664 }
1665
1666 impl ToTokens for ItemStruct {
1667 fn to_tokens(&self, tokens: &mut Tokens) {
1668 tokens.append_all(self.attrs.outer());
1669 self.vis.to_tokens(tokens);
1670 self.struct_token.to_tokens(tokens);
1671 self.ident.to_tokens(tokens);
1672 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001673 match self.fields {
1674 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001675 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001676 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001677 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001678 Fields::Unnamed(ref fields) => {
1679 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001680 self.generics.where_clause.to_tokens(tokens);
1681 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001682 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001683 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001684 self.generics.where_clause.to_tokens(tokens);
1685 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001686 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001687 }
1688 }
1689 }
1690
1691 impl ToTokens for ItemUnion {
1692 fn to_tokens(&self, tokens: &mut Tokens) {
1693 tokens.append_all(self.attrs.outer());
1694 self.vis.to_tokens(tokens);
1695 self.union_token.to_tokens(tokens);
1696 self.ident.to_tokens(tokens);
1697 self.generics.to_tokens(tokens);
1698 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001699 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001700 }
1701 }
1702
1703 impl ToTokens for ItemTrait {
1704 fn to_tokens(&self, tokens: &mut Tokens) {
1705 tokens.append_all(self.attrs.outer());
1706 self.vis.to_tokens(tokens);
1707 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001708 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001709 self.trait_token.to_tokens(tokens);
1710 self.ident.to_tokens(tokens);
1711 self.generics.to_tokens(tokens);
1712 if !self.supertraits.is_empty() {
1713 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1714 self.supertraits.to_tokens(tokens);
1715 }
1716 self.generics.where_clause.to_tokens(tokens);
1717 self.brace_token.surround(tokens, |tokens| {
1718 tokens.append_all(&self.items);
1719 });
1720 }
1721 }
1722
David Tolnay1bfa7332017-11-11 12:41:20 -08001723 impl ToTokens for ItemImpl {
1724 fn to_tokens(&self, tokens: &mut Tokens) {
1725 tokens.append_all(self.attrs.outer());
1726 self.defaultness.to_tokens(tokens);
1727 self.unsafety.to_tokens(tokens);
1728 self.impl_token.to_tokens(tokens);
1729 self.generics.to_tokens(tokens);
1730 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1731 polarity.to_tokens(tokens);
1732 path.to_tokens(tokens);
1733 for_token.to_tokens(tokens);
1734 }
1735 self.self_ty.to_tokens(tokens);
1736 self.generics.where_clause.to_tokens(tokens);
1737 self.brace_token.surround(tokens, |tokens| {
David Tolnaycf3697a2018-03-31 20:51:15 +02001738 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001739 tokens.append_all(&self.items);
1740 });
1741 }
1742 }
1743
1744 impl ToTokens for ItemMacro {
1745 fn to_tokens(&self, tokens: &mut Tokens) {
1746 tokens.append_all(self.attrs.outer());
1747 self.mac.path.to_tokens(tokens);
1748 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001749 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001750 match self.mac.delimiter {
1751 MacroDelimiter::Paren(ref paren) => {
1752 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1753 }
1754 MacroDelimiter::Brace(ref brace) => {
1755 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1756 }
1757 MacroDelimiter::Bracket(ref bracket) => {
1758 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1759 }
1760 }
David Tolnay57292da2017-12-27 21:03:33 -05001761 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001762 }
1763 }
David Tolnay42602292016-10-01 22:25:45 -07001764
David Tolnay500d8322017-12-18 00:32:51 -08001765 impl ToTokens for ItemMacro2 {
1766 fn to_tokens(&self, tokens: &mut Tokens) {
1767 tokens.append_all(self.attrs.outer());
1768 self.vis.to_tokens(tokens);
1769 self.macro_token.to_tokens(tokens);
1770 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001771 self.paren_token.surround(tokens, |tokens| {
1772 self.args.to_tokens(tokens);
1773 });
1774 self.brace_token.surround(tokens, |tokens| {
1775 self.body.to_tokens(tokens);
1776 });
David Tolnay500d8322017-12-18 00:32:51 -08001777 }
1778 }
1779
David Tolnay2ae520a2017-12-29 11:19:50 -05001780 impl ToTokens for ItemVerbatim {
1781 fn to_tokens(&self, tokens: &mut Tokens) {
1782 self.tts.to_tokens(tokens);
1783 }
1784 }
1785
David Tolnay5f332a92017-12-26 00:42:45 -05001786 impl ToTokens for UsePath {
David Tolnay4a057422016-10-08 00:02:31 -07001787 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay5f332a92017-12-26 00:42:45 -05001788 self.ident.to_tokens(tokens);
David Tolnayd97a7d22018-03-31 19:17:01 +02001789 self.colon2_token.to_tokens(tokens);
1790 self.tree.to_tokens(tokens);
1791 }
1792 }
1793
1794 impl ToTokens for UseName {
1795 fn to_tokens(&self, tokens: &mut Tokens) {
1796 self.ident.to_tokens(tokens);
1797 }
1798 }
1799
1800 impl ToTokens for UseRename {
1801 fn to_tokens(&self, tokens: &mut Tokens) {
1802 self.ident.to_tokens(tokens);
1803 self.as_token.to_tokens(tokens);
1804 self.rename.to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001805 }
1806 }
1807
David Tolnay5f332a92017-12-26 00:42:45 -05001808 impl ToTokens for UseGlob {
Alex Crichton62a0a592017-05-22 13:58:53 -07001809 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001810 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001811 }
1812 }
1813
David Tolnayd97a7d22018-03-31 19:17:01 +02001814 impl ToTokens for UseGroup {
Alex Crichton62a0a592017-05-22 13:58:53 -07001815 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001816 self.brace_token.surround(tokens, |tokens| {
1817 self.items.to_tokens(tokens);
1818 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001819 }
1820 }
1821
David Tolnay1bfa7332017-11-11 12:41:20 -08001822 impl ToTokens for TraitItemConst {
David Tolnayca085422016-10-04 00:12:38 -07001823 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001824 tokens.append_all(self.attrs.outer());
1825 self.const_token.to_tokens(tokens);
1826 self.ident.to_tokens(tokens);
1827 self.colon_token.to_tokens(tokens);
1828 self.ty.to_tokens(tokens);
1829 if let Some((ref eq_token, ref default)) = self.default {
1830 eq_token.to_tokens(tokens);
1831 default.to_tokens(tokens);
1832 }
1833 self.semi_token.to_tokens(tokens);
1834 }
1835 }
1836
1837 impl ToTokens for TraitItemMethod {
1838 fn to_tokens(&self, tokens: &mut Tokens) {
1839 tokens.append_all(self.attrs.outer());
1840 self.sig.to_tokens(tokens);
1841 match self.default {
1842 Some(ref block) => {
1843 block.brace_token.surround(tokens, |tokens| {
1844 tokens.append_all(self.attrs.inner());
1845 tokens.append_all(&block.stmts);
1846 });
David Tolnayca085422016-10-04 00:12:38 -07001847 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001848 None => {
1849 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001850 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001851 }
1852 }
1853 }
1854
1855 impl ToTokens for TraitItemType {
1856 fn to_tokens(&self, tokens: &mut Tokens) {
1857 tokens.append_all(self.attrs.outer());
1858 self.type_token.to_tokens(tokens);
1859 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001860 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001861 if !self.bounds.is_empty() {
1862 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1863 self.bounds.to_tokens(tokens);
1864 }
Nika Layzell0183ca32017-12-05 15:24:01 -05001865 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001866 if let Some((ref eq_token, ref default)) = self.default {
1867 eq_token.to_tokens(tokens);
1868 default.to_tokens(tokens);
1869 }
1870 self.semi_token.to_tokens(tokens);
1871 }
1872 }
1873
1874 impl ToTokens for TraitItemMacro {
1875 fn to_tokens(&self, tokens: &mut Tokens) {
1876 tokens.append_all(self.attrs.outer());
1877 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001878 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001879 }
1880 }
1881
David Tolnay2ae520a2017-12-29 11:19:50 -05001882 impl ToTokens for TraitItemVerbatim {
1883 fn to_tokens(&self, tokens: &mut Tokens) {
1884 self.tts.to_tokens(tokens);
1885 }
1886 }
1887
David Tolnay857628c2017-11-11 12:25:31 -08001888 impl ToTokens for ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001889 fn to_tokens(&self, tokens: &mut Tokens) {
1890 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08001891 self.vis.to_tokens(tokens);
1892 self.defaultness.to_tokens(tokens);
1893 self.const_token.to_tokens(tokens);
1894 self.ident.to_tokens(tokens);
1895 self.colon_token.to_tokens(tokens);
1896 self.ty.to_tokens(tokens);
1897 self.eq_token.to_tokens(tokens);
1898 self.expr.to_tokens(tokens);
1899 self.semi_token.to_tokens(tokens);
1900 }
1901 }
1902
1903 impl ToTokens for ImplItemMethod {
1904 fn to_tokens(&self, tokens: &mut Tokens) {
1905 tokens.append_all(self.attrs.outer());
1906 self.vis.to_tokens(tokens);
1907 self.defaultness.to_tokens(tokens);
1908 self.sig.to_tokens(tokens);
1909 self.block.brace_token.surround(tokens, |tokens| {
1910 tokens.append_all(self.attrs.inner());
1911 tokens.append_all(&self.block.stmts);
1912 });
1913 }
1914 }
1915
1916 impl ToTokens for ImplItemType {
1917 fn to_tokens(&self, tokens: &mut Tokens) {
1918 tokens.append_all(self.attrs.outer());
1919 self.vis.to_tokens(tokens);
1920 self.defaultness.to_tokens(tokens);
1921 self.type_token.to_tokens(tokens);
1922 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001923 self.generics.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08001924 self.eq_token.to_tokens(tokens);
1925 self.ty.to_tokens(tokens);
1926 self.semi_token.to_tokens(tokens);
1927 }
1928 }
1929
1930 impl ToTokens for ImplItemMacro {
1931 fn to_tokens(&self, tokens: &mut Tokens) {
1932 tokens.append_all(self.attrs.outer());
1933 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001934 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07001935 }
1936 }
1937
David Tolnay2ae520a2017-12-29 11:19:50 -05001938 impl ToTokens for ImplItemVerbatim {
1939 fn to_tokens(&self, tokens: &mut Tokens) {
1940 self.tts.to_tokens(tokens);
1941 }
1942 }
1943
David Tolnay8894f602017-11-11 12:11:04 -08001944 impl ToTokens for ForeignItemFn {
David Tolnay35902302016-10-06 01:11:08 -07001945 fn to_tokens(&self, tokens: &mut Tokens) {
1946 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001947 self.vis.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001948 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1949 self.semi_token.to_tokens(tokens);
1950 }
1951 }
1952
1953 impl ToTokens for ForeignItemStatic {
1954 fn to_tokens(&self, tokens: &mut Tokens) {
1955 tokens.append_all(self.attrs.outer());
1956 self.vis.to_tokens(tokens);
1957 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001958 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001959 self.ident.to_tokens(tokens);
1960 self.colon_token.to_tokens(tokens);
1961 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001962 self.semi_token.to_tokens(tokens);
1963 }
1964 }
1965
David Tolnay199bcbb2017-11-12 10:33:52 -08001966 impl ToTokens for ForeignItemType {
1967 fn to_tokens(&self, tokens: &mut Tokens) {
1968 tokens.append_all(self.attrs.outer());
1969 self.vis.to_tokens(tokens);
1970 self.type_token.to_tokens(tokens);
1971 self.ident.to_tokens(tokens);
1972 self.semi_token.to_tokens(tokens);
1973 }
1974 }
1975
David Tolnay2ae520a2017-12-29 11:19:50 -05001976 impl ToTokens for ForeignItemVerbatim {
1977 fn to_tokens(&self, tokens: &mut Tokens) {
1978 self.tts.to_tokens(tokens);
1979 }
1980 }
1981
David Tolnay570695e2017-06-03 16:15:13 -07001982 impl ToTokens for MethodSig {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001983 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay570695e2017-06-03 16:15:13 -07001984 self.constness.to_tokens(tokens);
1985 self.unsafety.to_tokens(tokens);
1986 self.abi.to_tokens(tokens);
1987 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001988 }
1989 }
1990
David Tolnay570695e2017-06-03 16:15:13 -07001991 struct NamedDecl<'a>(&'a FnDecl, Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001992
1993 impl<'a> ToTokens for NamedDecl<'a> {
1994 fn to_tokens(&self, tokens: &mut Tokens) {
1995 self.0.fn_token.to_tokens(tokens);
1996 self.1.to_tokens(tokens);
1997 self.0.generics.to_tokens(tokens);
1998 self.0.paren_token.surround(tokens, |tokens| {
1999 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05002000 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
2001 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04002002 }
David Tolnayd2836e22017-12-27 23:13:00 -05002003 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002004 });
2005 self.0.output.to_tokens(tokens);
2006 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07002007 }
2008 }
2009
Alex Crichton62a0a592017-05-22 13:58:53 -07002010 impl ToTokens for ArgSelfRef {
David Tolnay62f374c2016-10-02 13:37:00 -07002011 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002012 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002013 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002014 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002015 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002016 }
2017 }
2018
2019 impl ToTokens for ArgSelf {
2020 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay24237fb2017-12-29 02:15:26 -05002021 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002022 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002023 }
2024 }
2025
2026 impl ToTokens for ArgCaptured {
2027 fn to_tokens(&self, tokens: &mut Tokens) {
2028 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002029 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002030 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07002031 }
2032 }
David Tolnay4a51dc72016-10-01 00:40:31 -07002033}