blob: cb6184d4596edc201d567f6e5dfc70c03582662f [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 Tolnay9be32582018-07-31 22:37:26 -0700771 use synom::Synom;
David Tolnay84aa0752016-10-02 23:01:13 -0700772
David Tolnay4c614be2017-11-10 00:02:38 -0800773 impl_synom!(Item "item" alt!(
774 syn!(ItemExternCrate) => { Item::ExternCrate }
775 |
776 syn!(ItemUse) => { Item::Use }
777 |
778 syn!(ItemStatic) => { Item::Static }
779 |
780 syn!(ItemConst) => { Item::Const }
781 |
782 syn!(ItemFn) => { Item::Fn }
783 |
784 syn!(ItemMod) => { Item::Mod }
785 |
786 syn!(ItemForeignMod) => { Item::ForeignMod }
787 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800788 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800789 |
David Tolnaybb82ef02018-08-24 20:15:45 -0400790 syn!(ItemExistential) => { Item::Existential }
David Tolnay758ee132018-08-21 21:29:40 -0400791 |
David Tolnay4c614be2017-11-10 00:02:38 -0800792 syn!(ItemStruct) => { Item::Struct }
793 |
794 syn!(ItemEnum) => { Item::Enum }
795 |
796 syn!(ItemUnion) => { Item::Union }
797 |
798 syn!(ItemTrait) => { Item::Trait }
799 |
David Tolnay4c614be2017-11-10 00:02:38 -0800800 syn!(ItemImpl) => { Item::Impl }
801 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800802 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800803 |
804 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800805 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700806
David Tolnaydecf28d2017-11-11 11:56:45 -0800807 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500808 attrs: many0!(Attribute::parse_outer) >>
David Tolnayd69fc2b2018-01-23 09:39:14 -0800809 what: call!(Path::parse_mod_style) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800810 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700811 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500812 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500813 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800814 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700815 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800816 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800817 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500818 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700819 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500820 delimiter: body.0,
821 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800822 },
David Tolnay57292da2017-12-27 21:03:33 -0500823 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800824 })
David Tolnayedf2b992016-09-23 20:43:45 -0700825 ));
826
David Tolnay500d8322017-12-18 00:32:51 -0800827 // TODO: figure out the actual grammar; is body required to be braced?
828 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500829 attrs: many0!(Attribute::parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800830 vis: syn!(Visibility) >>
831 macro_: keyword!(macro) >>
832 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500833 args: call!(tt::parenthesized) >>
834 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800835 (ItemMacro2 {
836 attrs: attrs,
837 vis: vis,
838 macro_token: macro_,
839 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500840 paren_token: args.0,
841 args: args.1,
842 brace_token: body.0,
843 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800844 })
845 ));
846
David Tolnay4c614be2017-11-10 00:02:38 -0800847 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500848 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700849 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800850 extern_: keyword!(extern) >>
851 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700852 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800853 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
854 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800855 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700856 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800857 vis: vis,
858 extern_token: extern_,
859 crate_token: crate_,
860 ident: ident,
861 rename: rename,
862 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800863 })
David Tolnayedf2b992016-09-23 20:43:45 -0700864 ));
865
David Tolnay4c614be2017-11-10 00:02:38 -0800866 impl_synom!(ItemUse "use item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500867 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700868 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800869 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500870 leading_colon: option!(punct!(::)) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200871 tree: syn!(UseTree) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800872 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800873 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700874 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800875 vis: vis,
876 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500877 leading_colon: leading_colon,
David Tolnay5f332a92017-12-26 00:42:45 -0500878 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800879 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800880 })
David Tolnay4a057422016-10-08 00:02:31 -0700881 ));
882
David Tolnayd97a7d22018-03-31 19:17:01 +0200883 named!(use_element -> Ident, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500884 syn!(Ident)
885 |
886 keyword!(self) => { Into::into }
887 |
888 keyword!(super) => { Into::into }
889 |
890 keyword!(crate) => { Into::into }
David Tolnay0a4d4e92018-07-21 15:31:45 -0700891 |
892 keyword!(extern) => { Into::into }
David Tolnay5f332a92017-12-26 00:42:45 -0500893 ));
894
895 impl_synom!(UseTree "use tree" alt!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200896 syn!(UseRename) => { UseTree::Rename }
897 |
David Tolnay5f332a92017-12-26 00:42:45 -0500898 syn!(UsePath) => { UseTree::Path }
899 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200900 syn!(UseName) => { UseTree::Name }
901 |
David Tolnay5f332a92017-12-26 00:42:45 -0500902 syn!(UseGlob) => { UseTree::Glob }
903 |
David Tolnayd97a7d22018-03-31 19:17:01 +0200904 syn!(UseGroup) => { UseTree::Group }
David Tolnay5f332a92017-12-26 00:42:45 -0500905 ));
906
907 impl_synom!(UsePath "use path" do_parse!(
David Tolnayd97a7d22018-03-31 19:17:01 +0200908 ident: call!(use_element) >>
909 colon2_token: punct!(::) >>
910 tree: syn!(UseTree) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500911 (UsePath {
912 ident: ident,
David Tolnayd97a7d22018-03-31 19:17:01 +0200913 colon2_token: colon2_token,
914 tree: Box::new(tree),
915 })
916 ));
917
918 impl_synom!(UseName "use name" do_parse!(
919 ident: call!(use_element) >>
920 (UseName {
921 ident: ident,
922 })
923 ));
924
925 impl_synom!(UseRename "use rename" do_parse!(
926 ident: call!(use_element) >>
927 as_token: keyword!(as) >>
928 rename: syn!(Ident) >>
929 (UseRename {
930 ident: ident,
931 as_token: as_token,
David Tolnay5f332a92017-12-26 00:42:45 -0500932 rename: rename,
933 })
934 ));
David Tolnay4a057422016-10-08 00:02:31 -0700935
David Tolnay5f332a92017-12-26 00:42:45 -0500936 impl_synom!(UseGlob "use glob" do_parse!(
937 star: punct!(*) >>
938 (UseGlob {
939 star_token: star,
940 })
941 ));
David Tolnay4a057422016-10-08 00:02:31 -0700942
David Tolnayd97a7d22018-03-31 19:17:01 +0200943 impl_synom!(UseGroup "use group" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500944 list: braces!(Punctuated::parse_terminated) >>
David Tolnayd97a7d22018-03-31 19:17:01 +0200945 (UseGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500946 brace_token: list.0,
947 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500948 })
949 ));
David Tolnay4a057422016-10-08 00:02:31 -0700950
David Tolnay4c614be2017-11-10 00:02:38 -0800951 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500952 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700953 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800954 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500955 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700956 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800957 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800958 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800959 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700960 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800961 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800962 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700963 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800964 vis: vis,
965 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500966 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800967 ident: ident,
968 colon_token: colon,
969 ty: Box::new(ty),
970 eq_token: eq,
971 expr: Box::new(value),
972 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800973 })
David Tolnay47a877c2016-10-01 16:50:55 -0700974 ));
975
David Tolnay4c614be2017-11-10 00:02:38 -0800976 impl_synom!(ItemConst "const item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500977 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700978 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800979 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700980 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800981 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800982 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800983 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700984 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800985 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800986 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700987 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800988 vis: vis,
989 const_token: const_,
990 ident: ident,
991 colon_token: colon,
992 ty: Box::new(ty),
993 eq_token: eq,
994 expr: Box::new(value),
995 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800996 })
David Tolnay47a877c2016-10-01 16:50:55 -0700997 ));
998
David Tolnay4c614be2017-11-10 00:02:38 -0800999 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001000 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001001 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001002 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001003 unsafety: option!(keyword!(unsafe)) >>
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001004 asyncness: option!(keyword!(async)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001005 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001006 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001007 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001008 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001009 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001010 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001011 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001012 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001013 many0!(Attribute::parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001014 call!(Block::parse_within),
Michael Layzell416724e2017-05-24 21:12:34 -04001015 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001016 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -07001017 attrs: {
1018 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001019 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001020 attrs
1021 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001022 vis: vis,
1023 constness: constness,
1024 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001025 asyncness: asyncness,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001026 abi: abi,
1027 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -08001028 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001029 paren_token: inputs.0,
1030 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001031 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -05001032 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001033 generics: Generics {
1034 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001035 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001036 },
1037 }),
1038 ident: ident,
1039 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001040 brace_token: inner_attrs_stmts.0,
1041 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001042 }),
David Tolnay4c614be2017-11-10 00:02:38 -08001043 })
David Tolnay42602292016-10-01 22:25:45 -07001044 ));
1045
Alex Crichton954046c2017-05-30 21:49:42 -07001046 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -04001047 named!(parse -> Self, alt!(
1048 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001049 and: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001050 lt: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001051 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001052 self_: keyword!(self) >>
1053 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001054 (ArgSelfRef {
1055 lifetime: lt,
David Tolnay24237fb2017-12-29 02:15:26 -05001056 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -04001057 and_token: and,
1058 self_token: self_,
1059 }.into())
1060 )
1061 |
1062 do_parse!(
David Tolnay24237fb2017-12-29 02:15:26 -05001063 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001064 self_: keyword!(self) >>
1065 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001066 (ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -05001067 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -04001068 self_token: self_,
1069 }.into())
1070 )
1071 |
1072 do_parse!(
1073 pat: syn!(Pat) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001074 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001075 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -04001076 (ArgCaptured {
1077 pat: pat,
1078 ty: ty,
1079 colon_token: colon,
1080 }.into())
1081 )
1082 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001083 syn!(Type) => { FnArg::Ignored }
Michael Layzell92639a52017-06-01 00:07:44 -04001084 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -08001085
1086 fn description() -> Option<&'static str> {
1087 Some("function argument")
1088 }
Alex Crichton954046c2017-05-30 21:49:42 -07001089 }
David Tolnay62f374c2016-10-02 13:37:00 -07001090
David Tolnay4c614be2017-11-10 00:02:38 -08001091 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001092 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001093 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001094 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -07001095 ident: syn!(Ident) >>
1096 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -08001097 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -07001098 Vec::new(),
1099 None,
1100 Some(semi),
1101 )}
David Tolnay37d10332016-10-13 20:51:04 -07001102 |
Alex Crichton954046c2017-05-30 21:49:42 -07001103 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -07001104 tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001105 many0!(Attribute::parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001106 many0!(Item::parse),
Michael Layzell416724e2017-05-24 21:12:34 -04001107 )
David Tolnay8875fca2017-12-31 13:52:37 -05001108 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -07001109 inner_attrs,
1110 Some((brace, items)),
1111 None,
1112 )}
David Tolnay37d10332016-10-13 20:51:04 -07001113 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001114 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -07001115 attrs: {
1116 let mut attrs = outer_attrs;
1117 attrs.extend(content_semi.0);
1118 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -07001119 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001120 vis: vis,
1121 mod_token: mod_,
1122 ident: ident,
1123 content: content_semi.1,
1124 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -08001125 })
David Tolnay35902302016-10-06 01:11:08 -07001126 ));
1127
David Tolnay4c614be2017-11-10 00:02:38 -08001128 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnay5c4613a2018-07-21 15:40:17 -07001129 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001130 abi: syn!(Abi) >>
David Tolnay5c4613a2018-07-21 15:40:17 -07001131 braced_content: braces!(tuple!(
1132 many0!(Attribute::parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001133 many0!(ForeignItem::parse),
David Tolnay5c4613a2018-07-21 15:40:17 -07001134 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001135 (ItemForeignMod {
David Tolnay5c4613a2018-07-21 15:40:17 -07001136 attrs: {
1137 let mut attrs = outer_attrs;
1138 attrs.extend((braced_content.1).0);
1139 attrs
1140 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001141 abi: abi,
David Tolnay5c4613a2018-07-21 15:40:17 -07001142 brace_token: braced_content.0,
1143 items: (braced_content.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001144 })
David Tolnay35902302016-10-06 01:11:08 -07001145 ));
1146
David Tolnay8894f602017-11-11 12:11:04 -08001147 impl_synom!(ForeignItem "foreign item" alt!(
1148 syn!(ForeignItemFn) => { ForeignItem::Fn }
1149 |
1150 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -08001151 |
1152 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay78572112018-08-01 00:36:18 -07001153 |
David Tolnay435c1782018-08-24 16:15:44 -04001154 syn!(ForeignItemMacro) => { ForeignItem::Macro }
David Tolnay8894f602017-11-11 12:11:04 -08001155 ));
David Tolnay35902302016-10-06 01:11:08 -07001156
David Tolnay8894f602017-11-11 12:11:04 -08001157 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001158 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001159 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001160 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001161 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001162 generics: syn!(Generics) >>
1163 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -05001164 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -05001165 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001166 (args, variadic)
1167 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001168 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001169 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001170 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001171 ({
David Tolnay8875fca2017-12-31 13:52:37 -05001172 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -08001173 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -07001174 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -07001175 attrs: attrs,
1176 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001177 decl: Box::new(FnDecl {
1178 fn_token: fn_,
1179 paren_token: parens,
1180 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001181 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001182 output: ret,
1183 generics: Generics {
1184 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001185 ..generics
David Tolnay8894f602017-11-11 12:11:04 -08001186 },
1187 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001188 vis: vis,
1189 }
David Tolnay35902302016-10-06 01:11:08 -07001190 })
1191 ));
1192
David Tolnay8894f602017-11-11 12:11:04 -08001193 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001194 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001195 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001196 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001197 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001198 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001199 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001200 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001201 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001202 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001203 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001204 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001205 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001206 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001207 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001208 static_token: static_,
1209 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001210 vis: vis,
1211 })
1212 ));
1213
David Tolnay199bcbb2017-11-12 10:33:52 -08001214 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001215 attrs: many0!(Attribute::parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001216 vis: syn!(Visibility) >>
1217 type_: keyword!(type) >>
1218 ident: syn!(Ident) >>
1219 semi: punct!(;) >>
1220 (ForeignItemType {
1221 attrs: attrs,
1222 vis: vis,
1223 type_token: type_,
1224 ident: ident,
1225 semi_token: semi,
1226 })
1227 ));
1228
David Tolnay435c1782018-08-24 16:15:44 -04001229 impl_synom!(ForeignItemMacro "macro in extern block" do_parse!(
1230 attrs: many0!(Attribute::parse_outer) >>
David Tolnay78572112018-08-01 00:36:18 -07001231 mac: syn!(Macro) >>
David Tolnay435c1782018-08-24 16:15:44 -04001232 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
1233 (ForeignItemMacro {
1234 attrs: attrs,
1235 mac: mac,
1236 semi_token: semi,
David Tolnay78572112018-08-01 00:36:18 -07001237 })
1238 ));
1239
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001240 impl_synom!(ItemType "type item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001241 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001242 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001243 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001244 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001245 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001246 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001247 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001248 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001249 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001250 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001251 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001252 vis: vis,
1253 type_token: type_,
1254 ident: ident,
1255 generics: Generics {
1256 where_clause: where_clause,
1257 ..generics
1258 },
1259 eq_token: eq,
1260 ty: Box::new(ty),
1261 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001262 })
David Tolnay3cf52982016-10-01 17:11:37 -07001263 ));
1264
David Tolnaybb82ef02018-08-24 20:15:45 -04001265 named!(existential_type(vis: bool) -> ItemExistential, do_parse!(
1266 attrs: many0!(Attribute::parse_outer) >>
1267 vis: cond_reduce!(vis, syn!(Visibility)) >>
1268 existential_token: keyword!(existential) >>
1269 type_token: keyword!(type) >>
1270 ident: syn!(Ident) >>
1271 generics: syn!(Generics) >>
1272 where_clause: option!(syn!(WhereClause)) >>
David Tolnay758ee132018-08-21 21:29:40 -04001273 colon: option!(punct!(:)) >>
David Tolnaybb82ef02018-08-24 20:15:45 -04001274 bounds: cond!(
David Tolnay758ee132018-08-21 21:29:40 -04001275 colon.is_some(),
1276 Punctuated::<TypeParamBound, Token![+]>::parse_separated_nonempty
1277 ) >>
David Tolnaybb82ef02018-08-24 20:15:45 -04001278 semi: punct!(;) >>
1279 (ItemExistential {
1280 attrs: attrs,
1281 vis: vis,
1282 existential_token: existential_token,
1283 type_token: type_token,
1284 ident: ident,
1285 generics: Generics {
1286 where_clause: where_clause,
1287 ..generics
1288 },
1289 colon_token: colon,
1290 bounds: bounds.unwrap_or_else(Punctuated::new),
1291 semi_token: semi,
1292 })
David Tolnay758ee132018-08-21 21:29:40 -04001293 ));
1294
David Tolnaybb82ef02018-08-24 20:15:45 -04001295 impl_synom!(ItemExistential "existential type" call!(existential_type, true));
David Tolnay758ee132018-08-21 21:29:40 -04001296
David Tolnay4c614be2017-11-10 00:02:38 -08001297 impl_synom!(ItemStruct "struct item" switch!(
1298 map!(syn!(DeriveInput), Into::into),
1299 Item::Struct(item) => value!(item)
1300 |
1301 _ => reject!()
1302 ));
David Tolnay42602292016-10-01 22:25:45 -07001303
David Tolnay4c614be2017-11-10 00:02:38 -08001304 impl_synom!(ItemEnum "enum item" switch!(
1305 map!(syn!(DeriveInput), Into::into),
1306 Item::Enum(item) => value!(item)
1307 |
1308 _ => reject!()
1309 ));
1310
1311 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001312 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001313 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001314 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001315 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001316 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001317 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001318 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001319 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001320 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001321 vis: vis,
1322 union_token: union_,
1323 ident: ident,
1324 generics: Generics {
1325 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001326 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001327 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001328 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001329 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001330 ));
1331
David Tolnay4c614be2017-11-10 00:02:38 -08001332 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001333 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001334 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001335 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001336 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001337 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001338 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001339 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001340 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001341 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001342 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001343 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001344 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001345 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001346 vis: vis,
1347 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001348 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001349 trait_token: trait_,
1350 ident: ident,
1351 generics: Generics {
1352 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001353 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001354 },
1355 colon_token: colon,
1356 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001357 brace_token: body.0,
1358 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001359 })
David Tolnay0aecb732016-10-03 23:03:50 -07001360 ));
1361
David Tolnayda705bd2017-11-10 21:58:05 -08001362 impl_synom!(TraitItem "trait item" alt!(
1363 syn!(TraitItemConst) => { TraitItem::Const }
1364 |
1365 syn!(TraitItemMethod) => { TraitItem::Method }
1366 |
1367 syn!(TraitItemType) => { TraitItem::Type }
1368 |
David Tolnaybb82ef02018-08-24 20:15:45 -04001369 syn!(TraitItemExistential) => { TraitItem::Existential }
David Tolnay758ee132018-08-21 21:29:40 -04001370 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001371 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001372 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001373
David Tolnayda705bd2017-11-10 21:58:05 -08001374 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001375 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001376 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001377 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001378 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001379 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001380 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1381 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001382 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001383 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001384 const_token: const_,
1385 ident: ident,
1386 colon_token: colon,
1387 ty: ty,
1388 default: default,
1389 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001390 })
1391 ));
1392
David Tolnayda705bd2017-11-10 21:58:05 -08001393 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001394 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001395 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001396 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001397 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001398 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001399 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001400 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001401 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001402 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001403 where_clause: option!(syn!(WhereClause)) >>
David Tolnay76178be2018-07-31 23:06:15 -07001404 body: option!(braces!(tuple!(
1405 many0!(Attribute::parse_inner),
1406 call!(Block::parse_within),
1407 ))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001408 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001409 ({
1410 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001411 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001412 None => (Vec::new(), None),
1413 };
David Tolnayda705bd2017-11-10 21:58:05 -08001414 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001415 attrs: {
1416 let mut attrs = outer_attrs;
1417 attrs.extend(inner_attrs);
1418 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001419 },
David Tolnayda705bd2017-11-10 21:58:05 -08001420 sig: MethodSig {
1421 constness: constness,
1422 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001423 asyncness: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001424 abi: abi,
1425 ident: ident,
1426 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001427 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001428 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001429 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001430 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001431 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001432 generics: Generics {
1433 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001434 ..generics
David Tolnay5859df12016-10-29 22:49:54 -07001435 },
1436 },
David Tolnayda705bd2017-11-10 21:58:05 -08001437 },
1438 default: stmts.map(|stmts| {
1439 Block {
1440 stmts: stmts.0,
1441 brace_token: stmts.1,
1442 }
1443 }),
1444 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001445 }
David Tolnay0aecb732016-10-03 23:03:50 -07001446 })
1447 ));
1448
David Tolnayda705bd2017-11-10 21:58:05 -08001449 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001450 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001451 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001452 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001453 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001454 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001455 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001456 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001457 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001458 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001459 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001460 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001461 type_token: type_,
1462 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001463 generics: Generics {
1464 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001465 ..generics
Nika Layzell0183ca32017-12-05 15:24:01 -05001466 },
David Tolnayda705bd2017-11-10 21:58:05 -08001467 colon_token: colon,
1468 bounds: bounds.unwrap_or_default(),
1469 default: default,
1470 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001471 })
1472 ));
1473
David Tolnaybb82ef02018-08-24 20:15:45 -04001474 impl_synom!(TraitItemExistential "trait item existential type" map!(
1475 call!(existential_type, false),
1476 |ety| TraitItemExistential {
1477 attrs: ety.attrs,
1478 existential_token: ety.existential_token,
1479 type_token: ety.type_token,
1480 ident: ety.ident,
1481 generics: ety.generics,
1482 colon_token: ety.colon_token,
1483 bounds: ety.bounds,
1484 semi_token: ety.semi_token,
1485 }
David Tolnay758ee132018-08-21 21:29:40 -04001486 ));
1487
David Tolnaydecf28d2017-11-11 11:56:45 -08001488 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001489 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001490 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001491 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001492 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001493 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001494 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001495 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001496 })
1497 ));
1498
David Tolnay4c614be2017-11-10 00:02:38 -08001499 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnaycf3697a2018-03-31 20:51:15 +02001500 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001501 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001502 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001503 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001504 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001505 polarity_path: alt!(
1506 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001507 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001508 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001509 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001510 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001511 )
1512 |
David Tolnay570695e2017-06-03 16:15:13 -07001513 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001514 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001515 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001516 where_clause: option!(syn!(WhereClause)) >>
David Tolnaycf3697a2018-03-31 20:51:15 +02001517 inner: braces!(tuple!(
1518 many0!(Attribute::parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001519 many0!(ImplItem::parse),
David Tolnaycf3697a2018-03-31 20:51:15 +02001520 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001521 (ItemImpl {
David Tolnaycf3697a2018-03-31 20:51:15 +02001522 attrs: {
1523 let mut attrs = outer_attrs;
1524 attrs.extend((inner.1).0);
1525 attrs
1526 },
David Tolnayc6b55bc2017-11-09 22:48:38 -08001527 defaultness: defaultness,
1528 unsafety: unsafety,
1529 impl_token: impl_,
1530 generics: Generics {
1531 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001532 ..generics
David Tolnayc6b55bc2017-11-09 22:48:38 -08001533 },
1534 trait_: polarity_path,
1535 self_ty: Box::new(self_ty),
David Tolnaycf3697a2018-03-31 20:51:15 +02001536 brace_token: inner.0,
1537 items: (inner.1).1,
David Tolnay4c614be2017-11-10 00:02:38 -08001538 })
David Tolnay4c9be372016-10-06 00:47:37 -07001539 ));
1540
David Tolnay857628c2017-11-11 12:25:31 -08001541 impl_synom!(ImplItem "item in impl block" alt!(
1542 syn!(ImplItemConst) => { ImplItem::Const }
1543 |
1544 syn!(ImplItemMethod) => { ImplItem::Method }
1545 |
1546 syn!(ImplItemType) => { ImplItem::Type }
1547 |
David Tolnaybb82ef02018-08-24 20:15:45 -04001548 syn!(ImplItemExistential) => { ImplItem::Existential }
David Tolnay758ee132018-08-21 21:29:40 -04001549 |
David Tolnay857628c2017-11-11 12:25:31 -08001550 syn!(ImplItemMacro) => { ImplItem::Macro }
1551 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001552
David Tolnay857628c2017-11-11 12:25:31 -08001553 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001554 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001555 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001556 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001557 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001558 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001559 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001560 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001561 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001562 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001563 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001564 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001565 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001566 vis: vis,
1567 defaultness: defaultness,
1568 const_token: const_,
1569 ident: ident,
1570 colon_token: colon,
1571 ty: ty,
1572 eq_token: eq,
1573 expr: value,
1574 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001575 })
1576 ));
1577
David Tolnay857628c2017-11-11 12:25:31 -08001578 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001579 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001580 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001581 defaultness: option!(keyword!(default)) >>
1582 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001583 unsafety: option!(keyword!(unsafe)) >>
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001584 asyncness: option!(keyword!(async)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001585 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001586 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001587 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001588 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001589 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001590 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001591 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001592 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001593 many0!(Attribute::parse_inner),
David Tolnay0235ba62018-07-21 19:20:50 -07001594 call!(Block::parse_within),
Michael Layzell416724e2017-05-24 21:12:34 -04001595 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001596 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001597 attrs: {
1598 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001599 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001600 attrs
1601 },
David Tolnay857628c2017-11-11 12:25:31 -08001602 vis: vis,
1603 defaultness: defaultness,
1604 sig: MethodSig {
1605 constness: constness,
1606 unsafety: unsafety,
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001607 asyncness: asyncness,
David Tolnay857628c2017-11-11 12:25:31 -08001608 abi: abi,
1609 ident: ident,
1610 decl: FnDecl {
1611 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001612 paren_token: inputs.0,
1613 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001614 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001615 generics: Generics {
1616 where_clause: where_clause,
David Tolnayd142fc52018-07-21 15:09:53 -07001617 ..generics
David Tolnay4c9be372016-10-06 00:47:37 -07001618 },
David Tolnayd2836e22017-12-27 23:13:00 -05001619 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001620 },
David Tolnay857628c2017-11-11 12:25:31 -08001621 },
1622 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001623 brace_token: inner_attrs_stmts.0,
1624 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001625 },
David Tolnay4c9be372016-10-06 00:47:37 -07001626 })
1627 ));
1628
David Tolnay857628c2017-11-11 12:25:31 -08001629 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001630 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001631 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001632 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001633 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001634 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001635 generics: syn!(Generics) >>
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001636 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001637 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001638 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001639 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001640 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001641 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001642 vis: vis,
1643 defaultness: defaultness,
1644 type_token: type_,
1645 ident: ident,
David Tolnaycaa2a6d2018-07-21 15:08:07 -07001646 generics: Generics {
1647 where_clause: where_clause,
1648 ..generics
1649 },
David Tolnay857628c2017-11-11 12:25:31 -08001650 eq_token: eq,
1651 ty: ty,
1652 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001653 })
1654 ));
1655
David Tolnaybb82ef02018-08-24 20:15:45 -04001656 impl_synom!(ImplItemExistential "existential type in impl block" map!(
1657 call!(existential_type, true),
1658 |ety| ImplItemExistential {
1659 attrs: ety.attrs,
1660 existential_token: ety.existential_token,
1661 type_token: ety.type_token,
1662 ident: ety.ident,
1663 generics: ety.generics,
1664 colon_token: ety.colon_token,
1665 bounds: ety.bounds,
1666 semi_token: ety.semi_token,
1667 }
David Tolnay758ee132018-08-21 21:29:40 -04001668 ));
1669
David Tolnay857628c2017-11-11 12:25:31 -08001670 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001671 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001672 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001673 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001674 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001675 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001676 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001677 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001678 })
1679 ));
1680
David Tolnayab919512017-12-30 23:31:51 -05001681 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1682 match *delimiter {
1683 MacroDelimiter::Brace(_) => true,
1684 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001685 }
1686 }
David Tolnayedf2b992016-09-23 20:43:45 -07001687}
David Tolnay4a51dc72016-10-01 00:40:31 -07001688
1689#[cfg(feature = "printing")]
1690mod printing {
1691 use super::*;
1692 use attr::FilterAttrs;
Alex Crichtona74a1c82018-05-16 10:20:44 -07001693 use proc_macro2::TokenStream;
David Tolnay65fb5662018-05-20 20:02:28 -07001694 use quote::{ToTokens, TokenStreamExt};
David Tolnay4a51dc72016-10-01 00:40:31 -07001695
David Tolnay1bfa7332017-11-11 12:41:20 -08001696 impl ToTokens for ItemExternCrate {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001697 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001698 tokens.append_all(self.attrs.outer());
1699 self.vis.to_tokens(tokens);
1700 self.extern_token.to_tokens(tokens);
1701 self.crate_token.to_tokens(tokens);
1702 self.ident.to_tokens(tokens);
1703 if let Some((ref as_token, ref rename)) = self.rename {
1704 as_token.to_tokens(tokens);
1705 rename.to_tokens(tokens);
1706 }
1707 self.semi_token.to_tokens(tokens);
1708 }
1709 }
1710
1711 impl ToTokens for ItemUse {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001712 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001713 tokens.append_all(self.attrs.outer());
1714 self.vis.to_tokens(tokens);
1715 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001716 self.leading_colon.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001717 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001718 self.semi_token.to_tokens(tokens);
1719 }
1720 }
1721
1722 impl ToTokens for ItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001723 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001724 tokens.append_all(self.attrs.outer());
1725 self.vis.to_tokens(tokens);
1726 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001727 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001728 self.ident.to_tokens(tokens);
1729 self.colon_token.to_tokens(tokens);
1730 self.ty.to_tokens(tokens);
1731 self.eq_token.to_tokens(tokens);
1732 self.expr.to_tokens(tokens);
1733 self.semi_token.to_tokens(tokens);
1734 }
1735 }
1736
1737 impl ToTokens for ItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001738 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001739 tokens.append_all(self.attrs.outer());
1740 self.vis.to_tokens(tokens);
1741 self.const_token.to_tokens(tokens);
1742 self.ident.to_tokens(tokens);
1743 self.colon_token.to_tokens(tokens);
1744 self.ty.to_tokens(tokens);
1745 self.eq_token.to_tokens(tokens);
1746 self.expr.to_tokens(tokens);
1747 self.semi_token.to_tokens(tokens);
1748 }
1749 }
1750
1751 impl ToTokens for ItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001752 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001753 tokens.append_all(self.attrs.outer());
1754 self.vis.to_tokens(tokens);
1755 self.constness.to_tokens(tokens);
1756 self.unsafety.to_tokens(tokens);
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09001757 self.asyncness.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001758 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07001759 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001760 self.block.brace_token.surround(tokens, |tokens| {
1761 tokens.append_all(self.attrs.inner());
1762 tokens.append_all(&self.block.stmts);
1763 });
1764 }
1765 }
1766
1767 impl ToTokens for ItemMod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001768 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001769 tokens.append_all(self.attrs.outer());
1770 self.vis.to_tokens(tokens);
1771 self.mod_token.to_tokens(tokens);
1772 self.ident.to_tokens(tokens);
1773 if let Some((ref brace, ref items)) = self.content {
1774 brace.surround(tokens, |tokens| {
1775 tokens.append_all(self.attrs.inner());
1776 tokens.append_all(items);
1777 });
1778 } else {
1779 TokensOrDefault(&self.semi).to_tokens(tokens);
1780 }
1781 }
1782 }
1783
1784 impl ToTokens for ItemForeignMod {
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.abi.to_tokens(tokens);
1788 self.brace_token.surround(tokens, |tokens| {
David Tolnay5c4613a2018-07-21 15:40:17 -07001789 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001790 tokens.append_all(&self.items);
1791 });
1792 }
1793 }
1794
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001795 impl ToTokens for ItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001796 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001797 tokens.append_all(self.attrs.outer());
1798 self.vis.to_tokens(tokens);
1799 self.type_token.to_tokens(tokens);
1800 self.ident.to_tokens(tokens);
1801 self.generics.to_tokens(tokens);
1802 self.generics.where_clause.to_tokens(tokens);
1803 self.eq_token.to_tokens(tokens);
1804 self.ty.to_tokens(tokens);
1805 self.semi_token.to_tokens(tokens);
1806 }
1807 }
1808
David Tolnaybb82ef02018-08-24 20:15:45 -04001809 impl ToTokens for ItemExistential {
1810 fn to_tokens(&self, tokens: &mut TokenStream) {
1811 tokens.append_all(self.attrs.outer());
1812 self.vis.to_tokens(tokens);
1813 self.existential_token.to_tokens(tokens);
1814 self.type_token.to_tokens(tokens);
1815 self.ident.to_tokens(tokens);
1816 self.generics.to_tokens(tokens);
1817 self.generics.where_clause.to_tokens(tokens);
1818 if !self.bounds.is_empty() {
1819 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1820 self.bounds.to_tokens(tokens);
1821 }
1822 self.semi_token.to_tokens(tokens);
1823 }
1824 }
1825
David Tolnay1bfa7332017-11-11 12:41:20 -08001826 impl ToTokens for ItemEnum {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001827 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001828 tokens.append_all(self.attrs.outer());
1829 self.vis.to_tokens(tokens);
1830 self.enum_token.to_tokens(tokens);
1831 self.ident.to_tokens(tokens);
1832 self.generics.to_tokens(tokens);
1833 self.generics.where_clause.to_tokens(tokens);
1834 self.brace_token.surround(tokens, |tokens| {
1835 self.variants.to_tokens(tokens);
1836 });
1837 }
1838 }
1839
1840 impl ToTokens for ItemStruct {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001841 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001842 tokens.append_all(self.attrs.outer());
1843 self.vis.to_tokens(tokens);
1844 self.struct_token.to_tokens(tokens);
1845 self.ident.to_tokens(tokens);
1846 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001847 match self.fields {
1848 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001849 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001850 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001851 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001852 Fields::Unnamed(ref fields) => {
1853 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001854 self.generics.where_clause.to_tokens(tokens);
1855 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001856 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001857 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001858 self.generics.where_clause.to_tokens(tokens);
1859 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001860 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001861 }
1862 }
1863 }
1864
1865 impl ToTokens for ItemUnion {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001866 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001867 tokens.append_all(self.attrs.outer());
1868 self.vis.to_tokens(tokens);
1869 self.union_token.to_tokens(tokens);
1870 self.ident.to_tokens(tokens);
1871 self.generics.to_tokens(tokens);
1872 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001873 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001874 }
1875 }
1876
1877 impl ToTokens for ItemTrait {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001878 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001879 tokens.append_all(self.attrs.outer());
1880 self.vis.to_tokens(tokens);
1881 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001882 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001883 self.trait_token.to_tokens(tokens);
1884 self.ident.to_tokens(tokens);
1885 self.generics.to_tokens(tokens);
1886 if !self.supertraits.is_empty() {
1887 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1888 self.supertraits.to_tokens(tokens);
1889 }
1890 self.generics.where_clause.to_tokens(tokens);
1891 self.brace_token.surround(tokens, |tokens| {
1892 tokens.append_all(&self.items);
1893 });
1894 }
1895 }
1896
David Tolnay1bfa7332017-11-11 12:41:20 -08001897 impl ToTokens for ItemImpl {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001898 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001899 tokens.append_all(self.attrs.outer());
1900 self.defaultness.to_tokens(tokens);
1901 self.unsafety.to_tokens(tokens);
1902 self.impl_token.to_tokens(tokens);
1903 self.generics.to_tokens(tokens);
1904 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1905 polarity.to_tokens(tokens);
1906 path.to_tokens(tokens);
1907 for_token.to_tokens(tokens);
1908 }
1909 self.self_ty.to_tokens(tokens);
1910 self.generics.where_clause.to_tokens(tokens);
1911 self.brace_token.surround(tokens, |tokens| {
David Tolnaycf3697a2018-03-31 20:51:15 +02001912 tokens.append_all(self.attrs.inner());
David Tolnay1bfa7332017-11-11 12:41:20 -08001913 tokens.append_all(&self.items);
1914 });
1915 }
1916 }
1917
1918 impl ToTokens for ItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001919 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001920 tokens.append_all(self.attrs.outer());
1921 self.mac.path.to_tokens(tokens);
1922 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001923 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001924 match self.mac.delimiter {
1925 MacroDelimiter::Paren(ref paren) => {
1926 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1927 }
1928 MacroDelimiter::Brace(ref brace) => {
1929 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1930 }
1931 MacroDelimiter::Bracket(ref bracket) => {
1932 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1933 }
1934 }
David Tolnay57292da2017-12-27 21:03:33 -05001935 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001936 }
1937 }
David Tolnay42602292016-10-01 22:25:45 -07001938
David Tolnay500d8322017-12-18 00:32:51 -08001939 impl ToTokens for ItemMacro2 {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001940 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay500d8322017-12-18 00:32:51 -08001941 tokens.append_all(self.attrs.outer());
1942 self.vis.to_tokens(tokens);
1943 self.macro_token.to_tokens(tokens);
1944 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001945 self.paren_token.surround(tokens, |tokens| {
1946 self.args.to_tokens(tokens);
1947 });
1948 self.brace_token.surround(tokens, |tokens| {
1949 self.body.to_tokens(tokens);
1950 });
David Tolnay500d8322017-12-18 00:32:51 -08001951 }
1952 }
1953
David Tolnay2ae520a2017-12-29 11:19:50 -05001954 impl ToTokens for ItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001955 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05001956 self.tts.to_tokens(tokens);
1957 }
1958 }
1959
David Tolnay5f332a92017-12-26 00:42:45 -05001960 impl ToTokens for UsePath {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001961 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay5f332a92017-12-26 00:42:45 -05001962 self.ident.to_tokens(tokens);
David Tolnayd97a7d22018-03-31 19:17:01 +02001963 self.colon2_token.to_tokens(tokens);
1964 self.tree.to_tokens(tokens);
1965 }
1966 }
1967
1968 impl ToTokens for UseName {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001969 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001970 self.ident.to_tokens(tokens);
1971 }
1972 }
1973
1974 impl ToTokens for UseRename {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001975 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayd97a7d22018-03-31 19:17:01 +02001976 self.ident.to_tokens(tokens);
1977 self.as_token.to_tokens(tokens);
1978 self.rename.to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001979 }
1980 }
1981
David Tolnay5f332a92017-12-26 00:42:45 -05001982 impl ToTokens for UseGlob {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001983 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001984 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001985 }
1986 }
1987
David Tolnayd97a7d22018-03-31 19:17:01 +02001988 impl ToTokens for UseGroup {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001989 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001990 self.brace_token.surround(tokens, |tokens| {
1991 self.items.to_tokens(tokens);
1992 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001993 }
1994 }
1995
David Tolnay1bfa7332017-11-11 12:41:20 -08001996 impl ToTokens for TraitItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07001997 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001998 tokens.append_all(self.attrs.outer());
1999 self.const_token.to_tokens(tokens);
2000 self.ident.to_tokens(tokens);
2001 self.colon_token.to_tokens(tokens);
2002 self.ty.to_tokens(tokens);
2003 if let Some((ref eq_token, ref default)) = self.default {
2004 eq_token.to_tokens(tokens);
2005 default.to_tokens(tokens);
2006 }
2007 self.semi_token.to_tokens(tokens);
2008 }
2009 }
2010
2011 impl ToTokens for TraitItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002012 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002013 tokens.append_all(self.attrs.outer());
2014 self.sig.to_tokens(tokens);
2015 match self.default {
2016 Some(ref block) => {
2017 block.brace_token.surround(tokens, |tokens| {
2018 tokens.append_all(self.attrs.inner());
2019 tokens.append_all(&block.stmts);
2020 });
David Tolnayca085422016-10-04 00:12:38 -07002021 }
David Tolnay1bfa7332017-11-11 12:41:20 -08002022 None => {
2023 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07002024 }
David Tolnay1bfa7332017-11-11 12:41:20 -08002025 }
2026 }
2027 }
2028
2029 impl ToTokens for TraitItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002030 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002031 tokens.append_all(self.attrs.outer());
2032 self.type_token.to_tokens(tokens);
2033 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05002034 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08002035 if !self.bounds.is_empty() {
2036 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2037 self.bounds.to_tokens(tokens);
2038 }
Nika Layzell0183ca32017-12-05 15:24:01 -05002039 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08002040 if let Some((ref eq_token, ref default)) = self.default {
2041 eq_token.to_tokens(tokens);
2042 default.to_tokens(tokens);
2043 }
2044 self.semi_token.to_tokens(tokens);
2045 }
2046 }
2047
David Tolnaybb82ef02018-08-24 20:15:45 -04002048 impl ToTokens for TraitItemExistential {
2049 fn to_tokens(&self, tokens: &mut TokenStream) {
2050 tokens.append_all(self.attrs.outer());
2051 self.existential_token.to_tokens(tokens);
2052 self.type_token.to_tokens(tokens);
2053 self.ident.to_tokens(tokens);
2054 self.generics.to_tokens(tokens);
2055 self.generics.where_clause.to_tokens(tokens);
2056 if !self.bounds.is_empty() {
2057 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2058 self.bounds.to_tokens(tokens);
2059 }
2060 self.semi_token.to_tokens(tokens);
2061 }
2062 }
2063
David Tolnay1bfa7332017-11-11 12:41:20 -08002064 impl ToTokens for TraitItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002065 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay1bfa7332017-11-11 12:41:20 -08002066 tokens.append_all(self.attrs.outer());
2067 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05002068 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07002069 }
2070 }
2071
David Tolnay2ae520a2017-12-29 11:19:50 -05002072 impl ToTokens for TraitItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002073 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002074 self.tts.to_tokens(tokens);
2075 }
2076 }
2077
David Tolnay857628c2017-11-11 12:25:31 -08002078 impl ToTokens for ImplItemConst {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002079 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay4c9be372016-10-06 00:47:37 -07002080 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08002081 self.vis.to_tokens(tokens);
2082 self.defaultness.to_tokens(tokens);
2083 self.const_token.to_tokens(tokens);
2084 self.ident.to_tokens(tokens);
2085 self.colon_token.to_tokens(tokens);
2086 self.ty.to_tokens(tokens);
2087 self.eq_token.to_tokens(tokens);
2088 self.expr.to_tokens(tokens);
2089 self.semi_token.to_tokens(tokens);
2090 }
2091 }
2092
2093 impl ToTokens for ImplItemMethod {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002094 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002095 tokens.append_all(self.attrs.outer());
2096 self.vis.to_tokens(tokens);
2097 self.defaultness.to_tokens(tokens);
2098 self.sig.to_tokens(tokens);
2099 self.block.brace_token.surround(tokens, |tokens| {
2100 tokens.append_all(self.attrs.inner());
2101 tokens.append_all(&self.block.stmts);
2102 });
2103 }
2104 }
2105
2106 impl ToTokens for ImplItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002107 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002108 tokens.append_all(self.attrs.outer());
2109 self.vis.to_tokens(tokens);
2110 self.defaultness.to_tokens(tokens);
2111 self.type_token.to_tokens(tokens);
2112 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05002113 self.generics.to_tokens(tokens);
David Tolnaycaa2a6d2018-07-21 15:08:07 -07002114 self.generics.where_clause.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08002115 self.eq_token.to_tokens(tokens);
2116 self.ty.to_tokens(tokens);
2117 self.semi_token.to_tokens(tokens);
2118 }
2119 }
2120
David Tolnaybb82ef02018-08-24 20:15:45 -04002121 impl ToTokens for ImplItemExistential {
2122 fn to_tokens(&self, tokens: &mut TokenStream) {
2123 tokens.append_all(self.attrs.outer());
2124 self.existential_token.to_tokens(tokens);
2125 self.type_token.to_tokens(tokens);
2126 self.ident.to_tokens(tokens);
2127 self.generics.to_tokens(tokens);
2128 self.generics.where_clause.to_tokens(tokens);
2129 if !self.bounds.is_empty() {
2130 TokensOrDefault(&self.colon_token).to_tokens(tokens);
2131 self.bounds.to_tokens(tokens);
2132 }
2133 self.semi_token.to_tokens(tokens);
2134 }
2135 }
2136
David Tolnay857628c2017-11-11 12:25:31 -08002137 impl ToTokens for ImplItemMacro {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002138 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay857628c2017-11-11 12:25:31 -08002139 tokens.append_all(self.attrs.outer());
2140 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05002141 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07002142 }
2143 }
2144
David Tolnay2ae520a2017-12-29 11:19:50 -05002145 impl ToTokens for ImplItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002146 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002147 self.tts.to_tokens(tokens);
2148 }
2149 }
2150
David Tolnay8894f602017-11-11 12:11:04 -08002151 impl ToTokens for ForeignItemFn {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002152 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay35902302016-10-06 01:11:08 -07002153 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002154 self.vis.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07002155 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08002156 self.semi_token.to_tokens(tokens);
2157 }
2158 }
2159
2160 impl ToTokens for ForeignItemStatic {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002161 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay8894f602017-11-11 12:11:04 -08002162 tokens.append_all(self.attrs.outer());
2163 self.vis.to_tokens(tokens);
2164 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002165 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08002166 self.ident.to_tokens(tokens);
2167 self.colon_token.to_tokens(tokens);
2168 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002169 self.semi_token.to_tokens(tokens);
2170 }
2171 }
2172
David Tolnay199bcbb2017-11-12 10:33:52 -08002173 impl ToTokens for ForeignItemType {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002174 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay199bcbb2017-11-12 10:33:52 -08002175 tokens.append_all(self.attrs.outer());
2176 self.vis.to_tokens(tokens);
2177 self.type_token.to_tokens(tokens);
2178 self.ident.to_tokens(tokens);
2179 self.semi_token.to_tokens(tokens);
2180 }
2181 }
2182
David Tolnay435c1782018-08-24 16:15:44 -04002183 impl ToTokens for ForeignItemMacro {
2184 fn to_tokens(&self, tokens: &mut TokenStream) {
2185 tokens.append_all(self.attrs.outer());
2186 self.mac.to_tokens(tokens);
2187 self.semi_token.to_tokens(tokens);
2188 }
2189 }
2190
David Tolnay2ae520a2017-12-29 11:19:50 -05002191 impl ToTokens for ForeignItemVerbatim {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002192 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay2ae520a2017-12-29 11:19:50 -05002193 self.tts.to_tokens(tokens);
2194 }
2195 }
2196
David Tolnay570695e2017-06-03 16:15:13 -07002197 impl ToTokens for MethodSig {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002198 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay570695e2017-06-03 16:15:13 -07002199 self.constness.to_tokens(tokens);
2200 self.unsafety.to_tokens(tokens);
Yusuke Sasakif00a3ef2018-07-20 22:08:42 +09002201 self.asyncness.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -07002202 self.abi.to_tokens(tokens);
Alex Crichtona74a1c82018-05-16 10:20:44 -07002203 NamedDecl(&self.decl, &self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002204 }
2205 }
2206
Alex Crichtona74a1c82018-05-16 10:20:44 -07002207 struct NamedDecl<'a>(&'a FnDecl, &'a Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002208
2209 impl<'a> ToTokens for NamedDecl<'a> {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002210 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002211 self.0.fn_token.to_tokens(tokens);
2212 self.1.to_tokens(tokens);
2213 self.0.generics.to_tokens(tokens);
2214 self.0.paren_token.surround(tokens, |tokens| {
2215 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05002216 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
2217 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04002218 }
David Tolnayd2836e22017-12-27 23:13:00 -05002219 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002220 });
2221 self.0.output.to_tokens(tokens);
2222 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07002223 }
2224 }
2225
Alex Crichton62a0a592017-05-22 13:58:53 -07002226 impl ToTokens for ArgSelfRef {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002227 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002228 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002229 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05002230 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002231 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002232 }
2233 }
2234
2235 impl ToTokens for ArgSelf {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002236 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnay24237fb2017-12-29 02:15:26 -05002237 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002238 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002239 }
2240 }
2241
2242 impl ToTokens for ArgCaptured {
Alex Crichtona74a1c82018-05-16 10:20:44 -07002243 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichton62a0a592017-05-22 13:58:53 -07002244 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07002245 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07002246 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07002247 }
2248 }
David Tolnay4a51dc72016-10-01 00:40:31 -07002249}