blob: 7b5a01551abe2573ac7b798f499a0764f85d6421 [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 Tolnaye303b7c2018-05-20 16:46:35 -070011use 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 Tolnay65fb5662018-05-20 20:02:28 -0700251 self.attrs == other.attrs
252 && self.vis == other.vis
253 && self.macro_token == other.macro_token
254 && self.ident == other.ident
255 && self.paren_token == other.paren_token
David Tolnayab919512017-12-30 23:31:51 -0500256 && TokenStreamHelper(&self.args) == TokenStreamHelper(&other.args)
257 && self.brace_token == other.brace_token
258 && TokenStreamHelper(&self.body) == TokenStreamHelper(&other.body)
David Tolnay9c76bcb2017-12-26 23:14:59 -0500259 }
260}
261
262#[cfg(feature = "extra-traits")]
263impl Hash for ItemMacro2 {
264 fn hash<H>(&self, state: &mut H)
David Tolnay51382052017-12-27 13:46:21 -0500265 where
266 H: Hasher,
David Tolnay9c76bcb2017-12-26 23:14:59 -0500267 {
268 self.attrs.hash(state);
269 self.vis.hash(state);
270 self.macro_token.hash(state);
271 self.ident.hash(state);
David Tolnayab919512017-12-30 23:31:51 -0500272 self.paren_token.hash(state);
273 TokenStreamHelper(&self.args).hash(state);
274 self.brace_token.hash(state);
275 TokenStreamHelper(&self.body).hash(state);
David Tolnay9c76bcb2017-12-26 23:14:59 -0500276 }
277}
278
David Tolnay2ae520a2017-12-29 11:19:50 -0500279#[cfg(feature = "extra-traits")]
280impl Eq for ItemVerbatim {}
281
282#[cfg(feature = "extra-traits")]
283impl PartialEq for ItemVerbatim {
284 fn eq(&self, other: &Self) -> bool {
285 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
286 }
287}
288
289#[cfg(feature = "extra-traits")]
290impl Hash for ItemVerbatim {
291 fn hash<H>(&self, state: &mut H)
292 where
293 H: Hasher,
294 {
295 TokenStreamHelper(&self.tts).hash(state);
296 }
297}
298
David Tolnay0e837402016-12-22 17:25:55 -0500299impl From<DeriveInput> for Item {
300 fn from(input: DeriveInput) -> Item {
David Tolnaye3d41b72017-12-31 15:24:00 -0500301 match input.data {
302 Data::Struct(data) => Item::Struct(ItemStruct {
303 attrs: input.attrs,
304 vis: input.vis,
305 struct_token: data.struct_token,
306 ident: input.ident,
307 generics: input.generics,
308 fields: data.fields,
309 semi_token: data.semi_token,
310 }),
311 Data::Enum(data) => Item::Enum(ItemEnum {
David Tolnay51382052017-12-27 13:46:21 -0500312 attrs: input.attrs,
313 vis: input.vis,
314 enum_token: data.enum_token,
315 ident: input.ident,
316 generics: input.generics,
317 brace_token: data.brace_token,
318 variants: data.variants,
319 }),
David Tolnaye3d41b72017-12-31 15:24:00 -0500320 Data::Union(data) => Item::Union(ItemUnion {
David Tolnay51382052017-12-27 13:46:21 -0500321 attrs: input.attrs,
322 vis: input.vis,
David Tolnaye3d41b72017-12-31 15:24:00 -0500323 union_token: data.union_token,
David Tolnay51382052017-12-27 13:46:21 -0500324 ident: input.ident,
325 generics: input.generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500326 fields: data.fields,
David Tolnay51382052017-12-27 13:46:21 -0500327 }),
David Tolnay453cfd12016-10-23 11:00:14 -0700328 }
329 }
330}
331
Alex Crichton62a0a592017-05-22 13:58:53 -0700332ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800333 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
David Tolnay614a0142018-01-07 10:25:43 -0800334 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800335 /// *This type is available if Syn is built with the `"full"` feature.*
336 ///
David Tolnay614a0142018-01-07 10:25:43 -0800337 /// # Syntax tree enum
338 ///
339 /// This type is a [syntax tree enum].
340 ///
341 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay5f332a92017-12-26 00:42:45 -0500342 pub enum UseTree {
David Tolnayd97a7d22018-03-31 19:17:01 +0200343 /// A path prefix of imports in a `use` item: `std::...`.
David Tolnay461d98e2018-01-07 11:07:19 -0800344 ///
345 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500346 pub Path(UsePath {
347 pub ident: Ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200348 pub colon2_token: Token![::],
349 pub tree: Box<UseTree>,
350 }),
351
352 /// An identifier imported by a `use` item: `HashMap`.
353 ///
354 /// *This type is available if Syn is built with the `"full"` feature.*
355 pub Name(UseName {
356 pub ident: Ident,
357 }),
358
359 /// An renamed identifier imported by a `use` item: `HashMap as Map`.
360 ///
361 /// *This type is available if Syn is built with the `"full"` feature.*
362 pub Rename(UseRename {
363 pub ident: Ident,
364 pub as_token: Token![as],
365 pub rename: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700366 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800367
David Tolnay05658502018-01-07 09:56:37 -0800368 /// A glob import in a `use` item: `*`.
David Tolnay461d98e2018-01-07 11:07:19 -0800369 ///
370 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500371 pub Glob(UseGlob {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800372 pub star_token: Token![*],
Alex Crichton62a0a592017-05-22 13:58:53 -0700373 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800374
David Tolnayd97a7d22018-03-31 19:17:01 +0200375 /// A braced group of imports in a `use` item: `{A, B, C}`.
David Tolnay461d98e2018-01-07 11:07:19 -0800376 ///
377 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayd97a7d22018-03-31 19:17:01 +0200378 pub Group(UseGroup {
David Tolnay32954ef2017-12-26 22:43:16 -0500379 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500380 pub items: Punctuated<UseTree, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700381 }),
382 }
383}
384
Alex Crichton62a0a592017-05-22 13:58:53 -0700385ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800386 /// An item within an `extern` block.
David Tolnay614a0142018-01-07 10:25:43 -0800387 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800388 /// *This type is available if Syn is built with the `"full"` feature.*
389 ///
David Tolnay614a0142018-01-07 10:25:43 -0800390 /// # Syntax tree enum
391 ///
392 /// This type is a [syntax tree enum].
393 ///
394 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay8894f602017-11-11 12:11:04 -0800395 pub enum ForeignItem {
David Tolnayebb72722018-01-07 01:14:13 -0800396 /// A foreign function in an `extern` block.
David Tolnay461d98e2018-01-07 11:07:19 -0800397 ///
398 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700399 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800400 pub attrs: Vec<Attribute>,
401 pub vis: Visibility,
402 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700403 pub decl: Box<FnDecl>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800404 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700405 }),
David Tolnayebb72722018-01-07 01:14:13 -0800406
407 /// A foreign static item in an `extern` block: `static ext: u8`.
David Tolnay461d98e2018-01-07 11:07:19 -0800408 ///
409 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700410 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800411 pub attrs: Vec<Attribute>,
412 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800413 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -0500414 pub mutability: Option<Token![mut]>,
David Tolnay8894f602017-11-11 12:11:04 -0800415 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800416 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800417 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800418 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700419 }),
David Tolnayebb72722018-01-07 01:14:13 -0800420
421 /// A foreign type in an `extern` block: `type void`.
David Tolnay461d98e2018-01-07 11:07:19 -0800422 ///
423 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay199bcbb2017-11-12 10:33:52 -0800424 pub Type(ForeignItemType {
425 pub attrs: Vec<Attribute>,
426 pub vis: Visibility,
427 pub type_token: Token![type],
428 pub ident: Ident,
429 pub semi_token: Token![;],
430 }),
David Tolnayebb72722018-01-07 01:14:13 -0800431
432 /// Tokens in an `extern` block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800433 ///
434 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500435 pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
436 pub tts: TokenStream,
437 }),
438 }
439}
440
441#[cfg(feature = "extra-traits")]
442impl Eq for ForeignItemVerbatim {}
443
444#[cfg(feature = "extra-traits")]
445impl PartialEq for ForeignItemVerbatim {
446 fn eq(&self, other: &Self) -> bool {
447 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
448 }
449}
450
451#[cfg(feature = "extra-traits")]
452impl Hash for ForeignItemVerbatim {
453 fn hash<H>(&self, state: &mut H)
454 where
455 H: Hasher,
456 {
457 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700458 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700459}
460
David Tolnayda705bd2017-11-10 21:58:05 -0800461ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800462 /// An item declaration within the definition of a trait.
David Tolnay614a0142018-01-07 10:25:43 -0800463 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800464 /// *This type is available if Syn is built with the `"full"` feature.*
465 ///
David Tolnay614a0142018-01-07 10:25:43 -0800466 /// # Syntax tree enum
467 ///
468 /// This type is a [syntax tree enum].
469 ///
470 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayda705bd2017-11-10 21:58:05 -0800471 pub enum TraitItem {
David Tolnayebb72722018-01-07 01:14:13 -0800472 /// An associated constant within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800473 ///
474 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700475 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800476 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800477 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700478 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800479 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800480 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800481 pub default: Option<(Token![=], Expr)>,
482 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700483 }),
David Tolnayebb72722018-01-07 01:14:13 -0800484
485 /// A trait method within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800486 ///
487 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700488 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800489 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700490 pub sig: MethodSig,
491 pub default: Option<Block>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800492 pub semi_token: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700493 }),
David Tolnayebb72722018-01-07 01:14:13 -0800494
495 /// An associated type within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800496 ///
497 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700498 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800499 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800500 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700501 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500502 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800503 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500504 pub bounds: Punctuated<TypeParamBound, Token![+]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800505 pub default: Option<(Token![=], Type)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800506 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700507 }),
David Tolnayebb72722018-01-07 01:14:13 -0800508
509 /// A macro invocation within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800510 ///
511 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800512 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800513 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800514 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500515 pub semi_token: Option<Token![;]>,
David Tolnayda705bd2017-11-10 21:58:05 -0800516 }),
David Tolnayebb72722018-01-07 01:14:13 -0800517
518 /// Tokens within the definition of a trait not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800519 ///
520 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500521 pub Verbatim(TraitItemVerbatim #manual_extra_traits {
522 pub tts: TokenStream,
523 }),
524 }
525}
526
527#[cfg(feature = "extra-traits")]
528impl Eq for TraitItemVerbatim {}
529
530#[cfg(feature = "extra-traits")]
531impl PartialEq for TraitItemVerbatim {
532 fn eq(&self, other: &Self) -> bool {
533 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
534 }
535}
536
537#[cfg(feature = "extra-traits")]
538impl Hash for TraitItemVerbatim {
539 fn hash<H>(&self, state: &mut H)
540 where
541 H: Hasher,
542 {
543 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700544 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700545}
546
Alex Crichton62a0a592017-05-22 13:58:53 -0700547ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800548 /// An item within an impl block.
David Tolnay614a0142018-01-07 10:25:43 -0800549 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800550 /// *This type is available if Syn is built with the `"full"` feature.*
551 ///
David Tolnay614a0142018-01-07 10:25:43 -0800552 /// # Syntax tree enum
553 ///
554 /// This type is a [syntax tree enum].
555 ///
556 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay857628c2017-11-11 12:25:31 -0800557 pub enum ImplItem {
David Tolnayebb72722018-01-07 01:14:13 -0800558 /// An associated constant within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800559 ///
560 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700561 pub Const(ImplItemConst {
David Tolnay857628c2017-11-11 12:25:31 -0800562 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700563 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500564 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800565 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700566 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800567 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800568 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800569 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -0700570 pub expr: Expr,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800571 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700572 }),
David Tolnayebb72722018-01-07 01:14:13 -0800573
574 /// A method within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800575 ///
576 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700577 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800578 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700579 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500580 pub defaultness: Option<Token![default]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700581 pub sig: MethodSig,
582 pub block: Block,
583 }),
David Tolnayebb72722018-01-07 01:14:13 -0800584
585 /// An associated type within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800586 ///
587 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700588 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800589 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700590 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500591 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800592 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700593 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500594 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800595 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800596 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800597 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700598 }),
David Tolnayebb72722018-01-07 01:14:13 -0800599
600 /// A macro invocation within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800601 ///
602 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay857628c2017-11-11 12:25:31 -0800603 pub Macro(ImplItemMacro {
604 pub attrs: Vec<Attribute>,
605 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500606 pub semi_token: Option<Token![;]>,
David Tolnay857628c2017-11-11 12:25:31 -0800607 }),
David Tolnayebb72722018-01-07 01:14:13 -0800608
609 /// Tokens within an impl block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800610 ///
611 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500612 pub Verbatim(ImplItemVerbatim #manual_extra_traits {
613 pub tts: TokenStream,
614 }),
615 }
616}
617
618#[cfg(feature = "extra-traits")]
619impl Eq for ImplItemVerbatim {}
620
621#[cfg(feature = "extra-traits")]
622impl PartialEq for ImplItemVerbatim {
623 fn eq(&self, other: &Self) -> bool {
624 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
625 }
626}
627
628#[cfg(feature = "extra-traits")]
629impl Hash for ImplItemVerbatim {
630 fn hash<H>(&self, state: &mut H)
631 where
632 H: Hasher,
633 {
634 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700635 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700636}
637
638ast_struct! {
David Tolnay05658502018-01-07 09:56:37 -0800639 /// A method's signature in a trait or implementation: `unsafe fn
640 /// initialize(&self)`.
David Tolnay461d98e2018-01-07 11:07:19 -0800641 ///
642 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700643 pub struct MethodSig {
David Tolnay360a6342017-12-29 02:22:11 -0500644 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -0500645 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700646 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700647 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700648 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700649 }
650}
651
652ast_struct! {
David Tolnayebb72722018-01-07 01:14:13 -0800653 /// Header of a function declaration, without including the body.
David Tolnay461d98e2018-01-07 11:07:19 -0800654 ///
655 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700656 pub struct FnDecl {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800657 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500658 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500659 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -0500660 pub inputs: Punctuated<FnArg, Token![,]>,
David Tolnayd2836e22017-12-27 23:13:00 -0500661 pub variadic: Option<Token![...]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500662 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700663 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700664}
665
Alex Crichton62a0a592017-05-22 13:58:53 -0700666ast_enum_of_structs! {
David Tolnayc0435192018-01-07 11:46:08 -0800667 /// An argument in a function signature: the `n: usize` in `fn f(n: usize)`.
David Tolnay614a0142018-01-07 10:25:43 -0800668 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800669 /// *This type is available if Syn is built with the `"full"` feature.*
670 ///
David Tolnay614a0142018-01-07 10:25:43 -0800671 /// # Syntax tree enum
672 ///
673 /// This type is a [syntax tree enum].
674 ///
675 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700676 pub enum FnArg {
David Tolnay3f559052018-01-06 23:59:48 -0800677 /// Self captured by reference in a function signature: `&self` or `&mut
678 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800679 ///
680 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700681 pub SelfRef(ArgSelfRef {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800682 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -0700683 pub lifetime: Option<Lifetime>,
David Tolnay24237fb2017-12-29 02:15:26 -0500684 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500685 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700686 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800687
David Tolnay3f559052018-01-06 23:59:48 -0800688 /// Self captured by value in a function signature: `self` or `mut
689 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800690 ///
691 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700692 pub SelfValue(ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500693 pub mutability: Option<Token![mut]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800694 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700695 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800696
David Tolnay3f559052018-01-06 23:59:48 -0800697 /// An explicitly typed pattern captured by a function signature.
David Tolnay461d98e2018-01-07 11:07:19 -0800698 ///
699 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700700 pub Captured(ArgCaptured {
701 pub pat: Pat,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800702 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800703 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700704 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800705
David Tolnay3f559052018-01-06 23:59:48 -0800706 /// A pattern whose type is inferred captured by a function signature.
David Tolnay80ed55f2017-12-27 22:54:40 -0500707 pub Inferred(Pat),
David Tolnay3f559052018-01-06 23:59:48 -0800708 /// A type not bound to any pattern in a function signature.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800709 pub Ignored(Type),
Alex Crichton62a0a592017-05-22 13:58:53 -0700710 }
David Tolnay62f374c2016-10-02 13:37:00 -0700711}
712
David Tolnayedf2b992016-09-23 20:43:45 -0700713#[cfg(feature = "parsing")]
714pub mod parsing {
715 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700716
David Tolnayb21b0342018-01-18 23:36:26 -0800717 use synom::Synom;
David Tolnay84aa0752016-10-02 23:01:13 -0700718
David Tolnay4c614be2017-11-10 00:02:38 -0800719 impl_synom!(Item "item" alt!(
720 syn!(ItemExternCrate) => { Item::ExternCrate }
721 |
722 syn!(ItemUse) => { Item::Use }
723 |
724 syn!(ItemStatic) => { Item::Static }
725 |
726 syn!(ItemConst) => { Item::Const }
727 |
728 syn!(ItemFn) => { Item::Fn }
729 |
730 syn!(ItemMod) => { Item::Mod }
731 |
732 syn!(ItemForeignMod) => { Item::ForeignMod }
733 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800734 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800735 |
736 syn!(ItemStruct) => { Item::Struct }
737 |
738 syn!(ItemEnum) => { Item::Enum }
739 |
740 syn!(ItemUnion) => { Item::Union }
741 |
742 syn!(ItemTrait) => { Item::Trait }
743 |
David Tolnay4c614be2017-11-10 00:02:38 -0800744 syn!(ItemImpl) => { Item::Impl }
745 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800746 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800747 |
748 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800749 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700750
David Tolnaydecf28d2017-11-11 11:56:45 -0800751 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500752 attrs: many0!(Attribute::parse_outer) >>
David Tolnayd69fc2b2018-01-23 09:39:14 -0800753 what: call!(Path::parse_mod_style) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800754 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700755 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500756 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500757 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800758 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700759 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800760 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800761 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500762 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700763 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500764 delimiter: body.0,
765 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800766 },
David Tolnay57292da2017-12-27 21:03:33 -0500767 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800768 })
David Tolnayedf2b992016-09-23 20:43:45 -0700769 ));
770
David Tolnay500d8322017-12-18 00:32:51 -0800771 // TODO: figure out the actual grammar; is body required to be braced?
772 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500773 attrs: many0!(Attribute::parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800774 vis: syn!(Visibility) >>
775 macro_: keyword!(macro) >>
776 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500777 args: call!(tt::parenthesized) >>
778 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800779 (ItemMacro2 {
780 attrs: attrs,
781 vis: vis,
782 macro_token: macro_,
783 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500784 paren_token: args.0,
785 args: args.1,
786 brace_token: body.0,
787 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800788 })
789 ));
790
David Tolnay4c614be2017-11-10 00:02:38 -0800791 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500792 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700793 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800794 extern_: keyword!(extern) >>
795 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700796 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800797 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
798 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800799 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700800 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800801 vis: vis,
802 extern_token: extern_,
803 crate_token: crate_,
804 ident: ident,
805 rename: rename,
806 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800807 })
David Tolnayedf2b992016-09-23 20:43:45 -0700808 ));
809
David Tolnay4c614be2017-11-10 00:02:38 -0800810 impl_synom!(ItemUse "use item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500811 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700812 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800813 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500814 leading_colon: option!(punct!(::)) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200815 tree: syn!(UseTree) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800816 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800817 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700818 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800819 vis: vis,
820 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500821 leading_colon: leading_colon,
David Tolnay5f332a92017-12-26 00:42:45 -0500822 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800823 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800824 })
David Tolnay4a057422016-10-08 00:02:31 -0700825 ));
826
David Tolnayd97a7d22018-03-31 19:17:01 +0200827 named!(use_element -> Ident, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500828 syn!(Ident)
829 |
830 keyword!(self) => { Into::into }
831 |
832 keyword!(super) => { Into::into }
833 |
834 keyword!(crate) => { Into::into }
835 ));
836
837 impl_synom!(UseTree "use tree" alt!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200838 syn!(UseRename) => { UseTree::Rename }
839 |
David Tolnay5f332a92017-12-26 00:42:45 -0500840 syn!(UsePath) => { UseTree::Path }
841 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200842 syn!(UseName) => { UseTree::Name }
843 |
David Tolnay5f332a92017-12-26 00:42:45 -0500844 syn!(UseGlob) => { UseTree::Glob }
845 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200846 syn!(UseGroup) => { UseTree::Group }
David Tolnay5f332a92017-12-26 00:42:45 -0500847 ));
848
849 impl_synom!(UsePath "use path" do_parse!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200850 ident: call!(use_element) >>
851 colon2_token: punct!(::) >>
852 tree: syn!(UseTree) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500853 (UsePath {
854 ident: ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200855 colon2_token: colon2_token,
856 tree: Box::new(tree),
857 })
858 ));
859
860 impl_synom!(UseName "use name" do_parse!(
861 ident: call!(use_element) >>
862 (UseName {
863 ident: ident,
864 })
865 ));
866
867 impl_synom!(UseRename "use rename" do_parse!(
868 ident: call!(use_element) >>
869 as_token: keyword!(as) >>
870 rename: syn!(Ident) >>
871 (UseRename {
872 ident: ident,
873 as_token: as_token,
David Tolnay5f332a92017-12-26 00:42:45 -0500874 rename: rename,
875 })
876 ));
David Tolnay4a057422016-10-08 00:02:31 -0700877
David Tolnay5f332a92017-12-26 00:42:45 -0500878 impl_synom!(UseGlob "use glob" do_parse!(
879 star: punct!(*) >>
880 (UseGlob {
881 star_token: star,
882 })
883 ));
David Tolnay4a057422016-10-08 00:02:31 -0700884
David Tolnayd97a7d22018-03-31 19:17:01 +0200885 impl_synom!(UseGroup "use group" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500886 list: braces!(Punctuated::parse_terminated) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200887 (UseGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500888 brace_token: list.0,
889 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500890 })
891 ));
David Tolnay4a057422016-10-08 00:02:31 -0700892
David Tolnay4c614be2017-11-10 00:02:38 -0800893 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500894 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700895 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800896 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500897 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700898 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800899 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800900 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800901 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700902 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800903 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800904 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700905 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800906 vis: vis,
907 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500908 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800909 ident: ident,
910 colon_token: colon,
911 ty: Box::new(ty),
912 eq_token: eq,
913 expr: Box::new(value),
914 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800915 })
David Tolnay47a877c2016-10-01 16:50:55 -0700916 ));
917
David Tolnay4c614be2017-11-10 00:02:38 -0800918 impl_synom!(ItemConst "const item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500919 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700920 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800921 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700922 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800923 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800924 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800925 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700926 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800927 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800928 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700929 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800930 vis: vis,
931 const_token: const_,
932 ident: ident,
933 colon_token: colon,
934 ty: Box::new(ty),
935 eq_token: eq,
936 expr: Box::new(value),
937 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800938 })
David Tolnay47a877c2016-10-01 16:50:55 -0700939 ));
940
David Tolnay4c614be2017-11-10 00:02:38 -0800941 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500942 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700943 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -0500944 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500945 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700946 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800947 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -0700948 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700949 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500950 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800951 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -0500952 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700953 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -0500954 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -0700955 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -0400956 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800957 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -0700958 attrs: {
959 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -0500960 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -0700961 attrs
962 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800963 vis: vis,
964 constness: constness,
965 unsafety: unsafety,
966 abi: abi,
967 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800968 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500969 paren_token: inputs.0,
970 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800971 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -0500972 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800973 generics: Generics {
974 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -0700975 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -0800976 },
977 }),
978 ident: ident,
979 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -0500980 brace_token: inner_attrs_stmts.0,
981 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800982 }),
David Tolnay4c614be2017-11-10 00:02:38 -0800983 })
David Tolnay42602292016-10-01 22:25:45 -0700984 ));
985
Alex Crichton954046c2017-05-30 21:49:42 -0700986 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400987 named!(parse -> Self, alt!(
988 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800989 and: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400990 lt: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500991 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800992 self_: keyword!(self) >>
993 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400994 (ArgSelfRef {
995 lifetime: lt,
David Tolnay24237fb2017-12-29 02:15:26 -0500996 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400997 and_token: and,
998 self_token: self_,
999 }.into())
1000 )
1001 |
1002 do_parse!(
David Tolnay24237fb2017-12-29 02:15:26 -05001003 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001004 self_: keyword!(self) >>
1005 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001006 (ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -05001007 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -04001008 self_token: self_,
1009 }.into())
1010 )
1011 |
1012 do_parse!(
1013 pat: syn!(Pat) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001014 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001015 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001016 (ArgCaptured {
1017 pat: pat,
1018 ty: ty,
1019 colon_token: colon,
1020 }.into())
1021 )
1022 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001023 syn!(Type) => { FnArg::Ignored }
Michael Layzell92639a52017-06-01 00:07:44 -04001024 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001025
1026 fn description() -> Option<&'static str> {
1027 Some("function argument")
1028 }
Alex Crichton954046c2017-05-30 21:49:42 -07001029 }
David Tolnay62f374c2016-10-02 13:37:00 -07001030
David Tolnay4c614be2017-11-10 00:02:38 -08001031 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001032 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001033 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001034 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -07001035 ident: syn!(Ident) >>
1036 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001037 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -07001038 Vec::new(),
1039 None,
1040 Some(semi),
1041 )}
David Tolnay37d10332016-10-13 20:51:04 -07001042 |
Alex Crichton954046c2017-05-30 21:49:42 -07001043 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -07001044 tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001045 many0!(Attribute::parse_inner),
1046 many0!(Item::parse)
Michael Layzell416724e2017-05-24 21:12:34 -04001047 )
David Tolnay8875fca2017-12-31 13:52:37 -05001048 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -07001049 inner_attrs,
1050 Some((brace, items)),
1051 None,
1052 )}
David Tolnay37d10332016-10-13 20:51:04 -07001053 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001054 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -07001055 attrs: {
1056 let mut attrs = outer_attrs;
1057 attrs.extend(content_semi.0);
1058 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -07001059 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001060 vis: vis,
1061 mod_token: mod_,
1062 ident: ident,
1063 content: content_semi.1,
1064 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -08001065 })
David Tolnay35902302016-10-06 01:11:08 -07001066 ));
1067
David Tolnay4c614be2017-11-10 00:02:38 -08001068 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001069 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001070 abi: syn!(Abi) >>
David Tolnay2c136452017-12-27 14:13:32 -05001071 items: braces!(many0!(ForeignItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001072 (ItemForeignMod {
David Tolnay35902302016-10-06 01:11:08 -07001073 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001074 abi: abi,
David Tolnay8875fca2017-12-31 13:52:37 -05001075 brace_token: items.0,
1076 items: items.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001077 })
David Tolnay35902302016-10-06 01:11:08 -07001078 ));
1079
David Tolnay8894f602017-11-11 12:11:04 -08001080 impl_synom!(ForeignItem "foreign item" alt!(
1081 syn!(ForeignItemFn) => { ForeignItem::Fn }
1082 |
1083 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -08001084 |
1085 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay8894f602017-11-11 12:11:04 -08001086 ));
David Tolnay35902302016-10-06 01:11:08 -07001087
David Tolnay8894f602017-11-11 12:11:04 -08001088 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001089 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001090 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001091 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001092 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001093 generics: syn!(Generics) >>
1094 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -05001095 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -05001096 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001097 (args, variadic)
1098 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001099 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001100 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001101 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001102 ({
David Tolnay8875fca2017-12-31 13:52:37 -05001103 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -08001104 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -07001105 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -07001106 attrs: attrs,
1107 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001108 decl: Box::new(FnDecl {
1109 fn_token: fn_,
1110 paren_token: parens,
1111 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001112 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001113 output: ret,
1114 generics: Generics {
1115 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001116 ..generics
David Tolnay8894f602017-11-11 12:11:04 -08001117 },
1118 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001119 vis: vis,
1120 }
David Tolnay35902302016-10-06 01:11:08 -07001121 })
1122 ));
1123
David Tolnay8894f602017-11-11 12:11:04 -08001124 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001125 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001126 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001127 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001128 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001129 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001130 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001131 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001132 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001133 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001134 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001135 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001136 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001137 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001138 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001139 static_token: static_,
1140 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001141 vis: vis,
1142 })
1143 ));
1144
David Tolnay199bcbb2017-11-12 10:33:52 -08001145 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001146 attrs: many0!(Attribute::parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001147 vis: syn!(Visibility) >>
1148 type_: keyword!(type) >>
1149 ident: syn!(Ident) >>
1150 semi: punct!(;) >>
1151 (ForeignItemType {
1152 attrs: attrs,
1153 vis: vis,
1154 type_token: type_,
1155 ident: ident,
1156 semi_token: semi,
1157 })
1158 ));
1159
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001160 impl_synom!(ItemType "type item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001161 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001162 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001163 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001164 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001165 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001166 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001167 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001168 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001169 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001170 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001171 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001172 vis: vis,
1173 type_token: type_,
1174 ident: ident,
1175 generics: Generics {
1176 where_clause: where_clause,
1177 ..generics
1178 },
1179 eq_token: eq,
1180 ty: Box::new(ty),
1181 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001182 })
David Tolnay3cf52982016-10-01 17:11:37 -07001183 ));
1184
David Tolnay4c614be2017-11-10 00:02:38 -08001185 impl_synom!(ItemStruct "struct item" switch!(
1186 map!(syn!(DeriveInput), Into::into),
1187 Item::Struct(item) => value!(item)
1188 |
1189 _ => reject!()
1190 ));
David Tolnay42602292016-10-01 22:25:45 -07001191
David Tolnay4c614be2017-11-10 00:02:38 -08001192 impl_synom!(ItemEnum "enum item" switch!(
1193 map!(syn!(DeriveInput), Into::into),
1194 Item::Enum(item) => value!(item)
1195 |
1196 _ => reject!()
1197 ));
1198
1199 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001200 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001201 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001202 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001203 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001204 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001205 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001206 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001207 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001208 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001209 vis: vis,
1210 union_token: union_,
1211 ident: ident,
1212 generics: Generics {
1213 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001214 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001215 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001216 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001217 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001218 ));
1219
David Tolnay4c614be2017-11-10 00:02:38 -08001220 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001221 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001222 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001223 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001224 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001225 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001226 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001227 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001228 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001229 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001230 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001231 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001232 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001233 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001234 vis: vis,
1235 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001236 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001237 trait_token: trait_,
1238 ident: ident,
1239 generics: Generics {
1240 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001241 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001242 },
1243 colon_token: colon,
1244 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001245 brace_token: body.0,
1246 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001247 })
David Tolnay0aecb732016-10-03 23:03:50 -07001248 ));
1249
David Tolnayda705bd2017-11-10 21:58:05 -08001250 impl_synom!(TraitItem "trait item" alt!(
1251 syn!(TraitItemConst) => { TraitItem::Const }
1252 |
1253 syn!(TraitItemMethod) => { TraitItem::Method }
1254 |
1255 syn!(TraitItemType) => { TraitItem::Type }
1256 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001257 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001258 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001259
David Tolnayda705bd2017-11-10 21:58:05 -08001260 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001261 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001262 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001263 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001264 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001265 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001266 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1267 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001268 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001269 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001270 const_token: const_,
1271 ident: ident,
1272 colon_token: colon,
1273 ty: ty,
1274 default: default,
1275 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001276 })
1277 ));
1278
David Tolnayda705bd2017-11-10 21:58:05 -08001279 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001280 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001281 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001282 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001283 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001284 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001285 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001286 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001287 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001288 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001289 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001290 body: option!(braces!(
David Tolnay2c136452017-12-27 14:13:32 -05001291 tuple!(many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001292 call!(Block::parse_within))
David Tolnay5859df12016-10-29 22:49:54 -07001293 )) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001294 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001295 ({
1296 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001297 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001298 None => (Vec::new(), None),
1299 };
David Tolnayda705bd2017-11-10 21:58:05 -08001300 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001301 attrs: {
1302 let mut attrs = outer_attrs;
1303 attrs.extend(inner_attrs);
1304 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001305 },
David Tolnayda705bd2017-11-10 21:58:05 -08001306 sig: MethodSig {
1307 constness: constness,
1308 unsafety: unsafety,
1309 abi: abi,
1310 ident: ident,
1311 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001312 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001313 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001314 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001315 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001316 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001317 generics: Generics {
1318 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001319 ..generics
David Tolnay5859df12016-10-29 22:49:54 -07001320 },
1321 },
David Tolnayda705bd2017-11-10 21:58:05 -08001322 },
1323 default: stmts.map(|stmts| {
1324 Block {
1325 stmts: stmts.0,
1326 brace_token: stmts.1,
1327 }
1328 }),
1329 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001330 }
David Tolnay0aecb732016-10-03 23:03:50 -07001331 })
1332 ));
1333
David Tolnayda705bd2017-11-10 21:58:05 -08001334 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001335 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001336 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001337 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001338 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001339 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001340 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001341 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001342 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001343 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001344 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001345 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001346 type_token: type_,
1347 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001348 generics: Generics {
1349 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001350 ..generics
Nika Layzell0183ca32017-12-05 15:24:01 -05001351 },
David Tolnayda705bd2017-11-10 21:58:05 -08001352 colon_token: colon,
1353 bounds: bounds.unwrap_or_default(),
1354 default: default,
1355 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001356 })
1357 ));
1358
David Tolnaydecf28d2017-11-11 11:56:45 -08001359 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001360 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001361 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001362 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001363 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001364 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001365 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001366 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001367 })
1368 ));
1369
David Tolnay4c614be2017-11-10 00:02:38 -08001370 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnaycf3697a2018-03-31 20:51:15 +02001371 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001372 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001373 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001374 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001375 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001376 polarity_path: alt!(
1377 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001378 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001379 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001380 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001381 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001382 )
1383 |
David Tolnay570695e2017-06-03 16:15:13 -07001384 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001385 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001386 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001387 where_clause: option!(syn!(WhereClause)) >>
David Tolnaycf3697a2018-03-31 20:51:15 +02001388 inner: braces!(tuple!(
1389 many0!(Attribute::parse_inner),
1390 many0!(ImplItem::parse)
1391 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001392 (ItemImpl {
David Tolnaycf3697a2018-03-31 20:51:15 +02001393 attrs: {
1394 let mut attrs = outer_attrs;
1395 attrs.extend((inner.1).0);
1396 attrs
1397 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001398 defaultness: defaultness,
1399 unsafety: unsafety,
1400 impl_token: impl_,
1401 generics: Generics {
1402 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001403 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001404 },
1405 trait_: polarity_path,
1406 self_ty: Box::new(self_ty),
David Tolnaycf3697a2018-03-31 20:51:15 +02001407 brace_token: inner.0,
1408 items: (inner.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001409 })
David Tolnay4c9be372016-10-06 00:47:37 -07001410 ));
1411
David Tolnay857628c2017-11-11 12:25:31 -08001412 impl_synom!(ImplItem "item in impl block" alt!(
1413 syn!(ImplItemConst) => { ImplItem::Const }
1414 |
1415 syn!(ImplItemMethod) => { ImplItem::Method }
1416 |
1417 syn!(ImplItemType) => { ImplItem::Type }
1418 |
1419 syn!(ImplItemMacro) => { ImplItem::Macro }
1420 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001421
David Tolnay857628c2017-11-11 12:25:31 -08001422 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001423 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001424 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001425 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001426 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001427 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001428 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001429 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001430 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001431 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001432 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001433 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001434 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001435 vis: vis,
1436 defaultness: defaultness,
1437 const_token: const_,
1438 ident: ident,
1439 colon_token: colon,
1440 ty: ty,
1441 eq_token: eq,
1442 expr: value,
1443 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001444 })
1445 ));
1446
David Tolnay857628c2017-11-11 12:25:31 -08001447 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001448 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001449 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001450 defaultness: option!(keyword!(default)) >>
1451 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001452 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001453 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001454 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001455 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001456 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001457 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001458 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001459 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001460 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001461 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001462 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -04001463 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001464 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001465 attrs: {
1466 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001467 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001468 attrs
1469 },
David Tolnay857628c2017-11-11 12:25:31 -08001470 vis: vis,
1471 defaultness: defaultness,
1472 sig: MethodSig {
1473 constness: constness,
1474 unsafety: unsafety,
1475 abi: abi,
1476 ident: ident,
1477 decl: FnDecl {
1478 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001479 paren_token: inputs.0,
1480 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001481 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001482 generics: Generics {
1483 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001484 ..generics
David Tolnay4c9be372016-10-06 00:47:37 -07001485 },
David Tolnayd2836e22017-12-27 23:13:00 -05001486 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001487 },
David Tolnay857628c2017-11-11 12:25:31 -08001488 },
1489 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001490 brace_token: inner_attrs_stmts.0,
1491 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001492 },
David Tolnay4c9be372016-10-06 00:47:37 -07001493 })
1494 ));
1495
David Tolnay857628c2017-11-11 12:25:31 -08001496 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001497 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001498 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001499 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001500 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001501 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001502 generics: syn!(Generics) >>
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001503 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001504 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001505 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001506 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001507 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001508 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001509 vis: vis,
1510 defaultness: defaultness,
1511 type_token: type_,
1512 ident: ident,
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001513 generics: Generics {
1514 where_clause: where_clause,
1515 ..generics
1516 },
David Tolnay857628c2017-11-11 12:25:31 -08001517 eq_token: eq,
1518 ty: ty,
1519 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001520 })
1521 ));
1522
David Tolnay857628c2017-11-11 12:25:31 -08001523 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001524 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001525 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001526 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001527 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001528 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001529 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001530 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001531 })
1532 ));
1533
David Tolnayab919512017-12-30 23:31:51 -05001534 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1535 match *delimiter {
1536 MacroDelimiter::Brace(_) => true,
1537 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001538 }
1539 }
David Tolnayedf2b992016-09-23 20:43:45 -07001540}
David Tolnay4a51dc72016-10-01 00:40:31 -07001541
1542#[cfg(feature = "printing")]
1543mod printing {
1544 use super::*;
1545 use attr::FilterAttrs;
Alex Crichtona74a1c82018-05-16 10:20:44 -07001546 use proc_macro2::TokenStream;
David Tolnay65fb5662018-05-20 20:02:28 -07001547 use quote::{ToTokens, TokenStreamExt};
David Tolnay4a51dc72016-10-01 00:40:31 -07001548
David Tolnay1bfa7332017-11-11 12:41:20 -08001549 impl ToTokens for ItemExternCrate {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001550 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001551 tokens.append_all(self.attrs.outer());
1552 self.vis.to_tokens(tokens);
1553 self.extern_token.to_tokens(tokens);
1554 self.crate_token.to_tokens(tokens);
1555 self.ident.to_tokens(tokens);
1556 if let Some((ref as_token, ref rename)) = self.rename {
1557 as_token.to_tokens(tokens);
1558 rename.to_tokens(tokens);
1559 }
1560 self.semi_token.to_tokens(tokens);
1561 }
1562 }
1563
1564 impl ToTokens for ItemUse {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001565 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001566 tokens.append_all(self.attrs.outer());
1567 self.vis.to_tokens(tokens);
1568 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001569 self.leading_colon.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001570 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001571 self.semi_token.to_tokens(tokens);
1572 }
1573 }
1574
1575 impl ToTokens for ItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001576 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001577 tokens.append_all(self.attrs.outer());
1578 self.vis.to_tokens(tokens);
1579 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001580 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001581 self.ident.to_tokens(tokens);
1582 self.colon_token.to_tokens(tokens);
1583 self.ty.to_tokens(tokens);
1584 self.eq_token.to_tokens(tokens);
1585 self.expr.to_tokens(tokens);
1586 self.semi_token.to_tokens(tokens);
1587 }
1588 }
1589
1590 impl ToTokens for ItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001591 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001592 tokens.append_all(self.attrs.outer());
1593 self.vis.to_tokens(tokens);
1594 self.const_token.to_tokens(tokens);
1595 self.ident.to_tokens(tokens);
1596 self.colon_token.to_tokens(tokens);
1597 self.ty.to_tokens(tokens);
1598 self.eq_token.to_tokens(tokens);
1599 self.expr.to_tokens(tokens);
1600 self.semi_token.to_tokens(tokens);
1601 }
1602 }
1603
1604 impl ToTokens for ItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001605 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001606 tokens.append_all(self.attrs.outer());
1607 self.vis.to_tokens(tokens);
1608 self.constness.to_tokens(tokens);
1609 self.unsafety.to_tokens(tokens);
1610 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07001611 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001612 self.block.brace_token.surround(tokens, |tokens| {
1613 tokens.append_all(self.attrs.inner());
1614 tokens.append_all(&self.block.stmts);
1615 });
1616 }
1617 }
1618
1619 impl ToTokens for ItemMod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001620 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001621 tokens.append_all(self.attrs.outer());
1622 self.vis.to_tokens(tokens);
1623 self.mod_token.to_tokens(tokens);
1624 self.ident.to_tokens(tokens);
1625 if let Some((ref brace, ref items)) = self.content {
1626 brace.surround(tokens, |tokens| {
1627 tokens.append_all(self.attrs.inner());
1628 tokens.append_all(items);
1629 });
1630 } else {
1631 TokensOrDefault(&self.semi).to_tokens(tokens);
1632 }
1633 }
1634 }
1635
1636 impl ToTokens for ItemForeignMod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001637 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001638 tokens.append_all(self.attrs.outer());
1639 self.abi.to_tokens(tokens);
1640 self.brace_token.surround(tokens, |tokens| {
1641 tokens.append_all(&self.items);
1642 });
1643 }
1644 }
1645
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001646 impl ToTokens for ItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001647 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001648 tokens.append_all(self.attrs.outer());
1649 self.vis.to_tokens(tokens);
1650 self.type_token.to_tokens(tokens);
1651 self.ident.to_tokens(tokens);
1652 self.generics.to_tokens(tokens);
1653 self.generics.where_clause.to_tokens(tokens);
1654 self.eq_token.to_tokens(tokens);
1655 self.ty.to_tokens(tokens);
1656 self.semi_token.to_tokens(tokens);
1657 }
1658 }
1659
1660 impl ToTokens for ItemEnum {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001661 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001662 tokens.append_all(self.attrs.outer());
1663 self.vis.to_tokens(tokens);
1664 self.enum_token.to_tokens(tokens);
1665 self.ident.to_tokens(tokens);
1666 self.generics.to_tokens(tokens);
1667 self.generics.where_clause.to_tokens(tokens);
1668 self.brace_token.surround(tokens, |tokens| {
1669 self.variants.to_tokens(tokens);
1670 });
1671 }
1672 }
1673
1674 impl ToTokens for ItemStruct {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001675 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001676 tokens.append_all(self.attrs.outer());
1677 self.vis.to_tokens(tokens);
1678 self.struct_token.to_tokens(tokens);
1679 self.ident.to_tokens(tokens);
1680 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001681 match self.fields {
1682 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001683 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001684 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001685 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001686 Fields::Unnamed(ref fields) => {
1687 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001688 self.generics.where_clause.to_tokens(tokens);
1689 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001690 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001691 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001692 self.generics.where_clause.to_tokens(tokens);
1693 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001694 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001695 }
1696 }
1697 }
1698
1699 impl ToTokens for ItemUnion {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001700 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001701 tokens.append_all(self.attrs.outer());
1702 self.vis.to_tokens(tokens);
1703 self.union_token.to_tokens(tokens);
1704 self.ident.to_tokens(tokens);
1705 self.generics.to_tokens(tokens);
1706 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001707 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001708 }
1709 }
1710
1711 impl ToTokens for ItemTrait {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001712 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001713 tokens.append_all(self.attrs.outer());
1714 self.vis.to_tokens(tokens);
1715 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001716 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001717 self.trait_token.to_tokens(tokens);
1718 self.ident.to_tokens(tokens);
1719 self.generics.to_tokens(tokens);
1720 if !self.supertraits.is_empty() {
1721 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1722 self.supertraits.to_tokens(tokens);
1723 }
1724 self.generics.where_clause.to_tokens(tokens);
1725 self.brace_token.surround(tokens, |tokens| {
1726 tokens.append_all(&self.items);
1727 });
1728 }
1729 }
1730
David Tolnay1bfa7332017-11-11 12:41:20 -08001731 impl ToTokens for ItemImpl {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001732 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001733 tokens.append_all(self.attrs.outer());
1734 self.defaultness.to_tokens(tokens);
1735 self.unsafety.to_tokens(tokens);
1736 self.impl_token.to_tokens(tokens);
1737 self.generics.to_tokens(tokens);
1738 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1739 polarity.to_tokens(tokens);
1740 path.to_tokens(tokens);
1741 for_token.to_tokens(tokens);
1742 }
1743 self.self_ty.to_tokens(tokens);
1744 self.generics.where_clause.to_tokens(tokens);
1745 self.brace_token.surround(tokens, |tokens| {
David Tolnaycf3697a2018-03-31 20:51:15 +02001746 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001747 tokens.append_all(&self.items);
1748 });
1749 }
1750 }
1751
1752 impl ToTokens for ItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001753 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001754 tokens.append_all(self.attrs.outer());
1755 self.mac.path.to_tokens(tokens);
1756 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001757 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001758 match self.mac.delimiter {
1759 MacroDelimiter::Paren(ref paren) => {
1760 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1761 }
1762 MacroDelimiter::Brace(ref brace) => {
1763 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1764 }
1765 MacroDelimiter::Bracket(ref bracket) => {
1766 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1767 }
1768 }
David Tolnay57292da2017-12-27 21:03:33 -05001769 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001770 }
1771 }
David Tolnay42602292016-10-01 22:25:45 -07001772
David Tolnay500d8322017-12-18 00:32:51 -08001773 impl ToTokens for ItemMacro2 {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001774 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay500d8322017-12-18 00:32:51 -08001775 tokens.append_all(self.attrs.outer());
1776 self.vis.to_tokens(tokens);
1777 self.macro_token.to_tokens(tokens);
1778 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001779 self.paren_token.surround(tokens, |tokens| {
1780 self.args.to_tokens(tokens);
1781 });
1782 self.brace_token.surround(tokens, |tokens| {
1783 self.body.to_tokens(tokens);
1784 });
David Tolnay500d8322017-12-18 00:32:51 -08001785 }
1786 }
1787
David Tolnay2ae520a2017-12-29 11:19:50 -05001788 impl ToTokens for ItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001789 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001790 self.tts.to_tokens(tokens);
1791 }
1792 }
1793
David Tolnay5f332a92017-12-26 00:42:45 -05001794 impl ToTokens for UsePath {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001795 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay5f332a92017-12-26 00:42:45 -05001796 self.ident.to_tokens(tokens);
David Tolnayd97a7d22018-03-31 19:17:01 +02001797 self.colon2_token.to_tokens(tokens);
1798 self.tree.to_tokens(tokens);
1799 }
1800 }
1801
1802 impl ToTokens for UseName {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001803 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001804 self.ident.to_tokens(tokens);
1805 }
1806 }
1807
1808 impl ToTokens for UseRename {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001809 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001810 self.ident.to_tokens(tokens);
1811 self.as_token.to_tokens(tokens);
1812 self.rename.to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001813 }
1814 }
1815
David Tolnay5f332a92017-12-26 00:42:45 -05001816 impl ToTokens for UseGlob {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001817 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001818 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001819 }
1820 }
1821
David Tolnayd97a7d22018-03-31 19:17:01 +02001822 impl ToTokens for UseGroup {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001823 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001824 self.brace_token.surround(tokens, |tokens| {
1825 self.items.to_tokens(tokens);
1826 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001827 }
1828 }
1829
David Tolnay1bfa7332017-11-11 12:41:20 -08001830 impl ToTokens for TraitItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001831 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001832 tokens.append_all(self.attrs.outer());
1833 self.const_token.to_tokens(tokens);
1834 self.ident.to_tokens(tokens);
1835 self.colon_token.to_tokens(tokens);
1836 self.ty.to_tokens(tokens);
1837 if let Some((ref eq_token, ref default)) = self.default {
1838 eq_token.to_tokens(tokens);
1839 default.to_tokens(tokens);
1840 }
1841 self.semi_token.to_tokens(tokens);
1842 }
1843 }
1844
1845 impl ToTokens for TraitItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001846 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001847 tokens.append_all(self.attrs.outer());
1848 self.sig.to_tokens(tokens);
1849 match self.default {
1850 Some(ref block) => {
1851 block.brace_token.surround(tokens, |tokens| {
1852 tokens.append_all(self.attrs.inner());
1853 tokens.append_all(&block.stmts);
1854 });
David Tolnayca085422016-10-04 00:12:38 -07001855 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001856 None => {
1857 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001858 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001859 }
1860 }
1861 }
1862
1863 impl ToTokens for TraitItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001864 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001865 tokens.append_all(self.attrs.outer());
1866 self.type_token.to_tokens(tokens);
1867 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001868 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001869 if !self.bounds.is_empty() {
1870 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1871 self.bounds.to_tokens(tokens);
1872 }
Nika Layzell0183ca32017-12-05 15:24:01 -05001873 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001874 if let Some((ref eq_token, ref default)) = self.default {
1875 eq_token.to_tokens(tokens);
1876 default.to_tokens(tokens);
1877 }
1878 self.semi_token.to_tokens(tokens);
1879 }
1880 }
1881
1882 impl ToTokens for TraitItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001883 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001884 tokens.append_all(self.attrs.outer());
1885 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001886 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001887 }
1888 }
1889
David Tolnay2ae520a2017-12-29 11:19:50 -05001890 impl ToTokens for TraitItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001891 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001892 self.tts.to_tokens(tokens);
1893 }
1894 }
1895
David Tolnay857628c2017-11-11 12:25:31 -08001896 impl ToTokens for ImplItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001897 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay4c9be372016-10-06 00:47:37 -07001898 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08001899 self.vis.to_tokens(tokens);
1900 self.defaultness.to_tokens(tokens);
1901 self.const_token.to_tokens(tokens);
1902 self.ident.to_tokens(tokens);
1903 self.colon_token.to_tokens(tokens);
1904 self.ty.to_tokens(tokens);
1905 self.eq_token.to_tokens(tokens);
1906 self.expr.to_tokens(tokens);
1907 self.semi_token.to_tokens(tokens);
1908 }
1909 }
1910
1911 impl ToTokens for ImplItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001912 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08001913 tokens.append_all(self.attrs.outer());
1914 self.vis.to_tokens(tokens);
1915 self.defaultness.to_tokens(tokens);
1916 self.sig.to_tokens(tokens);
1917 self.block.brace_token.surround(tokens, |tokens| {
1918 tokens.append_all(self.attrs.inner());
1919 tokens.append_all(&self.block.stmts);
1920 });
1921 }
1922 }
1923
1924 impl ToTokens for ImplItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001925 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08001926 tokens.append_all(self.attrs.outer());
1927 self.vis.to_tokens(tokens);
1928 self.defaultness.to_tokens(tokens);
1929 self.type_token.to_tokens(tokens);
1930 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001931 self.generics.to_tokens(tokens);
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001932 self.generics.where_clause.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08001933 self.eq_token.to_tokens(tokens);
1934 self.ty.to_tokens(tokens);
1935 self.semi_token.to_tokens(tokens);
1936 }
1937 }
1938
1939 impl ToTokens for ImplItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001940 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08001941 tokens.append_all(self.attrs.outer());
1942 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001943 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07001944 }
1945 }
1946
David Tolnay2ae520a2017-12-29 11:19:50 -05001947 impl ToTokens for ImplItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001948 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001949 self.tts.to_tokens(tokens);
1950 }
1951 }
1952
David Tolnay8894f602017-11-11 12:11:04 -08001953 impl ToTokens for ForeignItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001954 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay35902302016-10-06 01:11:08 -07001955 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001956 self.vis.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07001957 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001958 self.semi_token.to_tokens(tokens);
1959 }
1960 }
1961
1962 impl ToTokens for ForeignItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001963 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay8894f602017-11-11 12:11:04 -08001964 tokens.append_all(self.attrs.outer());
1965 self.vis.to_tokens(tokens);
1966 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001967 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001968 self.ident.to_tokens(tokens);
1969 self.colon_token.to_tokens(tokens);
1970 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001971 self.semi_token.to_tokens(tokens);
1972 }
1973 }
1974
David Tolnay199bcbb2017-11-12 10:33:52 -08001975 impl ToTokens for ForeignItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001976 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay199bcbb2017-11-12 10:33:52 -08001977 tokens.append_all(self.attrs.outer());
1978 self.vis.to_tokens(tokens);
1979 self.type_token.to_tokens(tokens);
1980 self.ident.to_tokens(tokens);
1981 self.semi_token.to_tokens(tokens);
1982 }
1983 }
1984
David Tolnay2ae520a2017-12-29 11:19:50 -05001985 impl ToTokens for ForeignItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001986 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001987 self.tts.to_tokens(tokens);
1988 }
1989 }
1990
David Tolnay570695e2017-06-03 16:15:13 -07001991 impl ToTokens for MethodSig {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001992 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay570695e2017-06-03 16:15:13 -07001993 self.constness.to_tokens(tokens);
1994 self.unsafety.to_tokens(tokens);
1995 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07001996 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001997 }
1998 }
1999
Alex Crichtona74a1c82018-05-16 10:20:44 -07002000 struct NamedDecl<'a>(&'a FnDecl, &'a Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002001
2002 impl<'a> ToTokens for NamedDecl<'a> {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002003 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002004 self.0.fn_token.to_tokens(tokens);
2005 self.1.to_tokens(tokens);
2006 self.0.generics.to_tokens(tokens);
2007 self.0.paren_token.surround(tokens, |tokens| {
2008 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05002009 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
2010 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04002011 }
David Tolnayd2836e22017-12-27 23:13:00 -05002012 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002013 });
2014 self.0.output.to_tokens(tokens);
2015 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07002016 }
2017 }
2018
Alex Crichton62a0a592017-05-22 13:58:53 -07002019 impl ToTokens for ArgSelfRef {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002020 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002021 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002022 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002023 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002024 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002025 }
2026 }
2027
2028 impl ToTokens for ArgSelf {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002029 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay24237fb2017-12-29 02:15:26 -05002030 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002031 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002032 }
2033 }
2034
2035 impl ToTokens for ArgCaptured {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002036 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichton62a0a592017-05-22 13:58:53 -07002037 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002038 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002039 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07002040 }
2041 }
David Tolnay4a51dc72016-10-01 00:40:31 -07002042}