blob: c7e672621d857055c4ce36ffec0f1668afaa45fb [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]>,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +090096 pub asyncness: Option<Token![async]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070097 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -070098 pub ident: Ident,
David Tolnay4a3f59a2017-12-28 21:21:12 -050099 pub decl: Box<FnDecl>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700100 pub block: Box<Block>,
101 }),
David Tolnay2b214082018-01-07 01:30:18 -0800102
103 /// A module or module declaration: `mod m` or `mod m { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800104 ///
105 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700106 pub Mod(ItemMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800107 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700108 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800109 pub mod_token: Token![mod],
David Tolnay570695e2017-06-03 16:15:13 -0700110 pub ident: Ident,
David Tolnay32954ef2017-12-26 22:43:16 -0500111 pub content: Option<(token::Brace, Vec<Item>)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800112 pub semi: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700113 }),
David Tolnay2b214082018-01-07 01:30:18 -0800114
115 /// A block of foreign items: `extern "C" { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800116 ///
117 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700118 pub ForeignMod(ItemForeignMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800119 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700120 pub abi: Abi,
David Tolnay32954ef2017-12-26 22:43:16 -0500121 pub brace_token: token::Brace,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700122 pub items: Vec<ForeignItem>,
123 }),
David Tolnay2b214082018-01-07 01:30:18 -0800124
125 /// A type alias: `type Result<T> = std::result::Result<T, MyError>`.
David Tolnay461d98e2018-01-07 11:07:19 -0800126 ///
127 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800128 pub Type(ItemType {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800129 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700130 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800131 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700132 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700133 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800134 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800135 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800136 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700137 }),
David Tolnay2b214082018-01-07 01:30:18 -0800138
David Tolnaybb82ef02018-08-24 20:15:45 -0400139 /// An existential type: `existential type Iter: Iterator<Item = u8>`.
140 ///
141 /// *This type is available if Syn is built with the `"full"` feature.*
142 pub Existential(ItemExistential {
143 pub attrs: Vec<Attribute>,
144 pub vis: Visibility,
145 pub existential_token: Token![existential],
146 pub type_token: Token![type],
147 pub ident: Ident,
148 pub generics: Generics,
149 pub colon_token: Option<Token![:]>,
150 pub bounds: Punctuated<TypeParamBound, Token![+]>,
151 pub semi_token: Token![;],
152 }),
153
David Tolnay2b214082018-01-07 01:30:18 -0800154 /// A struct definition: `struct Foo<A> { x: A }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800155 ///
156 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaye3d41b72017-12-31 15:24:00 -0500157 pub Struct(ItemStruct {
158 pub attrs: Vec<Attribute>,
159 pub vis: Visibility,
160 pub struct_token: Token![struct],
161 pub ident: Ident,
162 pub generics: Generics,
163 pub fields: Fields,
164 pub semi_token: Option<Token![;]>,
165 }),
David Tolnay2b214082018-01-07 01:30:18 -0800166
167 /// An enum definition: `enum Foo<A, B> { C<A>, D<B> }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800168 ///
169 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700170 pub Enum(ItemEnum {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800171 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700172 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800173 pub enum_token: Token![enum],
David Tolnay570695e2017-06-03 16:15:13 -0700174 pub ident: Ident,
175 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500176 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500177 pub variants: Punctuated<Variant, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700178 }),
David Tolnay2b214082018-01-07 01:30:18 -0800179
180 /// A union definition: `union Foo<A, B> { x: A, y: B }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800181 ///
182 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700183 pub Union(ItemUnion {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800184 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700185 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800186 pub union_token: Token![union],
David Tolnay570695e2017-06-03 16:15:13 -0700187 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700188 pub generics: Generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500189 pub fields: FieldsNamed,
Alex Crichton62a0a592017-05-22 13:58:53 -0700190 }),
David Tolnay2b214082018-01-07 01:30:18 -0800191
192 /// A trait definition: `pub trait Iterator { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800193 ///
194 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700195 pub Trait(ItemTrait {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800196 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700197 pub vis: Visibility,
David Tolnay9b258702017-12-29 02:24:41 -0500198 pub unsafety: Option<Token![unsafe]>,
Nika Layzell0dc6e632017-11-18 12:55:25 -0500199 pub auto_token: Option<Token![auto]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800200 pub trait_token: Token![trait],
David Tolnay570695e2017-06-03 16:15:13 -0700201 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700202 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800203 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500204 pub supertraits: Punctuated<TypeParamBound, Token![+]>,
David Tolnay32954ef2017-12-26 22:43:16 -0500205 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700206 pub items: Vec<TraitItem>,
207 }),
David Tolnay2b214082018-01-07 01:30:18 -0800208
209 /// An impl block providing trait or associated items: `impl<A> Trait
210 /// for Data<A> { ... }`.
David Tolnay461d98e2018-01-07 11:07:19 -0800211 ///
212 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700213 pub Impl(ItemImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800214 pub attrs: Vec<Attribute>,
David Tolnay360a6342017-12-29 02:22:11 -0500215 pub defaultness: Option<Token![default]>,
David Tolnay9b258702017-12-29 02:24:41 -0500216 pub unsafety: Option<Token![unsafe]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800217 pub impl_token: Token![impl],
Alex Crichton62a0a592017-05-22 13:58:53 -0700218 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700219 /// Trait this impl implements.
David Tolnay360a6342017-12-29 02:22:11 -0500220 pub trait_: Option<(Option<Token![!]>, Path, Token![for])>,
David Tolnay570695e2017-06-03 16:15:13 -0700221 /// The Self type of the impl.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800222 pub self_ty: Box<Type>,
David Tolnay32954ef2017-12-26 22:43:16 -0500223 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700224 pub items: Vec<ImplItem>,
225 }),
David Tolnay2b214082018-01-07 01:30:18 -0800226
227 /// A macro invocation, which includes `macro_rules!` definitions.
David Tolnay461d98e2018-01-07 11:07:19 -0800228 ///
229 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800230 pub Macro(ItemMacro {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800231 pub attrs: Vec<Attribute>,
David Tolnay99a953d2017-11-11 12:51:43 -0800232 /// The `example` in `macro_rules! example { ... }`.
233 pub ident: Option<Ident>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800234 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500235 pub semi_token: Option<Token![;]>,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800236 }),
David Tolnay2b214082018-01-07 01:30:18 -0800237
238 /// A 2.0-style declarative macro introduced by the `macro` keyword.
David Tolnay461d98e2018-01-07 11:07:19 -0800239 ///
240 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay9c76bcb2017-12-26 23:14:59 -0500241 pub Macro2(ItemMacro2 #manual_extra_traits {
David Tolnay500d8322017-12-18 00:32:51 -0800242 pub attrs: Vec<Attribute>,
243 pub vis: Visibility,
244 pub macro_token: Token![macro],
245 pub ident: Ident,
David Tolnayab919512017-12-30 23:31:51 -0500246 pub paren_token: Paren,
247 pub args: TokenStream,
248 pub brace_token: Brace,
249 pub body: TokenStream,
David Tolnay500d8322017-12-18 00:32:51 -0800250 }),
David Tolnay2b214082018-01-07 01:30:18 -0800251
252 /// Tokens forming an item not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800253 ///
254 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500255 pub Verbatim(ItemVerbatim #manual_extra_traits {
256 pub tts: TokenStream,
257 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700258 }
David Tolnayb79ee962016-09-04 09:39:20 -0700259}
260
David Tolnay9c76bcb2017-12-26 23:14:59 -0500261#[cfg(feature = "extra-traits")]
262impl Eq for ItemMacro2 {}
263
264#[cfg(feature = "extra-traits")]
265impl PartialEq for ItemMacro2 {
266 fn eq(&self, other: &Self) -> bool {
David Tolnay65fb5662018-05-20 20:02:28 -0700267 self.attrs == other.attrs
268 && self.vis == other.vis
269 && self.macro_token == other.macro_token
270 && self.ident == other.ident
271 && self.paren_token == other.paren_token
David Tolnayab919512017-12-30 23:31:51 -0500272 && TokenStreamHelper(&self.args) == TokenStreamHelper(&other.args)
273 && self.brace_token == other.brace_token
274 && TokenStreamHelper(&self.body) == TokenStreamHelper(&other.body)
David Tolnay9c76bcb2017-12-26 23:14:59 -0500275 }
276}
277
278#[cfg(feature = "extra-traits")]
279impl Hash for ItemMacro2 {
280 fn hash<H>(&self, state: &mut H)
David Tolnay51382052017-12-27 13:46:21 -0500281 where
282 H: Hasher,
David Tolnay9c76bcb2017-12-26 23:14:59 -0500283 {
284 self.attrs.hash(state);
285 self.vis.hash(state);
286 self.macro_token.hash(state);
287 self.ident.hash(state);
David Tolnayab919512017-12-30 23:31:51 -0500288 self.paren_token.hash(state);
289 TokenStreamHelper(&self.args).hash(state);
290 self.brace_token.hash(state);
291 TokenStreamHelper(&self.body).hash(state);
David Tolnay9c76bcb2017-12-26 23:14:59 -0500292 }
293}
294
David Tolnay2ae520a2017-12-29 11:19:50 -0500295#[cfg(feature = "extra-traits")]
296impl Eq for ItemVerbatim {}
297
298#[cfg(feature = "extra-traits")]
299impl PartialEq for ItemVerbatim {
300 fn eq(&self, other: &Self) -> bool {
301 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
302 }
303}
304
305#[cfg(feature = "extra-traits")]
306impl Hash for ItemVerbatim {
307 fn hash<H>(&self, state: &mut H)
308 where
309 H: Hasher,
310 {
311 TokenStreamHelper(&self.tts).hash(state);
312 }
313}
314
David Tolnay0e837402016-12-22 17:25:55 -0500315impl From<DeriveInput> for Item {
316 fn from(input: DeriveInput) -> Item {
David Tolnaye3d41b72017-12-31 15:24:00 -0500317 match input.data {
318 Data::Struct(data) => Item::Struct(ItemStruct {
319 attrs: input.attrs,
320 vis: input.vis,
321 struct_token: data.struct_token,
322 ident: input.ident,
323 generics: input.generics,
324 fields: data.fields,
325 semi_token: data.semi_token,
326 }),
327 Data::Enum(data) => Item::Enum(ItemEnum {
David Tolnay51382052017-12-27 13:46:21 -0500328 attrs: input.attrs,
329 vis: input.vis,
330 enum_token: data.enum_token,
331 ident: input.ident,
332 generics: input.generics,
333 brace_token: data.brace_token,
334 variants: data.variants,
335 }),
David Tolnaye3d41b72017-12-31 15:24:00 -0500336 Data::Union(data) => Item::Union(ItemUnion {
David Tolnay51382052017-12-27 13:46:21 -0500337 attrs: input.attrs,
338 vis: input.vis,
David Tolnaye3d41b72017-12-31 15:24:00 -0500339 union_token: data.union_token,
David Tolnay51382052017-12-27 13:46:21 -0500340 ident: input.ident,
341 generics: input.generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500342 fields: data.fields,
David Tolnay51382052017-12-27 13:46:21 -0500343 }),
David Tolnay453cfd12016-10-23 11:00:14 -0700344 }
345 }
346}
347
Alex Crichton62a0a592017-05-22 13:58:53 -0700348ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800349 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
David Tolnay614a0142018-01-07 10:25:43 -0800350 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800351 /// *This type is available if Syn is built with the `"full"` feature.*
352 ///
David Tolnay614a0142018-01-07 10:25:43 -0800353 /// # Syntax tree enum
354 ///
355 /// This type is a [syntax tree enum].
356 ///
357 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay5f332a92017-12-26 00:42:45 -0500358 pub enum UseTree {
David Tolnayd97a7d22018-03-31 19:17:01 +0200359 /// A path prefix of imports in a `use` item: `std::...`.
David Tolnay461d98e2018-01-07 11:07:19 -0800360 ///
361 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500362 pub Path(UsePath {
363 pub ident: Ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200364 pub colon2_token: Token![::],
365 pub tree: Box<UseTree>,
366 }),
367
368 /// An identifier imported by a `use` item: `HashMap`.
369 ///
370 /// *This type is available if Syn is built with the `"full"` feature.*
371 pub Name(UseName {
372 pub ident: Ident,
373 }),
374
375 /// An renamed identifier imported by a `use` item: `HashMap as Map`.
376 ///
377 /// *This type is available if Syn is built with the `"full"` feature.*
378 pub Rename(UseRename {
379 pub ident: Ident,
380 pub as_token: Token![as],
381 pub rename: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700382 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800383
David Tolnay05658502018-01-07 09:56:37 -0800384 /// A glob import in a `use` item: `*`.
David Tolnay461d98e2018-01-07 11:07:19 -0800385 ///
386 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay5f332a92017-12-26 00:42:45 -0500387 pub Glob(UseGlob {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800388 pub star_token: Token![*],
Alex Crichton62a0a592017-05-22 13:58:53 -0700389 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800390
David Tolnayd97a7d22018-03-31 19:17:01 +0200391 /// A braced group of imports in a `use` item: `{A, B, C}`.
David Tolnay461d98e2018-01-07 11:07:19 -0800392 ///
393 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayd97a7d22018-03-31 19:17:01 +0200394 pub Group(UseGroup {
David Tolnay32954ef2017-12-26 22:43:16 -0500395 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500396 pub items: Punctuated<UseTree, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700397 }),
398 }
399}
400
Alex Crichton62a0a592017-05-22 13:58:53 -0700401ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800402 /// An item within an `extern` block.
David Tolnay614a0142018-01-07 10:25:43 -0800403 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800404 /// *This type is available if Syn is built with the `"full"` feature.*
405 ///
David Tolnay614a0142018-01-07 10:25:43 -0800406 /// # Syntax tree enum
407 ///
408 /// This type is a [syntax tree enum].
409 ///
410 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay8894f602017-11-11 12:11:04 -0800411 pub enum ForeignItem {
David Tolnayebb72722018-01-07 01:14:13 -0800412 /// A foreign function in an `extern` block.
David Tolnay461d98e2018-01-07 11:07:19 -0800413 ///
414 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700415 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800416 pub attrs: Vec<Attribute>,
417 pub vis: Visibility,
418 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700419 pub decl: Box<FnDecl>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800420 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700421 }),
David Tolnayebb72722018-01-07 01:14:13 -0800422
423 /// A foreign static item in an `extern` block: `static ext: u8`.
David Tolnay461d98e2018-01-07 11:07:19 -0800424 ///
425 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700426 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800427 pub attrs: Vec<Attribute>,
428 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800429 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -0500430 pub mutability: Option<Token![mut]>,
David Tolnay8894f602017-11-11 12:11:04 -0800431 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800432 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800433 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800434 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700435 }),
David Tolnayebb72722018-01-07 01:14:13 -0800436
437 /// A foreign type in an `extern` block: `type void`.
David Tolnay461d98e2018-01-07 11:07:19 -0800438 ///
439 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay199bcbb2017-11-12 10:33:52 -0800440 pub Type(ForeignItemType {
441 pub attrs: Vec<Attribute>,
442 pub vis: Visibility,
443 pub type_token: Token![type],
444 pub ident: Ident,
445 pub semi_token: Token![;],
446 }),
David Tolnayebb72722018-01-07 01:14:13 -0800447
David Tolnay435c1782018-08-24 16:15:44 -0400448 /// A macro invocation within an extern block.
449 ///
450 /// *This type is available if Syn is built with the `"full"` feature.*
451 pub Macro(ForeignItemMacro {
452 pub attrs: Vec<Attribute>,
453 pub mac: Macro,
454 pub semi_token: Option<Token![;]>,
455 }),
456
David Tolnayebb72722018-01-07 01:14:13 -0800457 /// Tokens in an `extern` block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800458 ///
459 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500460 pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
461 pub tts: TokenStream,
462 }),
463 }
464}
465
466#[cfg(feature = "extra-traits")]
467impl Eq for ForeignItemVerbatim {}
468
469#[cfg(feature = "extra-traits")]
470impl PartialEq for ForeignItemVerbatim {
471 fn eq(&self, other: &Self) -> bool {
472 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
473 }
474}
475
476#[cfg(feature = "extra-traits")]
477impl Hash for ForeignItemVerbatim {
478 fn hash<H>(&self, state: &mut H)
479 where
480 H: Hasher,
481 {
482 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700483 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700484}
485
David Tolnayda705bd2017-11-10 21:58:05 -0800486ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800487 /// An item declaration within the definition of a trait.
David Tolnay614a0142018-01-07 10:25:43 -0800488 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800489 /// *This type is available if Syn is built with the `"full"` feature.*
490 ///
David Tolnay614a0142018-01-07 10:25:43 -0800491 /// # Syntax tree enum
492 ///
493 /// This type is a [syntax tree enum].
494 ///
495 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayda705bd2017-11-10 21:58:05 -0800496 pub enum TraitItem {
David Tolnayebb72722018-01-07 01:14:13 -0800497 /// An associated constant within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800498 ///
499 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700500 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800501 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800502 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700503 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800504 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800505 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800506 pub default: Option<(Token![=], Expr)>,
507 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700508 }),
David Tolnayebb72722018-01-07 01:14:13 -0800509
510 /// A trait method within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800511 ///
512 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700513 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800514 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700515 pub sig: MethodSig,
516 pub default: Option<Block>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800517 pub semi_token: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700518 }),
David Tolnayebb72722018-01-07 01:14:13 -0800519
520 /// An associated type within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800521 ///
522 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700523 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800524 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800525 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700526 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500527 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800528 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500529 pub bounds: Punctuated<TypeParamBound, Token![+]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800530 pub default: Option<(Token![=], Type)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800531 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700532 }),
David Tolnayebb72722018-01-07 01:14:13 -0800533
David Tolnaybb82ef02018-08-24 20:15:45 -0400534 /// An existential type within the definition of a trait.
535 ///
536 /// *This type is available if Syn is built with the `"full"` feature.*
537 pub Existential(TraitItemExistential {
538 pub attrs: Vec<Attribute>,
539 pub existential_token: Token![existential],
540 pub type_token: Token![type],
541 pub ident: Ident,
542 pub generics: Generics,
543 pub colon_token: Option<Token![:]>,
544 pub bounds: Punctuated<TypeParamBound, Token![+]>,
545 pub semi_token: Token![;],
546 }),
547
David Tolnayebb72722018-01-07 01:14:13 -0800548 /// A macro invocation within the definition of a trait.
David Tolnay461d98e2018-01-07 11:07:19 -0800549 ///
550 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnaydecf28d2017-11-11 11:56:45 -0800551 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800552 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800553 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500554 pub semi_token: Option<Token![;]>,
David Tolnayda705bd2017-11-10 21:58:05 -0800555 }),
David Tolnayebb72722018-01-07 01:14:13 -0800556
557 /// Tokens within the definition of a trait not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800558 ///
559 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500560 pub Verbatim(TraitItemVerbatim #manual_extra_traits {
561 pub tts: TokenStream,
562 }),
563 }
564}
565
566#[cfg(feature = "extra-traits")]
567impl Eq for TraitItemVerbatim {}
568
569#[cfg(feature = "extra-traits")]
570impl PartialEq for TraitItemVerbatim {
571 fn eq(&self, other: &Self) -> bool {
572 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
573 }
574}
575
576#[cfg(feature = "extra-traits")]
577impl Hash for TraitItemVerbatim {
578 fn hash<H>(&self, state: &mut H)
579 where
580 H: Hasher,
581 {
582 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700583 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700584}
585
Alex Crichton62a0a592017-05-22 13:58:53 -0700586ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800587 /// An item within an impl block.
David Tolnay614a0142018-01-07 10:25:43 -0800588 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800589 /// *This type is available if Syn is built with the `"full"` feature.*
590 ///
David Tolnay614a0142018-01-07 10:25:43 -0800591 /// # Syntax tree enum
592 ///
593 /// This type is a [syntax tree enum].
594 ///
595 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay857628c2017-11-11 12:25:31 -0800596 pub enum ImplItem {
David Tolnayebb72722018-01-07 01:14:13 -0800597 /// An associated constant within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800598 ///
599 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700600 pub Const(ImplItemConst {
David Tolnay857628c2017-11-11 12:25:31 -0800601 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700602 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500603 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800604 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700605 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800606 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800607 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800608 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -0700609 pub expr: Expr,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800610 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700611 }),
David Tolnayebb72722018-01-07 01:14:13 -0800612
613 /// A method within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800614 ///
615 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700616 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800617 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700618 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500619 pub defaultness: Option<Token![default]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700620 pub sig: MethodSig,
621 pub block: Block,
622 }),
David Tolnayebb72722018-01-07 01:14:13 -0800623
624 /// An associated type within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800625 ///
626 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700627 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800628 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700629 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500630 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800631 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700632 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500633 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800634 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800635 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800636 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700637 }),
David Tolnayebb72722018-01-07 01:14:13 -0800638
David Tolnaybb82ef02018-08-24 20:15:45 -0400639 /// An existential type within an impl block.
640 ///
641 /// *This type is available if Syn is built with the `"full"` feature.*
642 pub Existential(ImplItemExistential {
643 pub attrs: Vec<Attribute>,
644 pub existential_token: Token![existential],
645 pub type_token: Token![type],
646 pub ident: Ident,
647 pub generics: Generics,
648 pub colon_token: Option<Token![:]>,
649 pub bounds: Punctuated<TypeParamBound, Token![+]>,
650 pub semi_token: Token![;],
651 }),
652
David Tolnayebb72722018-01-07 01:14:13 -0800653 /// A macro invocation within an impl block.
David Tolnay461d98e2018-01-07 11:07:19 -0800654 ///
655 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay857628c2017-11-11 12:25:31 -0800656 pub Macro(ImplItemMacro {
657 pub attrs: Vec<Attribute>,
658 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500659 pub semi_token: Option<Token![;]>,
David Tolnay857628c2017-11-11 12:25:31 -0800660 }),
David Tolnayebb72722018-01-07 01:14:13 -0800661
662 /// Tokens within an impl block not interpreted by Syn.
David Tolnay461d98e2018-01-07 11:07:19 -0800663 ///
664 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnay2ae520a2017-12-29 11:19:50 -0500665 pub Verbatim(ImplItemVerbatim #manual_extra_traits {
666 pub tts: TokenStream,
667 }),
668 }
669}
670
671#[cfg(feature = "extra-traits")]
672impl Eq for ImplItemVerbatim {}
673
674#[cfg(feature = "extra-traits")]
675impl PartialEq for ImplItemVerbatim {
676 fn eq(&self, other: &Self) -> bool {
677 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
678 }
679}
680
681#[cfg(feature = "extra-traits")]
682impl Hash for ImplItemVerbatim {
683 fn hash<H>(&self, state: &mut H)
684 where
685 H: Hasher,
686 {
687 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700688 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700689}
690
691ast_struct! {
David Tolnay05658502018-01-07 09:56:37 -0800692 /// A method's signature in a trait or implementation: `unsafe fn
693 /// initialize(&self)`.
David Tolnay461d98e2018-01-07 11:07:19 -0800694 ///
695 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700696 pub struct MethodSig {
David Tolnay360a6342017-12-29 02:22:11 -0500697 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -0500698 pub unsafety: Option<Token![unsafe]>,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +0900699 pub asyncness: Option<Token![async]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700700 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700701 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700702 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700703 }
704}
705
706ast_struct! {
David Tolnayebb72722018-01-07 01:14:13 -0800707 /// Header of a function declaration, without including the body.
David Tolnay461d98e2018-01-07 11:07:19 -0800708 ///
709 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700710 pub struct FnDecl {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800711 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500712 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500713 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -0500714 pub inputs: Punctuated<FnArg, Token![,]>,
David Tolnayd2836e22017-12-27 23:13:00 -0500715 pub variadic: Option<Token![...]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500716 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700717 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700718}
719
Alex Crichton62a0a592017-05-22 13:58:53 -0700720ast_enum_of_structs! {
David Tolnayc0435192018-01-07 11:46:08 -0800721 /// An argument in a function signature: the `n: usize` in `fn f(n: usize)`.
David Tolnay614a0142018-01-07 10:25:43 -0800722 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800723 /// *This type is available if Syn is built with the `"full"` feature.*
724 ///
David Tolnay614a0142018-01-07 10:25:43 -0800725 /// # Syntax tree enum
726 ///
727 /// This type is a [syntax tree enum].
728 ///
729 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700730 pub enum FnArg {
David Tolnay3f559052018-01-06 23:59:48 -0800731 /// Self captured by reference in a function signature: `&self` or `&mut
732 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800733 ///
734 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700735 pub SelfRef(ArgSelfRef {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800736 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -0700737 pub lifetime: Option<Lifetime>,
David Tolnay24237fb2017-12-29 02:15:26 -0500738 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500739 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700740 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800741
David Tolnay3f559052018-01-06 23:59:48 -0800742 /// Self captured by value in a function signature: `self` or `mut
743 /// self`.
David Tolnay461d98e2018-01-07 11:07:19 -0800744 ///
745 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700746 pub SelfValue(ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500747 pub mutability: Option<Token![mut]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800748 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700749 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800750
David Tolnay3f559052018-01-06 23:59:48 -0800751 /// An explicitly typed pattern captured by a function signature.
David Tolnay461d98e2018-01-07 11:07:19 -0800752 ///
753 /// *This type is available if Syn is built with the `"full"` feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700754 pub Captured(ArgCaptured {
755 pub pat: Pat,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800756 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800757 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700758 }),
David Tolnay461d98e2018-01-07 11:07:19 -0800759
David Tolnay3f559052018-01-06 23:59:48 -0800760 /// A pattern whose type is inferred captured by a function signature.
David Tolnay80ed55f2017-12-27 22:54:40 -0500761 pub Inferred(Pat),
David Tolnay3f559052018-01-06 23:59:48 -0800762 /// A type not bound to any pattern in a function signature.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800763 pub Ignored(Type),
Alex Crichton62a0a592017-05-22 13:58:53 -0700764 }
David Tolnay62f374c2016-10-02 13:37:00 -0700765}
766
David Tolnayedf2b992016-09-23 20:43:45 -0700767#[cfg(feature = "parsing")]
768pub mod parsing {
769 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700770
David Tolnay2ad62c12018-08-26 19:00:35 -0400771 use parse::{Parse, ParseStream, Result};
David Tolnay9be32582018-07-31 22:37:26 -0700772 use synom::Synom;
David Tolnay84aa0752016-10-02 23:01:13 -0700773
David Tolnay4c614be2017-11-10 00:02:38 -0800774 impl_synom!(Item "item" alt!(
775 syn!(ItemExternCrate) => { Item::ExternCrate }
776 |
777 syn!(ItemUse) => { Item::Use }
778 |
779 syn!(ItemStatic) => { Item::Static }
780 |
781 syn!(ItemConst) => { Item::Const }
782 |
783 syn!(ItemFn) => { Item::Fn }
784 |
785 syn!(ItemMod) => { Item::Mod }
786 |
787 syn!(ItemForeignMod) => { Item::ForeignMod }
788 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800789 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800790 |
David Tolnaybb82ef02018-08-24 20:15:45 -0400791 syn!(ItemExistential) => { Item::Existential }
David Tolnay758ee132018-08-21 21:29:40 -0400792 |
David Tolnay4c614be2017-11-10 00:02:38 -0800793 syn!(ItemStruct) => { Item::Struct }
794 |
795 syn!(ItemEnum) => { Item::Enum }
796 |
797 syn!(ItemUnion) => { Item::Union }
798 |
799 syn!(ItemTrait) => { Item::Trait }
800 |
David Tolnay4c614be2017-11-10 00:02:38 -0800801 syn!(ItemImpl) => { Item::Impl }
802 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800803 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800804 |
805 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800806 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700807
David Tolnaydecf28d2017-11-11 11:56:45 -0800808 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400809 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnaya7d69fc2018-08-26 13:30:24 -0400810 what: call!(Path::old_parse_mod_style) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800811 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700812 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500813 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500814 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800815 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700816 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800817 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800818 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500819 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700820 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500821 delimiter: body.0,
822 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800823 },
David Tolnay57292da2017-12-27 21:03:33 -0500824 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800825 })
David Tolnayedf2b992016-09-23 20:43:45 -0700826 ));
827
David Tolnay500d8322017-12-18 00:32:51 -0800828 // TODO: figure out the actual grammar; is body required to be braced?
829 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400830 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800831 vis: syn!(Visibility) >>
832 macro_: keyword!(macro) >>
833 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500834 args: call!(tt::parenthesized) >>
835 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800836 (ItemMacro2 {
837 attrs: attrs,
838 vis: vis,
839 macro_token: macro_,
840 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500841 paren_token: args.0,
842 args: args.1,
843 brace_token: body.0,
844 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800845 })
846 ));
847
David Tolnay4c614be2017-11-10 00:02:38 -0800848 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400849 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700850 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800851 extern_: keyword!(extern) >>
852 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700853 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800854 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
855 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800856 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700857 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800858 vis: vis,
859 extern_token: extern_,
860 crate_token: crate_,
861 ident: ident,
862 rename: rename,
863 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800864 })
David Tolnayedf2b992016-09-23 20:43:45 -0700865 ));
866
David Tolnay4c614be2017-11-10 00:02:38 -0800867 impl_synom!(ItemUse "use item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400868 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700869 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800870 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500871 leading_colon: option!(punct!(::)) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200872 tree: syn!(UseTree) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800873 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800874 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700875 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800876 vis: vis,
877 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500878 leading_colon: leading_colon,
David Tolnay5f332a92017-12-26 00:42:45 -0500879 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800880 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800881 })
David Tolnay4a057422016-10-08 00:02:31 -0700882 ));
883
David Tolnayd97a7d22018-03-31 19:17:01 +0200884 named!(use_element -> Ident, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500885 syn!(Ident)
886 |
887 keyword!(self) => { Into::into }
888 |
889 keyword!(super) => { Into::into }
890 |
891 keyword!(crate) => { Into::into }
David Tolnay0a4d4e92018-07-21 15:31:45 -0700892 |
893 keyword!(extern) => { Into::into }
David Tolnay5f332a92017-12-26 00:42:45 -0500894 ));
895
896 impl_synom!(UseTree "use tree" alt!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200897 syn!(UseRename) => { UseTree::Rename }
898 |
David Tolnay5f332a92017-12-26 00:42:45 -0500899 syn!(UsePath) => { UseTree::Path }
900 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200901 syn!(UseName) => { UseTree::Name }
902 |
David Tolnay5f332a92017-12-26 00:42:45 -0500903 syn!(UseGlob) => { UseTree::Glob }
904 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200905 syn!(UseGroup) => { UseTree::Group }
David Tolnay5f332a92017-12-26 00:42:45 -0500906 ));
907
908 impl_synom!(UsePath "use path" do_parse!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200909 ident: call!(use_element) >>
910 colon2_token: punct!(::) >>
911 tree: syn!(UseTree) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500912 (UsePath {
913 ident: ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200914 colon2_token: colon2_token,
915 tree: Box::new(tree),
916 })
917 ));
918
919 impl_synom!(UseName "use name" do_parse!(
920 ident: call!(use_element) >>
921 (UseName {
922 ident: ident,
923 })
924 ));
925
926 impl_synom!(UseRename "use rename" do_parse!(
927 ident: call!(use_element) >>
928 as_token: keyword!(as) >>
929 rename: syn!(Ident) >>
930 (UseRename {
931 ident: ident,
932 as_token: as_token,
David Tolnay5f332a92017-12-26 00:42:45 -0500933 rename: rename,
934 })
935 ));
David Tolnay4a057422016-10-08 00:02:31 -0700936
David Tolnay5f332a92017-12-26 00:42:45 -0500937 impl_synom!(UseGlob "use glob" do_parse!(
938 star: punct!(*) >>
939 (UseGlob {
940 star_token: star,
941 })
942 ));
David Tolnay4a057422016-10-08 00:02:31 -0700943
David Tolnayd97a7d22018-03-31 19:17:01 +0200944 impl_synom!(UseGroup "use group" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500945 list: braces!(Punctuated::parse_terminated) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200946 (UseGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500947 brace_token: list.0,
948 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500949 })
950 ));
David Tolnay4a057422016-10-08 00:02:31 -0700951
David Tolnay4c614be2017-11-10 00:02:38 -0800952 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400953 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700954 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800955 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500956 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700957 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800958 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800959 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800960 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700961 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800962 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800963 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700964 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800965 vis: vis,
966 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500967 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800968 ident: ident,
969 colon_token: colon,
970 ty: Box::new(ty),
971 eq_token: eq,
972 expr: Box::new(value),
973 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800974 })
David Tolnay47a877c2016-10-01 16:50:55 -0700975 ));
976
David Tolnay4c614be2017-11-10 00:02:38 -0800977 impl_synom!(ItemConst "const item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -0400978 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700979 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800980 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700981 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800982 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800983 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800984 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700985 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800986 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800987 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700988 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800989 vis: vis,
990 const_token: const_,
991 ident: ident,
992 colon_token: colon,
993 ty: Box::new(ty),
994 eq_token: eq,
995 expr: Box::new(value),
996 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800997 })
David Tolnay47a877c2016-10-01 16:50:55 -0700998 ));
999
David Tolnay4c614be2017-11-10 00:02:38 -08001000 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001001 outer_attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001002 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001003 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001004 unsafety: option!(keyword!(unsafe)) >>
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001005 asyncness: option!(keyword!(async)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001006 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001007 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001008 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001009 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001010 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001011 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001012 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001013 inner_attrs_stmts: braces!(tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001014 many0!(Attribute::old_parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001015 call!(Block::parse_within),
Michael Layzell416724e2017-05-24 21:12:34 -04001016 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001017 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -07001018 attrs: {
1019 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001020 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001021 attrs
1022 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001023 vis: vis,
1024 constness: constness,
1025 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001026 asyncness: asyncness,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001027 abi: abi,
1028 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -08001029 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001030 paren_token: inputs.0,
1031 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001032 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -05001033 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001034 generics: Generics {
1035 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001036 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001037 },
1038 }),
1039 ident: ident,
1040 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001041 brace_token: inner_attrs_stmts.0,
1042 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001043 }),
David Tolnay4c614be2017-11-10 00:02:38 -08001044 })
David Tolnay42602292016-10-01 22:25:45 -07001045 ));
1046
David Tolnay2ad62c12018-08-26 19:00:35 -04001047 impl Parse for FnArg {
1048 fn parse(input: ParseStream) -> Result<Self> {
1049 if input.peek(Token![&]) {
1050 let ahead = input.fork();
1051 if ahead.parse::<ArgSelfRef>().is_ok() && !ahead.peek(Token![:]) {
1052 return input.parse().map(FnArg::SelfRef);
1053 }
1054 }
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001055
David Tolnay2ad62c12018-08-26 19:00:35 -04001056 if input.peek(Token![mut]) || input.peek(Token![self]) {
1057 let ahead = input.fork();
1058 if ahead.parse::<ArgSelf>().is_ok() && !ahead.peek(Token![:]) {
1059 return input.parse().map(FnArg::SelfValue);
1060 }
1061 }
1062
1063 let ahead = input.fork();
1064 let err = match ahead.parse::<ArgCaptured>() {
1065 Ok(_) => return input.parse().map(FnArg::Captured),
1066 Err(err) => err,
1067 };
1068
1069 let ahead = input.fork();
1070 if ahead.parse::<Type>().is_ok() {
1071 return input.parse().map(FnArg::Ignored);
1072 }
1073
1074 Err(err)
1075 }
1076 }
1077
1078 impl Parse for ArgSelfRef {
1079 fn parse(input: ParseStream) -> Result<Self> {
1080 Ok(ArgSelfRef {
1081 and_token: input.parse()?,
1082 lifetime: input.parse()?,
1083 mutability: input.parse()?,
1084 self_token: input.parse()?,
1085 })
1086 }
1087 }
1088
1089 impl Parse for ArgSelf {
1090 fn parse(input: ParseStream) -> Result<Self> {
1091 Ok(ArgSelf {
1092 mutability: input.parse()?,
1093 self_token: input.parse()?,
1094 })
1095 }
1096 }
1097
1098 impl Parse for ArgCaptured {
1099 fn parse(input: ParseStream) -> Result<Self> {
1100 Ok(ArgCaptured {
1101 pat: input.parse_synom(Pat::parse)?,
1102 colon_token: input.parse()?,
1103 ty: input.parse()?,
1104 })
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001105 }
Alex Crichton954046c2017-05-30 21:49:42 -07001106 }
David Tolnay62f374c2016-10-02 13:37:00 -07001107
David Tolnay4c614be2017-11-10 00:02:38 -08001108 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001109 outer_attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001110 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001111 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -07001112 ident: syn!(Ident) >>
1113 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001114 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -07001115 Vec::new(),
1116 None,
1117 Some(semi),
1118 )}
David Tolnay37d10332016-10-13 20:51:04 -07001119 |
Alex Crichton954046c2017-05-30 21:49:42 -07001120 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -07001121 tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001122 many0!(Attribute::old_parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001123 many0!(Item::parse),
Michael Layzell416724e2017-05-24 21:12:34 -04001124 )
David Tolnay8875fca2017-12-31 13:52:37 -05001125 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -07001126 inner_attrs,
1127 Some((brace, items)),
1128 None,
1129 )}
David Tolnay37d10332016-10-13 20:51:04 -07001130 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001131 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -07001132 attrs: {
1133 let mut attrs = outer_attrs;
1134 attrs.extend(content_semi.0);
1135 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -07001136 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001137 vis: vis,
1138 mod_token: mod_,
1139 ident: ident,
1140 content: content_semi.1,
1141 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -08001142 })
David Tolnay35902302016-10-06 01:11:08 -07001143 ));
1144
David Tolnay4c614be2017-11-10 00:02:38 -08001145 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001146 outer_attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001147 abi: syn!(Abi) >>
David Tolnay5c4613a2018-07-21 15:40:17 -07001148 braced_content: braces!(tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001149 many0!(Attribute::old_parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001150 many0!(ForeignItem::parse),
David Tolnay5c4613a2018-07-21 15:40:17 -07001151 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001152 (ItemForeignMod {
David Tolnay5c4613a2018-07-21 15:40:17 -07001153 attrs: {
1154 let mut attrs = outer_attrs;
1155 attrs.extend((braced_content.1).0);
1156 attrs
1157 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001158 abi: abi,
David Tolnay5c4613a2018-07-21 15:40:17 -07001159 brace_token: braced_content.0,
1160 items: (braced_content.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001161 })
David Tolnay35902302016-10-06 01:11:08 -07001162 ));
1163
David Tolnay8894f602017-11-11 12:11:04 -08001164 impl_synom!(ForeignItem "foreign item" alt!(
1165 syn!(ForeignItemFn) => { ForeignItem::Fn }
1166 |
1167 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -08001168 |
1169 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay78572112018-08-01 00:36:18 -07001170 |
David Tolnay435c1782018-08-24 16:15:44 -04001171 syn!(ForeignItemMacro) => { ForeignItem::Macro }
David Tolnay8894f602017-11-11 12:11:04 -08001172 ));
David Tolnay35902302016-10-06 01:11:08 -07001173
David Tolnay8894f602017-11-11 12:11:04 -08001174 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001175 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001176 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001177 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001178 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001179 generics: syn!(Generics) >>
1180 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -05001181 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -05001182 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001183 (args, variadic)
1184 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001185 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001186 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001187 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001188 ({
David Tolnay8875fca2017-12-31 13:52:37 -05001189 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -08001190 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -07001191 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -07001192 attrs: attrs,
1193 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001194 decl: Box::new(FnDecl {
1195 fn_token: fn_,
1196 paren_token: parens,
1197 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001198 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001199 output: ret,
1200 generics: Generics {
1201 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001202 ..generics
David Tolnay8894f602017-11-11 12:11:04 -08001203 },
1204 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001205 vis: vis,
1206 }
David Tolnay35902302016-10-06 01:11:08 -07001207 })
1208 ));
1209
David Tolnay8894f602017-11-11 12:11:04 -08001210 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001211 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001212 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001213 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001214 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001215 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001216 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001217 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001218 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001219 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001220 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001221 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001222 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001223 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001224 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001225 static_token: static_,
1226 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001227 vis: vis,
1228 })
1229 ));
1230
David Tolnay199bcbb2017-11-12 10:33:52 -08001231 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001232 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001233 vis: syn!(Visibility) >>
1234 type_: keyword!(type) >>
1235 ident: syn!(Ident) >>
1236 semi: punct!(;) >>
1237 (ForeignItemType {
1238 attrs: attrs,
1239 vis: vis,
1240 type_token: type_,
1241 ident: ident,
1242 semi_token: semi,
1243 })
1244 ));
1245
David Tolnay435c1782018-08-24 16:15:44 -04001246 impl_synom!(ForeignItemMacro "macro in extern block" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001247 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnay78572112018-08-01 00:36:18 -07001248 mac: syn!(Macro) >>
David Tolnay435c1782018-08-24 16:15:44 -04001249 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
1250 (ForeignItemMacro {
1251 attrs: attrs,
1252 mac: mac,
1253 semi_token: semi,
David Tolnay78572112018-08-01 00:36:18 -07001254 })
1255 ));
1256
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001257 impl_synom!(ItemType "type item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001258 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001259 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001260 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001261 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001262 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001263 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001264 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001265 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001266 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001267 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001268 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001269 vis: vis,
1270 type_token: type_,
1271 ident: ident,
1272 generics: Generics {
1273 where_clause: where_clause,
1274 ..generics
1275 },
1276 eq_token: eq,
1277 ty: Box::new(ty),
1278 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001279 })
David Tolnay3cf52982016-10-01 17:11:37 -07001280 ));
1281
David Tolnaybb82ef02018-08-24 20:15:45 -04001282 named!(existential_type(vis: bool) -> ItemExistential, do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001283 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnaybb82ef02018-08-24 20:15:45 -04001284 vis: cond_reduce!(vis, syn!(Visibility)) >>
1285 existential_token: keyword!(existential) >>
1286 type_token: keyword!(type) >>
1287 ident: syn!(Ident) >>
1288 generics: syn!(Generics) >>
1289 where_clause: option!(syn!(WhereClause)) >>
David Tolnay758ee132018-08-21 21:29:40 -04001290 colon: option!(punct!(:)) >>
David Tolnaybb82ef02018-08-24 20:15:45 -04001291 bounds: cond!(
David Tolnay758ee132018-08-21 21:29:40 -04001292 colon.is_some(),
1293 Punctuated::<TypeParamBound, Token![+]>::parse_separated_nonempty
1294 ) >>
David Tolnaybb82ef02018-08-24 20:15:45 -04001295 semi: punct!(;) >>
1296 (ItemExistential {
1297 attrs: attrs,
1298 vis: vis,
1299 existential_token: existential_token,
1300 type_token: type_token,
1301 ident: ident,
1302 generics: Generics {
1303 where_clause: where_clause,
1304 ..generics
1305 },
1306 colon_token: colon,
1307 bounds: bounds.unwrap_or_else(Punctuated::new),
1308 semi_token: semi,
1309 })
David Tolnay758ee132018-08-21 21:29:40 -04001310 ));
1311
David Tolnaybb82ef02018-08-24 20:15:45 -04001312 impl_synom!(ItemExistential "existential type" call!(existential_type, true));
David Tolnay758ee132018-08-21 21:29:40 -04001313
David Tolnay4c614be2017-11-10 00:02:38 -08001314 impl_synom!(ItemStruct "struct item" switch!(
1315 map!(syn!(DeriveInput), Into::into),
1316 Item::Struct(item) => value!(item)
1317 |
1318 _ => reject!()
1319 ));
David Tolnay42602292016-10-01 22:25:45 -07001320
David Tolnay4c614be2017-11-10 00:02:38 -08001321 impl_synom!(ItemEnum "enum item" switch!(
1322 map!(syn!(DeriveInput), Into::into),
1323 Item::Enum(item) => value!(item)
1324 |
1325 _ => reject!()
1326 ));
1327
1328 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001329 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001330 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001331 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001332 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001333 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001334 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001335 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001336 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001337 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001338 vis: vis,
1339 union_token: union_,
1340 ident: ident,
1341 generics: Generics {
1342 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001343 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001344 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001345 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001346 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001347 ));
1348
David Tolnay4c614be2017-11-10 00:02:38 -08001349 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001350 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001351 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001352 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001353 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001354 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001355 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001356 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001357 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001358 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001359 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001360 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001361 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001362 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001363 vis: vis,
1364 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001365 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001366 trait_token: trait_,
1367 ident: ident,
1368 generics: Generics {
1369 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001370 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001371 },
1372 colon_token: colon,
1373 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001374 brace_token: body.0,
1375 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001376 })
David Tolnay0aecb732016-10-03 23:03:50 -07001377 ));
1378
David Tolnayda705bd2017-11-10 21:58:05 -08001379 impl_synom!(TraitItem "trait item" alt!(
1380 syn!(TraitItemConst) => { TraitItem::Const }
1381 |
1382 syn!(TraitItemMethod) => { TraitItem::Method }
1383 |
1384 syn!(TraitItemType) => { TraitItem::Type }
1385 |
David Tolnaybb82ef02018-08-24 20:15:45 -04001386 syn!(TraitItemExistential) => { TraitItem::Existential }
David Tolnay758ee132018-08-21 21:29:40 -04001387 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001388 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001389 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001390
David Tolnayda705bd2017-11-10 21:58:05 -08001391 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001392 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001393 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001394 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001395 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001396 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001397 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1398 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001399 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001400 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001401 const_token: const_,
1402 ident: ident,
1403 colon_token: colon,
1404 ty: ty,
1405 default: default,
1406 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001407 })
1408 ));
1409
David Tolnayda705bd2017-11-10 21:58:05 -08001410 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001411 outer_attrs: many0!(Attribute::old_parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001412 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001413 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001414 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001415 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001416 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001417 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001418 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001419 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001420 where_clause: option!(syn!(WhereClause)) >>
David Tolnay76178be2018-07-31 23:06:15 -07001421 body: option!(braces!(tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001422 many0!(Attribute::old_parse_inner),
David Tolnay76178be2018-07-31 23:06:15 -07001423 call!(Block::parse_within),
1424 ))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001425 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001426 ({
1427 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001428 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001429 None => (Vec::new(), None),
1430 };
David Tolnayda705bd2017-11-10 21:58:05 -08001431 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001432 attrs: {
1433 let mut attrs = outer_attrs;
1434 attrs.extend(inner_attrs);
1435 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001436 },
David Tolnayda705bd2017-11-10 21:58:05 -08001437 sig: MethodSig {
1438 constness: constness,
1439 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001440 asyncness: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001441 abi: abi,
1442 ident: ident,
1443 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001444 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001445 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001446 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001447 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001448 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001449 generics: Generics {
1450 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001451 ..generics
David Tolnay5859df12016-10-29 22:49:54 -07001452 },
1453 },
David Tolnayda705bd2017-11-10 21:58:05 -08001454 },
1455 default: stmts.map(|stmts| {
1456 Block {
1457 stmts: stmts.0,
1458 brace_token: stmts.1,
1459 }
1460 }),
1461 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001462 }
David Tolnay0aecb732016-10-03 23:03:50 -07001463 })
1464 ));
1465
David Tolnayda705bd2017-11-10 21:58:05 -08001466 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001467 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001468 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001469 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001470 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001471 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001472 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001473 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001474 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001475 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001476 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001477 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001478 type_token: type_,
1479 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001480 generics: Generics {
1481 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001482 ..generics
Nika Layzell0183ca32017-12-05 15:24:01 -05001483 },
David Tolnayda705bd2017-11-10 21:58:05 -08001484 colon_token: colon,
1485 bounds: bounds.unwrap_or_default(),
1486 default: default,
1487 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001488 })
1489 ));
1490
David Tolnaybb82ef02018-08-24 20:15:45 -04001491 impl_synom!(TraitItemExistential "trait item existential type" map!(
1492 call!(existential_type, false),
1493 |ety| TraitItemExistential {
1494 attrs: ety.attrs,
1495 existential_token: ety.existential_token,
1496 type_token: ety.type_token,
1497 ident: ety.ident,
1498 generics: ety.generics,
1499 colon_token: ety.colon_token,
1500 bounds: ety.bounds,
1501 semi_token: ety.semi_token,
1502 }
David Tolnay758ee132018-08-21 21:29:40 -04001503 ));
1504
David Tolnaydecf28d2017-11-11 11:56:45 -08001505 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001506 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001507 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001508 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001509 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001510 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001511 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001512 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001513 })
1514 ));
1515
David Tolnay4c614be2017-11-10 00:02:38 -08001516 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001517 outer_attrs: many0!(Attribute::old_parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001518 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001519 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001520 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001521 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001522 polarity_path: alt!(
1523 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001524 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001525 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001526 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001527 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001528 )
1529 |
David Tolnay570695e2017-06-03 16:15:13 -07001530 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001531 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001532 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001533 where_clause: option!(syn!(WhereClause)) >>
David Tolnaycf3697a2018-03-31 20:51:15 +02001534 inner: braces!(tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001535 many0!(Attribute::old_parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001536 many0!(ImplItem::parse),
David Tolnaycf3697a2018-03-31 20:51:15 +02001537 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001538 (ItemImpl {
David Tolnaycf3697a2018-03-31 20:51:15 +02001539 attrs: {
1540 let mut attrs = outer_attrs;
1541 attrs.extend((inner.1).0);
1542 attrs
1543 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001544 defaultness: defaultness,
1545 unsafety: unsafety,
1546 impl_token: impl_,
1547 generics: Generics {
1548 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001549 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001550 },
1551 trait_: polarity_path,
1552 self_ty: Box::new(self_ty),
David Tolnaycf3697a2018-03-31 20:51:15 +02001553 brace_token: inner.0,
1554 items: (inner.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001555 })
David Tolnay4c9be372016-10-06 00:47:37 -07001556 ));
1557
David Tolnay857628c2017-11-11 12:25:31 -08001558 impl_synom!(ImplItem "item in impl block" alt!(
1559 syn!(ImplItemConst) => { ImplItem::Const }
1560 |
1561 syn!(ImplItemMethod) => { ImplItem::Method }
1562 |
1563 syn!(ImplItemType) => { ImplItem::Type }
1564 |
David Tolnaybb82ef02018-08-24 20:15:45 -04001565 syn!(ImplItemExistential) => { ImplItem::Existential }
David Tolnay758ee132018-08-21 21:29:40 -04001566 |
David Tolnay857628c2017-11-11 12:25:31 -08001567 syn!(ImplItemMacro) => { ImplItem::Macro }
1568 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001569
David Tolnay857628c2017-11-11 12:25:31 -08001570 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001571 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001572 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001573 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001574 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001575 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001576 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001577 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001578 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001579 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001580 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001581 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001582 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001583 vis: vis,
1584 defaultness: defaultness,
1585 const_token: const_,
1586 ident: ident,
1587 colon_token: colon,
1588 ty: ty,
1589 eq_token: eq,
1590 expr: value,
1591 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001592 })
1593 ));
1594
David Tolnay857628c2017-11-11 12:25:31 -08001595 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001596 outer_attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001597 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001598 defaultness: option!(keyword!(default)) >>
1599 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001600 unsafety: option!(keyword!(unsafe)) >>
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001601 asyncness: option!(keyword!(async)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001602 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001603 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001604 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001605 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001606 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001607 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001608 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001609 inner_attrs_stmts: braces!(tuple!(
David Tolnayf8106f82018-08-25 21:17:45 -04001610 many0!(Attribute::old_parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001611 call!(Block::parse_within),
Michael Layzell416724e2017-05-24 21:12:34 -04001612 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001613 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001614 attrs: {
1615 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001616 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001617 attrs
1618 },
David Tolnay857628c2017-11-11 12:25:31 -08001619 vis: vis,
1620 defaultness: defaultness,
1621 sig: MethodSig {
1622 constness: constness,
1623 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001624 asyncness: asyncness,
David Tolnay857628c2017-11-11 12:25:31 -08001625 abi: abi,
1626 ident: ident,
1627 decl: FnDecl {
1628 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001629 paren_token: inputs.0,
1630 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001631 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001632 generics: Generics {
1633 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001634 ..generics
David Tolnay4c9be372016-10-06 00:47:37 -07001635 },
David Tolnayd2836e22017-12-27 23:13:00 -05001636 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001637 },
David Tolnay857628c2017-11-11 12:25:31 -08001638 },
1639 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001640 brace_token: inner_attrs_stmts.0,
1641 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001642 },
David Tolnay4c9be372016-10-06 00:47:37 -07001643 })
1644 ));
1645
David Tolnay857628c2017-11-11 12:25:31 -08001646 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001647 attrs: many0!(Attribute::old_parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001648 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001649 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001650 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001651 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001652 generics: syn!(Generics) >>
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001653 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001654 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001655 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001656 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001657 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001658 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001659 vis: vis,
1660 defaultness: defaultness,
1661 type_token: type_,
1662 ident: ident,
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001663 generics: Generics {
1664 where_clause: where_clause,
1665 ..generics
1666 },
David Tolnay857628c2017-11-11 12:25:31 -08001667 eq_token: eq,
1668 ty: ty,
1669 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001670 })
1671 ));
1672
David Tolnaybb82ef02018-08-24 20:15:45 -04001673 impl_synom!(ImplItemExistential "existential type in impl block" map!(
1674 call!(existential_type, true),
1675 |ety| ImplItemExistential {
1676 attrs: ety.attrs,
1677 existential_token: ety.existential_token,
1678 type_token: ety.type_token,
1679 ident: ety.ident,
1680 generics: ety.generics,
1681 colon_token: ety.colon_token,
1682 bounds: ety.bounds,
1683 semi_token: ety.semi_token,
1684 }
David Tolnay758ee132018-08-21 21:29:40 -04001685 ));
1686
David Tolnay857628c2017-11-11 12:25:31 -08001687 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnayf8106f82018-08-25 21:17:45 -04001688 attrs: many0!(Attribute::old_parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001689 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001690 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001691 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001692 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001693 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001694 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001695 })
1696 ));
1697
David Tolnayab919512017-12-30 23:31:51 -05001698 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1699 match *delimiter {
1700 MacroDelimiter::Brace(_) => true,
1701 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001702 }
1703 }
David Tolnayedf2b992016-09-23 20:43:45 -07001704}
David Tolnay4a51dc72016-10-01 00:40:31 -07001705
1706#[cfg(feature = "printing")]
1707mod printing {
1708 use super::*;
1709 use attr::FilterAttrs;
Alex Crichtona74a1c82018-05-16 10:20:44 -07001710 use proc_macro2::TokenStream;
David Tolnay65fb5662018-05-20 20:02:28 -07001711 use quote::{ToTokens, TokenStreamExt};
David Tolnay4a51dc72016-10-01 00:40:31 -07001712
David Tolnay1bfa7332017-11-11 12:41:20 -08001713 impl ToTokens for ItemExternCrate {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001714 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001715 tokens.append_all(self.attrs.outer());
1716 self.vis.to_tokens(tokens);
1717 self.extern_token.to_tokens(tokens);
1718 self.crate_token.to_tokens(tokens);
1719 self.ident.to_tokens(tokens);
1720 if let Some((ref as_token, ref rename)) = self.rename {
1721 as_token.to_tokens(tokens);
1722 rename.to_tokens(tokens);
1723 }
1724 self.semi_token.to_tokens(tokens);
1725 }
1726 }
1727
1728 impl ToTokens for ItemUse {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001729 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001730 tokens.append_all(self.attrs.outer());
1731 self.vis.to_tokens(tokens);
1732 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001733 self.leading_colon.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001734 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001735 self.semi_token.to_tokens(tokens);
1736 }
1737 }
1738
1739 impl ToTokens for ItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001740 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001741 tokens.append_all(self.attrs.outer());
1742 self.vis.to_tokens(tokens);
1743 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001744 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001745 self.ident.to_tokens(tokens);
1746 self.colon_token.to_tokens(tokens);
1747 self.ty.to_tokens(tokens);
1748 self.eq_token.to_tokens(tokens);
1749 self.expr.to_tokens(tokens);
1750 self.semi_token.to_tokens(tokens);
1751 }
1752 }
1753
1754 impl ToTokens for ItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001755 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001756 tokens.append_all(self.attrs.outer());
1757 self.vis.to_tokens(tokens);
1758 self.const_token.to_tokens(tokens);
1759 self.ident.to_tokens(tokens);
1760 self.colon_token.to_tokens(tokens);
1761 self.ty.to_tokens(tokens);
1762 self.eq_token.to_tokens(tokens);
1763 self.expr.to_tokens(tokens);
1764 self.semi_token.to_tokens(tokens);
1765 }
1766 }
1767
1768 impl ToTokens for ItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001769 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001770 tokens.append_all(self.attrs.outer());
1771 self.vis.to_tokens(tokens);
1772 self.constness.to_tokens(tokens);
1773 self.unsafety.to_tokens(tokens);
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001774 self.asyncness.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001775 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07001776 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001777 self.block.brace_token.surround(tokens, |tokens| {
1778 tokens.append_all(self.attrs.inner());
1779 tokens.append_all(&self.block.stmts);
1780 });
1781 }
1782 }
1783
1784 impl ToTokens for ItemMod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001785 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001786 tokens.append_all(self.attrs.outer());
1787 self.vis.to_tokens(tokens);
1788 self.mod_token.to_tokens(tokens);
1789 self.ident.to_tokens(tokens);
1790 if let Some((ref brace, ref items)) = self.content {
1791 brace.surround(tokens, |tokens| {
1792 tokens.append_all(self.attrs.inner());
1793 tokens.append_all(items);
1794 });
1795 } else {
1796 TokensOrDefault(&self.semi).to_tokens(tokens);
1797 }
1798 }
1799 }
1800
1801 impl ToTokens for ItemForeignMod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001802 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001803 tokens.append_all(self.attrs.outer());
1804 self.abi.to_tokens(tokens);
1805 self.brace_token.surround(tokens, |tokens| {
David Tolnay5c4613a2018-07-21 15:40:17 -07001806 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001807 tokens.append_all(&self.items);
1808 });
1809 }
1810 }
1811
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001812 impl ToTokens for ItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001813 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001814 tokens.append_all(self.attrs.outer());
1815 self.vis.to_tokens(tokens);
1816 self.type_token.to_tokens(tokens);
1817 self.ident.to_tokens(tokens);
1818 self.generics.to_tokens(tokens);
1819 self.generics.where_clause.to_tokens(tokens);
1820 self.eq_token.to_tokens(tokens);
1821 self.ty.to_tokens(tokens);
1822 self.semi_token.to_tokens(tokens);
1823 }
1824 }
1825
David Tolnaybb82ef02018-08-24 20:15:45 -04001826 impl ToTokens for ItemExistential {
1827 fn to_tokens(&self, tokens: &mut TokenStream) {
1828 tokens.append_all(self.attrs.outer());
1829 self.vis.to_tokens(tokens);
1830 self.existential_token.to_tokens(tokens);
1831 self.type_token.to_tokens(tokens);
1832 self.ident.to_tokens(tokens);
1833 self.generics.to_tokens(tokens);
1834 self.generics.where_clause.to_tokens(tokens);
1835 if !self.bounds.is_empty() {
1836 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1837 self.bounds.to_tokens(tokens);
1838 }
1839 self.semi_token.to_tokens(tokens);
1840 }
1841 }
1842
David Tolnay1bfa7332017-11-11 12:41:20 -08001843 impl ToTokens for ItemEnum {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001844 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001845 tokens.append_all(self.attrs.outer());
1846 self.vis.to_tokens(tokens);
1847 self.enum_token.to_tokens(tokens);
1848 self.ident.to_tokens(tokens);
1849 self.generics.to_tokens(tokens);
1850 self.generics.where_clause.to_tokens(tokens);
1851 self.brace_token.surround(tokens, |tokens| {
1852 self.variants.to_tokens(tokens);
1853 });
1854 }
1855 }
1856
1857 impl ToTokens for ItemStruct {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001858 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001859 tokens.append_all(self.attrs.outer());
1860 self.vis.to_tokens(tokens);
1861 self.struct_token.to_tokens(tokens);
1862 self.ident.to_tokens(tokens);
1863 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001864 match self.fields {
1865 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001866 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001867 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001868 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001869 Fields::Unnamed(ref fields) => {
1870 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001871 self.generics.where_clause.to_tokens(tokens);
1872 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001873 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001874 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001875 self.generics.where_clause.to_tokens(tokens);
1876 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001877 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001878 }
1879 }
1880 }
1881
1882 impl ToTokens for ItemUnion {
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.vis.to_tokens(tokens);
1886 self.union_token.to_tokens(tokens);
1887 self.ident.to_tokens(tokens);
1888 self.generics.to_tokens(tokens);
1889 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001890 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001891 }
1892 }
1893
1894 impl ToTokens for ItemTrait {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001895 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001896 tokens.append_all(self.attrs.outer());
1897 self.vis.to_tokens(tokens);
1898 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001899 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001900 self.trait_token.to_tokens(tokens);
1901 self.ident.to_tokens(tokens);
1902 self.generics.to_tokens(tokens);
1903 if !self.supertraits.is_empty() {
1904 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1905 self.supertraits.to_tokens(tokens);
1906 }
1907 self.generics.where_clause.to_tokens(tokens);
1908 self.brace_token.surround(tokens, |tokens| {
1909 tokens.append_all(&self.items);
1910 });
1911 }
1912 }
1913
David Tolnay1bfa7332017-11-11 12:41:20 -08001914 impl ToTokens for ItemImpl {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001915 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001916 tokens.append_all(self.attrs.outer());
1917 self.defaultness.to_tokens(tokens);
1918 self.unsafety.to_tokens(tokens);
1919 self.impl_token.to_tokens(tokens);
1920 self.generics.to_tokens(tokens);
1921 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1922 polarity.to_tokens(tokens);
1923 path.to_tokens(tokens);
1924 for_token.to_tokens(tokens);
1925 }
1926 self.self_ty.to_tokens(tokens);
1927 self.generics.where_clause.to_tokens(tokens);
1928 self.brace_token.surround(tokens, |tokens| {
David Tolnaycf3697a2018-03-31 20:51:15 +02001929 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001930 tokens.append_all(&self.items);
1931 });
1932 }
1933 }
1934
1935 impl ToTokens for ItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001936 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001937 tokens.append_all(self.attrs.outer());
1938 self.mac.path.to_tokens(tokens);
1939 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001940 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001941 match self.mac.delimiter {
1942 MacroDelimiter::Paren(ref paren) => {
1943 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1944 }
1945 MacroDelimiter::Brace(ref brace) => {
1946 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1947 }
1948 MacroDelimiter::Bracket(ref bracket) => {
1949 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1950 }
1951 }
David Tolnay57292da2017-12-27 21:03:33 -05001952 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001953 }
1954 }
David Tolnay42602292016-10-01 22:25:45 -07001955
David Tolnay500d8322017-12-18 00:32:51 -08001956 impl ToTokens for ItemMacro2 {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001957 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay500d8322017-12-18 00:32:51 -08001958 tokens.append_all(self.attrs.outer());
1959 self.vis.to_tokens(tokens);
1960 self.macro_token.to_tokens(tokens);
1961 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001962 self.paren_token.surround(tokens, |tokens| {
1963 self.args.to_tokens(tokens);
1964 });
1965 self.brace_token.surround(tokens, |tokens| {
1966 self.body.to_tokens(tokens);
1967 });
David Tolnay500d8322017-12-18 00:32:51 -08001968 }
1969 }
1970
David Tolnay2ae520a2017-12-29 11:19:50 -05001971 impl ToTokens for ItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001972 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001973 self.tts.to_tokens(tokens);
1974 }
1975 }
1976
David Tolnay5f332a92017-12-26 00:42:45 -05001977 impl ToTokens for UsePath {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001978 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay5f332a92017-12-26 00:42:45 -05001979 self.ident.to_tokens(tokens);
David Tolnayd97a7d22018-03-31 19:17:01 +02001980 self.colon2_token.to_tokens(tokens);
1981 self.tree.to_tokens(tokens);
1982 }
1983 }
1984
1985 impl ToTokens for UseName {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001986 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001987 self.ident.to_tokens(tokens);
1988 }
1989 }
1990
1991 impl ToTokens for UseRename {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001992 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001993 self.ident.to_tokens(tokens);
1994 self.as_token.to_tokens(tokens);
1995 self.rename.to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001996 }
1997 }
1998
David Tolnay5f332a92017-12-26 00:42:45 -05001999 impl ToTokens for UseGlob {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002000 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002001 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002002 }
2003 }
2004
David Tolnayd97a7d22018-03-31 19:17:01 +02002005 impl ToTokens for UseGroup {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002006 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002007 self.brace_token.surround(tokens, |tokens| {
2008 self.items.to_tokens(tokens);
2009 });
Alex Crichton62a0a592017-05-22 13:58:53 -07002010 }
2011 }
2012
David Tolnay1bfa7332017-11-11 12:41:20 -08002013 impl ToTokens for TraitItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002014 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002015 tokens.append_all(self.attrs.outer());
2016 self.const_token.to_tokens(tokens);
2017 self.ident.to_tokens(tokens);
2018 self.colon_token.to_tokens(tokens);
2019 self.ty.to_tokens(tokens);
2020 if let Some((ref eq_token, ref default)) = self.default {
2021 eq_token.to_tokens(tokens);
2022 default.to_tokens(tokens);
2023 }
2024 self.semi_token.to_tokens(tokens);
2025 }
2026 }
2027
2028 impl ToTokens for TraitItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002029 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002030 tokens.append_all(self.attrs.outer());
2031 self.sig.to_tokens(tokens);
2032 match self.default {
2033 Some(ref block) => {
2034 block.brace_token.surround(tokens, |tokens| {
2035 tokens.append_all(self.attrs.inner());
2036 tokens.append_all(&block.stmts);
2037 });
David Tolnayca085422016-10-04 00:12:38 -07002038 }
David Tolnay1bfa7332017-11-11 12:41:20 -08002039 None => {
2040 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07002041 }
David Tolnay1bfa7332017-11-11 12:41:20 -08002042 }
2043 }
2044 }
2045
2046 impl ToTokens for TraitItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002047 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002048 tokens.append_all(self.attrs.outer());
2049 self.type_token.to_tokens(tokens);
2050 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05002051 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08002052 if !self.bounds.is_empty() {
2053 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2054 self.bounds.to_tokens(tokens);
2055 }
Nika Layzell0183ca32017-12-05 15:24:01 -05002056 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08002057 if let Some((ref eq_token, ref default)) = self.default {
2058 eq_token.to_tokens(tokens);
2059 default.to_tokens(tokens);
2060 }
2061 self.semi_token.to_tokens(tokens);
2062 }
2063 }
2064
David Tolnaybb82ef02018-08-24 20:15:45 -04002065 impl ToTokens for TraitItemExistential {
2066 fn to_tokens(&self, tokens: &mut TokenStream) {
2067 tokens.append_all(self.attrs.outer());
2068 self.existential_token.to_tokens(tokens);
2069 self.type_token.to_tokens(tokens);
2070 self.ident.to_tokens(tokens);
2071 self.generics.to_tokens(tokens);
2072 self.generics.where_clause.to_tokens(tokens);
2073 if !self.bounds.is_empty() {
2074 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2075 self.bounds.to_tokens(tokens);
2076 }
2077 self.semi_token.to_tokens(tokens);
2078 }
2079 }
2080
David Tolnay1bfa7332017-11-11 12:41:20 -08002081 impl ToTokens for TraitItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002082 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002083 tokens.append_all(self.attrs.outer());
2084 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05002085 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07002086 }
2087 }
2088
David Tolnay2ae520a2017-12-29 11:19:50 -05002089 impl ToTokens for TraitItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002090 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002091 self.tts.to_tokens(tokens);
2092 }
2093 }
2094
David Tolnay857628c2017-11-11 12:25:31 -08002095 impl ToTokens for ImplItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002096 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay4c9be372016-10-06 00:47:37 -07002097 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08002098 self.vis.to_tokens(tokens);
2099 self.defaultness.to_tokens(tokens);
2100 self.const_token.to_tokens(tokens);
2101 self.ident.to_tokens(tokens);
2102 self.colon_token.to_tokens(tokens);
2103 self.ty.to_tokens(tokens);
2104 self.eq_token.to_tokens(tokens);
2105 self.expr.to_tokens(tokens);
2106 self.semi_token.to_tokens(tokens);
2107 }
2108 }
2109
2110 impl ToTokens for ImplItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002111 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002112 tokens.append_all(self.attrs.outer());
2113 self.vis.to_tokens(tokens);
2114 self.defaultness.to_tokens(tokens);
2115 self.sig.to_tokens(tokens);
2116 self.block.brace_token.surround(tokens, |tokens| {
2117 tokens.append_all(self.attrs.inner());
2118 tokens.append_all(&self.block.stmts);
2119 });
2120 }
2121 }
2122
2123 impl ToTokens for ImplItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002124 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002125 tokens.append_all(self.attrs.outer());
2126 self.vis.to_tokens(tokens);
2127 self.defaultness.to_tokens(tokens);
2128 self.type_token.to_tokens(tokens);
2129 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05002130 self.generics.to_tokens(tokens);
David Tolnaycaa2a6d2018-07-21 15:08:07 -07002131 self.generics.where_clause.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08002132 self.eq_token.to_tokens(tokens);
2133 self.ty.to_tokens(tokens);
2134 self.semi_token.to_tokens(tokens);
2135 }
2136 }
2137
David Tolnaybb82ef02018-08-24 20:15:45 -04002138 impl ToTokens for ImplItemExistential {
2139 fn to_tokens(&self, tokens: &mut TokenStream) {
2140 tokens.append_all(self.attrs.outer());
2141 self.existential_token.to_tokens(tokens);
2142 self.type_token.to_tokens(tokens);
2143 self.ident.to_tokens(tokens);
2144 self.generics.to_tokens(tokens);
2145 self.generics.where_clause.to_tokens(tokens);
2146 if !self.bounds.is_empty() {
2147 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2148 self.bounds.to_tokens(tokens);
2149 }
2150 self.semi_token.to_tokens(tokens);
2151 }
2152 }
2153
David Tolnay857628c2017-11-11 12:25:31 -08002154 impl ToTokens for ImplItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002155 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002156 tokens.append_all(self.attrs.outer());
2157 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05002158 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07002159 }
2160 }
2161
David Tolnay2ae520a2017-12-29 11:19:50 -05002162 impl ToTokens for ImplItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002163 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002164 self.tts.to_tokens(tokens);
2165 }
2166 }
2167
David Tolnay8894f602017-11-11 12:11:04 -08002168 impl ToTokens for ForeignItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002169 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay35902302016-10-06 01:11:08 -07002170 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002171 self.vis.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07002172 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08002173 self.semi_token.to_tokens(tokens);
2174 }
2175 }
2176
2177 impl ToTokens for ForeignItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002178 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay8894f602017-11-11 12:11:04 -08002179 tokens.append_all(self.attrs.outer());
2180 self.vis.to_tokens(tokens);
2181 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002182 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08002183 self.ident.to_tokens(tokens);
2184 self.colon_token.to_tokens(tokens);
2185 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002186 self.semi_token.to_tokens(tokens);
2187 }
2188 }
2189
David Tolnay199bcbb2017-11-12 10:33:52 -08002190 impl ToTokens for ForeignItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002191 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay199bcbb2017-11-12 10:33:52 -08002192 tokens.append_all(self.attrs.outer());
2193 self.vis.to_tokens(tokens);
2194 self.type_token.to_tokens(tokens);
2195 self.ident.to_tokens(tokens);
2196 self.semi_token.to_tokens(tokens);
2197 }
2198 }
2199
David Tolnay435c1782018-08-24 16:15:44 -04002200 impl ToTokens for ForeignItemMacro {
2201 fn to_tokens(&self, tokens: &mut TokenStream) {
2202 tokens.append_all(self.attrs.outer());
2203 self.mac.to_tokens(tokens);
2204 self.semi_token.to_tokens(tokens);
2205 }
2206 }
2207
David Tolnay2ae520a2017-12-29 11:19:50 -05002208 impl ToTokens for ForeignItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002209 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002210 self.tts.to_tokens(tokens);
2211 }
2212 }
2213
David Tolnay570695e2017-06-03 16:15:13 -07002214 impl ToTokens for MethodSig {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002215 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay570695e2017-06-03 16:15:13 -07002216 self.constness.to_tokens(tokens);
2217 self.unsafety.to_tokens(tokens);
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09002218 self.asyncness.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -07002219 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07002220 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002221 }
2222 }
2223
Alex Crichtona74a1c82018-05-16 10:20:44 -07002224 struct NamedDecl<'a>(&'a FnDecl, &'a Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002225
2226 impl<'a> ToTokens for NamedDecl<'a> {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002227 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002228 self.0.fn_token.to_tokens(tokens);
2229 self.1.to_tokens(tokens);
2230 self.0.generics.to_tokens(tokens);
2231 self.0.paren_token.surround(tokens, |tokens| {
2232 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05002233 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
2234 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04002235 }
David Tolnayd2836e22017-12-27 23:13:00 -05002236 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002237 });
2238 self.0.output.to_tokens(tokens);
2239 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07002240 }
2241 }
2242
Alex Crichton62a0a592017-05-22 13:58:53 -07002243 impl ToTokens for ArgSelfRef {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002244 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002245 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002246 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002247 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002248 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002249 }
2250 }
2251
2252 impl ToTokens for ArgSelf {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002253 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay24237fb2017-12-29 02:15:26 -05002254 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002255 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002256 }
2257 }
2258
2259 impl ToTokens for ArgCaptured {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002260 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichton62a0a592017-05-22 13:58:53 -07002261 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002262 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002263 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07002264 }
2265 }
David Tolnay4a51dc72016-10-01 00:40:31 -07002266}