blob: 0bc57aac0aa0efe20362f219a7bcfa1c1d4fdad6 [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// Copyright 2018 Syn Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
David Tolnayb79ee962016-09-04 09:39:20 -07009use super::*;
David Tolnay3cfd1d32018-01-03 00:22:08 -080010use derive::{Data, DeriveInput};
David Tolnayf2cfd722017-12-31 18:02:51 -050011use punctuated::Punctuated;
David Tolnay61037c62018-01-05 16:21:03 -080012use proc_macro2::TokenStream;
13use token::{Brace, Paren};
David Tolnay9c76bcb2017-12-26 23:14:59 -050014
15#[cfg(feature = "extra-traits")]
David Tolnayc43b44e2017-12-30 23:55:54 -050016use tt::TokenStreamHelper;
David Tolnay9c76bcb2017-12-26 23:14:59 -050017#[cfg(feature = "extra-traits")]
18use std::hash::{Hash, Hasher};
David Tolnayb79ee962016-09-04 09:39:20 -070019
Alex Crichton62a0a592017-05-22 13:58:53 -070020ast_enum_of_structs! {
David Tolnay2b214082018-01-07 01:30:18 -080021 /// Things that can appear directly inside of a module or scope.
David Tolnay614a0142018-01-07 10:25:43 -080022 ///
23 /// # Syntax tree enum
24 ///
25 /// This type is a [syntax tree enum].
26 ///
27 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayc6b55bc2017-11-09 22:48:38 -080028 pub enum Item {
David Tolnay2b214082018-01-07 01:30:18 -080029 /// An `extern crate` item: `extern crate serde`.
Alex Crichton62a0a592017-05-22 13:58:53 -070030 pub ExternCrate(ItemExternCrate {
David Tolnayc6b55bc2017-11-09 22:48:38 -080031 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070032 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080033 pub extern_token: Token![extern],
34 pub crate_token: Token![crate],
David Tolnay570695e2017-06-03 16:15:13 -070035 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080036 pub rename: Option<(Token![as], Ident)>,
37 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070038 }),
David Tolnay2b214082018-01-07 01:30:18 -080039
40 /// A use declaration: `use std::collections::HashMap`.
Alex Crichton62a0a592017-05-22 13:58:53 -070041 pub Use(ItemUse {
David Tolnayc6b55bc2017-11-09 22:48:38 -080042 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070043 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080044 pub use_token: Token![use],
David Tolnay5f332a92017-12-26 00:42:45 -050045 pub leading_colon: Option<Token![::]>,
David Tolnayf2cfd722017-12-31 18:02:51 -050046 pub prefix: Punctuated<Ident, Token![::]>,
David Tolnay5f332a92017-12-26 00:42:45 -050047 pub tree: UseTree,
David Tolnayf8db7ba2017-11-11 22:52:16 -080048 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070049 }),
David Tolnay2b214082018-01-07 01:30:18 -080050
51 /// A static item: `static BIKE: Shed = Shed(42)`.
Alex Crichton62a0a592017-05-22 13:58:53 -070052 pub Static(ItemStatic {
David Tolnayc6b55bc2017-11-09 22:48:38 -080053 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070054 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080055 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -050056 pub mutability: Option<Token![mut]>,
David Tolnay570695e2017-06-03 16:15:13 -070057 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080058 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080059 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080060 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070061 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080062 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070063 }),
David Tolnay2b214082018-01-07 01:30:18 -080064
65 /// A constant item: `const MAX: u16 = 65535`.
Alex Crichton62a0a592017-05-22 13:58:53 -070066 pub Const(ItemConst {
David Tolnayc6b55bc2017-11-09 22:48:38 -080067 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070068 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080069 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -070070 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -080071 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080072 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080073 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -070074 pub expr: Box<Expr>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080075 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -070076 }),
David Tolnay2b214082018-01-07 01:30:18 -080077
78 /// A free-standing function: `fn process(n: usize) -> Result<()> { ... }`.
Alex Crichton62a0a592017-05-22 13:58:53 -070079 pub Fn(ItemFn {
David Tolnayc6b55bc2017-11-09 22:48:38 -080080 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070081 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -050082 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -050083 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070084 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -070085 pub ident: Ident,
David Tolnay4a3f59a2017-12-28 21:21:12 -050086 pub decl: Box<FnDecl>,
Alex Crichton62a0a592017-05-22 13:58:53 -070087 pub block: Box<Block>,
88 }),
David Tolnay2b214082018-01-07 01:30:18 -080089
90 /// A module or module declaration: `mod m` or `mod m { ... }`.
Alex Crichton62a0a592017-05-22 13:58:53 -070091 pub Mod(ItemMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -080092 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -070093 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -080094 pub mod_token: Token![mod],
David Tolnay570695e2017-06-03 16:15:13 -070095 pub ident: Ident,
David Tolnay32954ef2017-12-26 22:43:16 -050096 pub content: Option<(token::Brace, Vec<Item>)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080097 pub semi: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070098 }),
David Tolnay2b214082018-01-07 01:30:18 -080099
100 /// A block of foreign items: `extern "C" { ... }`.
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700101 pub ForeignMod(ItemForeignMod {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800102 pub attrs: Vec<Attribute>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700103 pub abi: Abi,
David Tolnay32954ef2017-12-26 22:43:16 -0500104 pub brace_token: token::Brace,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700105 pub items: Vec<ForeignItem>,
106 }),
David Tolnay2b214082018-01-07 01:30:18 -0800107
108 /// A type alias: `type Result<T> = std::result::Result<T, MyError>`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800109 pub Type(ItemType {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800110 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700111 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800112 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700113 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700114 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800115 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800116 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800117 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700118 }),
David Tolnay2b214082018-01-07 01:30:18 -0800119
120 /// A struct definition: `struct Foo<A> { x: A }`.
David Tolnaye3d41b72017-12-31 15:24:00 -0500121 pub Struct(ItemStruct {
122 pub attrs: Vec<Attribute>,
123 pub vis: Visibility,
124 pub struct_token: Token![struct],
125 pub ident: Ident,
126 pub generics: Generics,
127 pub fields: Fields,
128 pub semi_token: Option<Token![;]>,
129 }),
David Tolnay2b214082018-01-07 01:30:18 -0800130
131 /// An enum definition: `enum Foo<A, B> { C<A>, D<B> }`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700132 pub Enum(ItemEnum {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800133 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700134 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800135 pub enum_token: Token![enum],
David Tolnay570695e2017-06-03 16:15:13 -0700136 pub ident: Ident,
137 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500138 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500139 pub variants: Punctuated<Variant, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700140 }),
David Tolnay2b214082018-01-07 01:30:18 -0800141
142 /// A union definition: `union Foo<A, B> { x: A, y: B }`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700143 pub Union(ItemUnion {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800144 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700145 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800146 pub union_token: Token![union],
David Tolnay570695e2017-06-03 16:15:13 -0700147 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700148 pub generics: Generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500149 pub fields: FieldsNamed,
Alex Crichton62a0a592017-05-22 13:58:53 -0700150 }),
David Tolnay2b214082018-01-07 01:30:18 -0800151
152 /// A trait definition: `pub trait Iterator { ... }`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700153 pub Trait(ItemTrait {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800154 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700155 pub vis: Visibility,
David Tolnay9b258702017-12-29 02:24:41 -0500156 pub unsafety: Option<Token![unsafe]>,
Nika Layzell0dc6e632017-11-18 12:55:25 -0500157 pub auto_token: Option<Token![auto]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800158 pub trait_token: Token![trait],
David Tolnay570695e2017-06-03 16:15:13 -0700159 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700160 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800161 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500162 pub supertraits: Punctuated<TypeParamBound, Token![+]>,
David Tolnay32954ef2017-12-26 22:43:16 -0500163 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700164 pub items: Vec<TraitItem>,
165 }),
David Tolnay2b214082018-01-07 01:30:18 -0800166
167 /// An impl block providing trait or associated items: `impl<A> Trait
168 /// for Data<A> { ... }`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700169 pub Impl(ItemImpl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800170 pub attrs: Vec<Attribute>,
David Tolnay360a6342017-12-29 02:22:11 -0500171 pub defaultness: Option<Token![default]>,
David Tolnay9b258702017-12-29 02:24:41 -0500172 pub unsafety: Option<Token![unsafe]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800173 pub impl_token: Token![impl],
Alex Crichton62a0a592017-05-22 13:58:53 -0700174 pub generics: Generics,
David Tolnay570695e2017-06-03 16:15:13 -0700175 /// Trait this impl implements.
David Tolnay360a6342017-12-29 02:22:11 -0500176 pub trait_: Option<(Option<Token![!]>, Path, Token![for])>,
David Tolnay570695e2017-06-03 16:15:13 -0700177 /// The Self type of the impl.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800178 pub self_ty: Box<Type>,
David Tolnay32954ef2017-12-26 22:43:16 -0500179 pub brace_token: token::Brace,
Alex Crichton62a0a592017-05-22 13:58:53 -0700180 pub items: Vec<ImplItem>,
181 }),
David Tolnay2b214082018-01-07 01:30:18 -0800182
183 /// A macro invocation, which includes `macro_rules!` definitions.
David Tolnaydecf28d2017-11-11 11:56:45 -0800184 pub Macro(ItemMacro {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800185 pub attrs: Vec<Attribute>,
David Tolnay99a953d2017-11-11 12:51:43 -0800186 /// The `example` in `macro_rules! example { ... }`.
187 pub ident: Option<Ident>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800188 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500189 pub semi_token: Option<Token![;]>,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800190 }),
David Tolnay2b214082018-01-07 01:30:18 -0800191
192 /// A 2.0-style declarative macro introduced by the `macro` keyword.
David Tolnay9c76bcb2017-12-26 23:14:59 -0500193 pub Macro2(ItemMacro2 #manual_extra_traits {
David Tolnay500d8322017-12-18 00:32:51 -0800194 pub attrs: Vec<Attribute>,
195 pub vis: Visibility,
196 pub macro_token: Token![macro],
197 pub ident: Ident,
David Tolnayab919512017-12-30 23:31:51 -0500198 pub paren_token: Paren,
199 pub args: TokenStream,
200 pub brace_token: Brace,
201 pub body: TokenStream,
David Tolnay500d8322017-12-18 00:32:51 -0800202 }),
David Tolnay2b214082018-01-07 01:30:18 -0800203
204 /// Tokens forming an item not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500205 pub Verbatim(ItemVerbatim #manual_extra_traits {
206 pub tts: TokenStream,
207 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700208 }
David Tolnayb79ee962016-09-04 09:39:20 -0700209}
210
David Tolnay9c76bcb2017-12-26 23:14:59 -0500211#[cfg(feature = "extra-traits")]
212impl Eq for ItemMacro2 {}
213
214#[cfg(feature = "extra-traits")]
215impl PartialEq for ItemMacro2 {
216 fn eq(&self, other: &Self) -> bool {
David Tolnay51382052017-12-27 13:46:21 -0500217 self.attrs == other.attrs && self.vis == other.vis && self.macro_token == other.macro_token
David Tolnayab919512017-12-30 23:31:51 -0500218 && self.ident == other.ident && self.paren_token == other.paren_token
219 && TokenStreamHelper(&self.args) == TokenStreamHelper(&other.args)
220 && self.brace_token == other.brace_token
221 && TokenStreamHelper(&self.body) == TokenStreamHelper(&other.body)
David Tolnay9c76bcb2017-12-26 23:14:59 -0500222 }
223}
224
225#[cfg(feature = "extra-traits")]
226impl Hash for ItemMacro2 {
227 fn hash<H>(&self, state: &mut H)
David Tolnay51382052017-12-27 13:46:21 -0500228 where
229 H: Hasher,
David Tolnay9c76bcb2017-12-26 23:14:59 -0500230 {
231 self.attrs.hash(state);
232 self.vis.hash(state);
233 self.macro_token.hash(state);
234 self.ident.hash(state);
David Tolnayab919512017-12-30 23:31:51 -0500235 self.paren_token.hash(state);
236 TokenStreamHelper(&self.args).hash(state);
237 self.brace_token.hash(state);
238 TokenStreamHelper(&self.body).hash(state);
David Tolnay9c76bcb2017-12-26 23:14:59 -0500239 }
240}
241
David Tolnay2ae520a2017-12-29 11:19:50 -0500242#[cfg(feature = "extra-traits")]
243impl Eq for ItemVerbatim {}
244
245#[cfg(feature = "extra-traits")]
246impl PartialEq for ItemVerbatim {
247 fn eq(&self, other: &Self) -> bool {
248 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
249 }
250}
251
252#[cfg(feature = "extra-traits")]
253impl Hash for ItemVerbatim {
254 fn hash<H>(&self, state: &mut H)
255 where
256 H: Hasher,
257 {
258 TokenStreamHelper(&self.tts).hash(state);
259 }
260}
261
David Tolnay0e837402016-12-22 17:25:55 -0500262impl From<DeriveInput> for Item {
263 fn from(input: DeriveInput) -> Item {
David Tolnaye3d41b72017-12-31 15:24:00 -0500264 match input.data {
265 Data::Struct(data) => Item::Struct(ItemStruct {
266 attrs: input.attrs,
267 vis: input.vis,
268 struct_token: data.struct_token,
269 ident: input.ident,
270 generics: input.generics,
271 fields: data.fields,
272 semi_token: data.semi_token,
273 }),
274 Data::Enum(data) => Item::Enum(ItemEnum {
David Tolnay51382052017-12-27 13:46:21 -0500275 attrs: input.attrs,
276 vis: input.vis,
277 enum_token: data.enum_token,
278 ident: input.ident,
279 generics: input.generics,
280 brace_token: data.brace_token,
281 variants: data.variants,
282 }),
David Tolnaye3d41b72017-12-31 15:24:00 -0500283 Data::Union(data) => Item::Union(ItemUnion {
David Tolnay51382052017-12-27 13:46:21 -0500284 attrs: input.attrs,
285 vis: input.vis,
David Tolnaye3d41b72017-12-31 15:24:00 -0500286 union_token: data.union_token,
David Tolnay51382052017-12-27 13:46:21 -0500287 ident: input.ident,
288 generics: input.generics,
David Tolnaye3d41b72017-12-31 15:24:00 -0500289 fields: data.fields,
David Tolnay51382052017-12-27 13:46:21 -0500290 }),
David Tolnay453cfd12016-10-23 11:00:14 -0700291 }
292 }
293}
294
Alex Crichton62a0a592017-05-22 13:58:53 -0700295ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800296 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
David Tolnay614a0142018-01-07 10:25:43 -0800297 ///
298 /// # Syntax tree enum
299 ///
300 /// This type is a [syntax tree enum].
301 ///
302 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay5f332a92017-12-26 00:42:45 -0500303 pub enum UseTree {
David Tolnay05658502018-01-07 09:56:37 -0800304 /// An identifier imported by a `use` item: `Type` or `Type as Renamed`.
David Tolnay5f332a92017-12-26 00:42:45 -0500305 pub Path(UsePath {
306 pub ident: Ident,
307 pub rename: Option<(Token![as], Ident)>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700308 }),
David Tolnay05658502018-01-07 09:56:37 -0800309 /// A glob import in a `use` item: `*`.
David Tolnay5f332a92017-12-26 00:42:45 -0500310 pub Glob(UseGlob {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800311 pub star_token: Token![*],
Alex Crichton62a0a592017-05-22 13:58:53 -0700312 }),
David Tolnay05658502018-01-07 09:56:37 -0800313 /// A braced list of imports in a `use` item: `{A, B, C}`.
David Tolnay5f332a92017-12-26 00:42:45 -0500314 pub List(UseList {
David Tolnay32954ef2017-12-26 22:43:16 -0500315 pub brace_token: token::Brace,
David Tolnayf2cfd722017-12-31 18:02:51 -0500316 pub items: Punctuated<UseTree, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700317 }),
318 }
319}
320
Alex Crichton62a0a592017-05-22 13:58:53 -0700321ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800322 /// An item within an `extern` block.
David Tolnay614a0142018-01-07 10:25:43 -0800323 ///
324 /// # Syntax tree enum
325 ///
326 /// This type is a [syntax tree enum].
327 ///
328 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay8894f602017-11-11 12:11:04 -0800329 pub enum ForeignItem {
David Tolnayebb72722018-01-07 01:14:13 -0800330 /// A foreign function in an `extern` block.
Alex Crichton62a0a592017-05-22 13:58:53 -0700331 pub Fn(ForeignItemFn {
David Tolnay8894f602017-11-11 12:11:04 -0800332 pub attrs: Vec<Attribute>,
333 pub vis: Visibility,
334 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700335 pub decl: Box<FnDecl>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800336 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700337 }),
David Tolnayebb72722018-01-07 01:14:13 -0800338
339 /// A foreign static item in an `extern` block: `static ext: u8`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700340 pub Static(ForeignItemStatic {
David Tolnay8894f602017-11-11 12:11:04 -0800341 pub attrs: Vec<Attribute>,
342 pub vis: Visibility,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800343 pub static_token: Token![static],
David Tolnay24237fb2017-12-29 02:15:26 -0500344 pub mutability: Option<Token![mut]>,
David Tolnay8894f602017-11-11 12:11:04 -0800345 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800346 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800347 pub ty: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800348 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700349 }),
David Tolnayebb72722018-01-07 01:14:13 -0800350
351 /// A foreign type in an `extern` block: `type void`.
David Tolnay199bcbb2017-11-12 10:33:52 -0800352 pub Type(ForeignItemType {
353 pub attrs: Vec<Attribute>,
354 pub vis: Visibility,
355 pub type_token: Token![type],
356 pub ident: Ident,
357 pub semi_token: Token![;],
358 }),
David Tolnayebb72722018-01-07 01:14:13 -0800359
360 /// Tokens in an `extern` block not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500361 pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
362 pub tts: TokenStream,
363 }),
364 }
365}
366
367#[cfg(feature = "extra-traits")]
368impl Eq for ForeignItemVerbatim {}
369
370#[cfg(feature = "extra-traits")]
371impl PartialEq for ForeignItemVerbatim {
372 fn eq(&self, other: &Self) -> bool {
373 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
374 }
375}
376
377#[cfg(feature = "extra-traits")]
378impl Hash for ForeignItemVerbatim {
379 fn hash<H>(&self, state: &mut H)
380 where
381 H: Hasher,
382 {
383 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700384 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700385}
386
David Tolnayda705bd2017-11-10 21:58:05 -0800387ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800388 /// An item declaration within the definition of a trait.
David Tolnay614a0142018-01-07 10:25:43 -0800389 ///
390 /// # Syntax tree enum
391 ///
392 /// This type is a [syntax tree enum].
393 ///
394 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayda705bd2017-11-10 21:58:05 -0800395 pub enum TraitItem {
David Tolnayebb72722018-01-07 01:14:13 -0800396 /// An associated constant within the definition of a trait.
Alex Crichton62a0a592017-05-22 13:58:53 -0700397 pub Const(TraitItemConst {
David Tolnayda705bd2017-11-10 21:58:05 -0800398 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800399 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700400 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800401 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800402 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800403 pub default: Option<(Token![=], Expr)>,
404 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700405 }),
David Tolnayebb72722018-01-07 01:14:13 -0800406
407 /// A trait method within the definition of a trait.
Alex Crichton62a0a592017-05-22 13:58:53 -0700408 pub Method(TraitItemMethod {
David Tolnayda705bd2017-11-10 21:58:05 -0800409 pub attrs: Vec<Attribute>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700410 pub sig: MethodSig,
411 pub default: Option<Block>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800412 pub semi_token: Option<Token![;]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700413 }),
David Tolnayebb72722018-01-07 01:14:13 -0800414
415 /// An associated type within the definition of a trait.
Alex Crichton62a0a592017-05-22 13:58:53 -0700416 pub Type(TraitItemType {
David Tolnayda705bd2017-11-10 21:58:05 -0800417 pub attrs: Vec<Attribute>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800418 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700419 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500420 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800421 pub colon_token: Option<Token![:]>,
David Tolnayf2cfd722017-12-31 18:02:51 -0500422 pub bounds: Punctuated<TypeParamBound, Token![+]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800423 pub default: Option<(Token![=], Type)>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800424 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700425 }),
David Tolnayebb72722018-01-07 01:14:13 -0800426
427 /// A macro invocation within the definition of a trait.
David Tolnaydecf28d2017-11-11 11:56:45 -0800428 pub Macro(TraitItemMacro {
David Tolnayda705bd2017-11-10 21:58:05 -0800429 pub attrs: Vec<Attribute>,
David Tolnaydecf28d2017-11-11 11:56:45 -0800430 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500431 pub semi_token: Option<Token![;]>,
David Tolnayda705bd2017-11-10 21:58:05 -0800432 }),
David Tolnayebb72722018-01-07 01:14:13 -0800433
434 /// Tokens within the definition of a trait not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500435 pub Verbatim(TraitItemVerbatim #manual_extra_traits {
436 pub tts: TokenStream,
437 }),
438 }
439}
440
441#[cfg(feature = "extra-traits")]
442impl Eq for TraitItemVerbatim {}
443
444#[cfg(feature = "extra-traits")]
445impl PartialEq for TraitItemVerbatim {
446 fn eq(&self, other: &Self) -> bool {
447 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
448 }
449}
450
451#[cfg(feature = "extra-traits")]
452impl Hash for TraitItemVerbatim {
453 fn hash<H>(&self, state: &mut H)
454 where
455 H: Hasher,
456 {
457 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700458 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700459}
460
Alex Crichton62a0a592017-05-22 13:58:53 -0700461ast_enum_of_structs! {
David Tolnayebb72722018-01-07 01:14:13 -0800462 /// An item within an impl block.
David Tolnay614a0142018-01-07 10:25:43 -0800463 ///
464 /// # Syntax tree enum
465 ///
466 /// This type is a [syntax tree enum].
467 ///
468 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnay857628c2017-11-11 12:25:31 -0800469 pub enum ImplItem {
David Tolnayebb72722018-01-07 01:14:13 -0800470 /// An associated constant within an impl block.
Alex Crichton62a0a592017-05-22 13:58:53 -0700471 pub Const(ImplItemConst {
David Tolnay857628c2017-11-11 12:25:31 -0800472 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700473 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500474 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800475 pub const_token: Token![const],
David Tolnay570695e2017-06-03 16:15:13 -0700476 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800477 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800478 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800479 pub eq_token: Token![=],
Alex Crichton62a0a592017-05-22 13:58:53 -0700480 pub expr: Expr,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800481 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700482 }),
David Tolnayebb72722018-01-07 01:14:13 -0800483
484 /// A method within an impl block.
Alex Crichton62a0a592017-05-22 13:58:53 -0700485 pub Method(ImplItemMethod {
David Tolnay857628c2017-11-11 12:25:31 -0800486 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700487 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500488 pub defaultness: Option<Token![default]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700489 pub sig: MethodSig,
490 pub block: Block,
491 }),
David Tolnayebb72722018-01-07 01:14:13 -0800492
493 /// An associated type within an impl block.
Alex Crichton62a0a592017-05-22 13:58:53 -0700494 pub Type(ImplItemType {
David Tolnay857628c2017-11-11 12:25:31 -0800495 pub attrs: Vec<Attribute>,
David Tolnay570695e2017-06-03 16:15:13 -0700496 pub vis: Visibility,
David Tolnay360a6342017-12-29 02:22:11 -0500497 pub defaultness: Option<Token![default]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800498 pub type_token: Token![type],
David Tolnay570695e2017-06-03 16:15:13 -0700499 pub ident: Ident,
Nika Layzell591528a2017-12-05 12:47:37 -0500500 pub generics: Generics,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800501 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800502 pub ty: Type,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800503 pub semi_token: Token![;],
Alex Crichton62a0a592017-05-22 13:58:53 -0700504 }),
David Tolnayebb72722018-01-07 01:14:13 -0800505
506 /// A macro invocation within an impl block.
David Tolnay857628c2017-11-11 12:25:31 -0800507 pub Macro(ImplItemMacro {
508 pub attrs: Vec<Attribute>,
509 pub mac: Macro,
David Tolnay57292da2017-12-27 21:03:33 -0500510 pub semi_token: Option<Token![;]>,
David Tolnay857628c2017-11-11 12:25:31 -0800511 }),
David Tolnayebb72722018-01-07 01:14:13 -0800512
513 /// Tokens within an impl block not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500514 pub Verbatim(ImplItemVerbatim #manual_extra_traits {
515 pub tts: TokenStream,
516 }),
517 }
518}
519
520#[cfg(feature = "extra-traits")]
521impl Eq for ImplItemVerbatim {}
522
523#[cfg(feature = "extra-traits")]
524impl PartialEq for ImplItemVerbatim {
525 fn eq(&self, other: &Self) -> bool {
526 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
527 }
528}
529
530#[cfg(feature = "extra-traits")]
531impl Hash for ImplItemVerbatim {
532 fn hash<H>(&self, state: &mut H)
533 where
534 H: Hasher,
535 {
536 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700537 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700538}
539
540ast_struct! {
David Tolnay05658502018-01-07 09:56:37 -0800541 /// A method's signature in a trait or implementation: `unsafe fn
542 /// initialize(&self)`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700543 pub struct MethodSig {
David Tolnay360a6342017-12-29 02:22:11 -0500544 pub constness: Option<Token![const]>,
David Tolnay9b258702017-12-29 02:24:41 -0500545 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700546 pub abi: Option<Abi>,
David Tolnay570695e2017-06-03 16:15:13 -0700547 pub ident: Ident,
Alex Crichton62a0a592017-05-22 13:58:53 -0700548 pub decl: FnDecl,
Alex Crichton62a0a592017-05-22 13:58:53 -0700549 }
550}
551
552ast_struct! {
David Tolnayebb72722018-01-07 01:14:13 -0800553 /// Header of a function declaration, without including the body.
Alex Crichton62a0a592017-05-22 13:58:53 -0700554 pub struct FnDecl {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800555 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500556 pub generics: Generics,
David Tolnay32954ef2017-12-26 22:43:16 -0500557 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -0500558 pub inputs: Punctuated<FnArg, Token![,]>,
David Tolnayd2836e22017-12-27 23:13:00 -0500559 pub variadic: Option<Token![...]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500560 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700561 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700562}
563
Alex Crichton62a0a592017-05-22 13:58:53 -0700564ast_enum_of_structs! {
David Tolnay3f559052018-01-06 23:59:48 -0800565 /// An argument in a function signature.
Alex Crichton62a0a592017-05-22 13:58:53 -0700566 ///
567 /// E.g. `bar: usize` as in `fn foo(bar: usize)`
David Tolnay614a0142018-01-07 10:25:43 -0800568 ///
569 /// # Syntax tree enum
570 ///
571 /// This type is a [syntax tree enum].
572 ///
573 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700574 pub enum FnArg {
David Tolnay3f559052018-01-06 23:59:48 -0800575 /// Self captured by reference in a function signature: `&self` or `&mut
576 /// self`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700577 pub SelfRef(ArgSelfRef {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800578 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -0700579 pub lifetime: Option<Lifetime>,
David Tolnay24237fb2017-12-29 02:15:26 -0500580 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -0500581 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700582 }),
David Tolnay3f559052018-01-06 23:59:48 -0800583 /// Self captured by value in a function signature: `self` or `mut
584 /// self`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700585 pub SelfValue(ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500586 pub mutability: Option<Token![mut]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800587 pub self_token: Token![self],
Alex Crichton62a0a592017-05-22 13:58:53 -0700588 }),
David Tolnay3f559052018-01-06 23:59:48 -0800589 /// An explicitly typed pattern captured by a function signature.
Alex Crichton62a0a592017-05-22 13:58:53 -0700590 pub Captured(ArgCaptured {
591 pub pat: Pat,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800592 pub colon_token: Token![:],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800593 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700594 }),
David Tolnay3f559052018-01-06 23:59:48 -0800595 /// A pattern whose type is inferred captured by a function signature.
David Tolnay80ed55f2017-12-27 22:54:40 -0500596 pub Inferred(Pat),
David Tolnay3f559052018-01-06 23:59:48 -0800597 /// A type not bound to any pattern in a function signature.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800598 pub Ignored(Type),
Alex Crichton62a0a592017-05-22 13:58:53 -0700599 }
David Tolnay62f374c2016-10-02 13:37:00 -0700600}
601
David Tolnayedf2b992016-09-23 20:43:45 -0700602#[cfg(feature = "parsing")]
603pub mod parsing {
604 use super::*;
David Tolnayedf2b992016-09-23 20:43:45 -0700605
David Tolnaydfc886b2018-01-06 08:03:09 -0800606 use buffer::Cursor;
607 use synom::{PResult, Synom};
David Tolnay84aa0752016-10-02 23:01:13 -0700608
David Tolnay4c614be2017-11-10 00:02:38 -0800609 impl_synom!(Item "item" alt!(
610 syn!(ItemExternCrate) => { Item::ExternCrate }
611 |
612 syn!(ItemUse) => { Item::Use }
613 |
614 syn!(ItemStatic) => { Item::Static }
615 |
616 syn!(ItemConst) => { Item::Const }
617 |
618 syn!(ItemFn) => { Item::Fn }
619 |
620 syn!(ItemMod) => { Item::Mod }
621 |
622 syn!(ItemForeignMod) => { Item::ForeignMod }
623 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800624 syn!(ItemType) => { Item::Type }
David Tolnay4c614be2017-11-10 00:02:38 -0800625 |
626 syn!(ItemStruct) => { Item::Struct }
627 |
628 syn!(ItemEnum) => { Item::Enum }
629 |
630 syn!(ItemUnion) => { Item::Union }
631 |
632 syn!(ItemTrait) => { Item::Trait }
633 |
David Tolnay03342952017-12-29 11:52:00 -0500634 call!(deprecated_default_impl) => { Item::Verbatim }
David Tolnay4c614be2017-11-10 00:02:38 -0800635 |
636 syn!(ItemImpl) => { Item::Impl }
637 |
David Tolnaydecf28d2017-11-11 11:56:45 -0800638 syn!(ItemMacro) => { Item::Macro }
David Tolnay500d8322017-12-18 00:32:51 -0800639 |
640 syn!(ItemMacro2) => { Item::Macro2 }
David Tolnay4c614be2017-11-10 00:02:38 -0800641 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700642
David Tolnaydecf28d2017-11-11 11:56:45 -0800643 impl_synom!(ItemMacro "macro item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500644 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700645 what: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800646 bang: punct!(!) >>
David Tolnay570695e2017-06-03 16:15:13 -0700647 ident: option!(syn!(Ident)) >>
David Tolnaye0824032017-12-27 15:25:56 -0500648 body: call!(tt::delimited) >>
David Tolnayab919512017-12-30 23:31:51 -0500649 semi: cond!(!is_brace(&body.0), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -0800650 (ItemMacro {
David Tolnay84aa0752016-10-02 23:01:13 -0700651 attrs: attrs,
David Tolnay99a953d2017-11-11 12:51:43 -0800652 ident: ident,
David Tolnaydecf28d2017-11-11 11:56:45 -0800653 mac: Macro {
David Tolnay5d55ef72016-12-21 20:20:04 -0500654 path: what,
David Tolnay570695e2017-06-03 16:15:13 -0700655 bang_token: bang,
David Tolnayab919512017-12-30 23:31:51 -0500656 delimiter: body.0,
657 tts: body.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800658 },
David Tolnay57292da2017-12-27 21:03:33 -0500659 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800660 })
David Tolnayedf2b992016-09-23 20:43:45 -0700661 ));
662
David Tolnay500d8322017-12-18 00:32:51 -0800663 // TODO: figure out the actual grammar; is body required to be braced?
664 impl_synom!(ItemMacro2 "macro2 item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500665 attrs: many0!(Attribute::parse_outer) >>
David Tolnay500d8322017-12-18 00:32:51 -0800666 vis: syn!(Visibility) >>
667 macro_: keyword!(macro) >>
668 ident: syn!(Ident) >>
David Tolnaye0824032017-12-27 15:25:56 -0500669 args: call!(tt::parenthesized) >>
670 body: call!(tt::braced) >>
David Tolnay500d8322017-12-18 00:32:51 -0800671 (ItemMacro2 {
672 attrs: attrs,
673 vis: vis,
674 macro_token: macro_,
675 ident: ident,
David Tolnayab919512017-12-30 23:31:51 -0500676 paren_token: args.0,
677 args: args.1,
678 brace_token: body.0,
679 body: body.1,
David Tolnay500d8322017-12-18 00:32:51 -0800680 })
681 ));
682
David Tolnay4c614be2017-11-10 00:02:38 -0800683 impl_synom!(ItemExternCrate "extern crate item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500684 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700685 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800686 extern_: keyword!(extern) >>
687 crate_: keyword!(crate) >>
David Tolnay570695e2017-06-03 16:15:13 -0700688 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800689 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
690 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800691 (ItemExternCrate {
David Tolnay570695e2017-06-03 16:15:13 -0700692 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800693 vis: vis,
694 extern_token: extern_,
695 crate_token: crate_,
696 ident: ident,
697 rename: rename,
698 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800699 })
David Tolnayedf2b992016-09-23 20:43:45 -0700700 ));
701
David Tolnay4c614be2017-11-10 00:02:38 -0800702 impl_synom!(ItemUse "use item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500703 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700704 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800705 use_: keyword!(use) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500706 leading_colon: option!(punct!(::)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500707 mut prefix: call!(Punctuated::parse_terminated_with, use_prefix) >>
David Tolnay8edcef12017-12-28 12:06:52 -0500708 tree: switch!(value!(prefix.empty_or_trailing()),
David Tolnay5f332a92017-12-26 00:42:45 -0500709 true => syn!(UseTree)
710 |
David Tolnay8edcef12017-12-28 12:06:52 -0500711 false => alt!(
712 tuple!(keyword!(as), syn!(Ident)) => {
713 |rename| UseTree::Path(UsePath {
David Tolnay56080682018-01-06 14:01:52 -0800714 ident: prefix.pop().unwrap().into_value(),
David Tolnay8edcef12017-12-28 12:06:52 -0500715 rename: Some(rename),
716 })
717 }
David Tolnay5f332a92017-12-26 00:42:45 -0500718 |
David Tolnay8edcef12017-12-28 12:06:52 -0500719 epsilon!() => {
720 |_| UseTree::Path(UsePath {
David Tolnay56080682018-01-06 14:01:52 -0800721 ident: prefix.pop().unwrap().into_value(),
David Tolnay8edcef12017-12-28 12:06:52 -0500722 rename: None,
723 })
724 }
David Tolnay5f332a92017-12-26 00:42:45 -0500725 )
726 ) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800727 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800728 (ItemUse {
David Tolnay4a057422016-10-08 00:02:31 -0700729 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800730 vis: vis,
731 use_token: use_,
David Tolnay5f332a92017-12-26 00:42:45 -0500732 leading_colon: leading_colon,
733 prefix: prefix,
734 tree: tree,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800735 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800736 })
David Tolnay4a057422016-10-08 00:02:31 -0700737 ));
738
David Tolnay5f332a92017-12-26 00:42:45 -0500739 named!(use_prefix -> Ident, alt!(
740 syn!(Ident)
741 |
742 keyword!(self) => { Into::into }
743 |
744 keyword!(super) => { Into::into }
745 |
746 keyword!(crate) => { Into::into }
747 ));
748
749 impl_synom!(UseTree "use tree" alt!(
750 syn!(UsePath) => { UseTree::Path }
751 |
752 syn!(UseGlob) => { UseTree::Glob }
753 |
754 syn!(UseList) => { UseTree::List }
755 ));
756
757 impl_synom!(UsePath "use path" do_parse!(
758 ident: alt!(
759 syn!(Ident)
Michael Layzell92639a52017-06-01 00:07:44 -0400760 |
David Tolnay5f332a92017-12-26 00:42:45 -0500761 keyword!(self) => { Into::into }
762 ) >>
763 rename: option!(tuple!(keyword!(as), syn!(Ident))) >>
764 (UsePath {
765 ident: ident,
766 rename: rename,
767 })
768 ));
David Tolnay4a057422016-10-08 00:02:31 -0700769
David Tolnay5f332a92017-12-26 00:42:45 -0500770 impl_synom!(UseGlob "use glob" do_parse!(
771 star: punct!(*) >>
772 (UseGlob {
773 star_token: star,
774 })
775 ));
David Tolnay4a057422016-10-08 00:02:31 -0700776
David Tolnay5f332a92017-12-26 00:42:45 -0500777 impl_synom!(UseList "use list" do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500778 list: braces!(Punctuated::parse_terminated) >>
David Tolnay5f332a92017-12-26 00:42:45 -0500779 (UseList {
David Tolnay8875fca2017-12-31 13:52:37 -0500780 brace_token: list.0,
781 items: list.1,
David Tolnay5f332a92017-12-26 00:42:45 -0500782 })
783 ));
David Tolnay4a057422016-10-08 00:02:31 -0700784
David Tolnay4c614be2017-11-10 00:02:38 -0800785 impl_synom!(ItemStatic "static item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500786 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700787 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800788 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500789 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -0700790 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800791 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800792 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800793 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700794 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800795 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800796 (ItemStatic {
David Tolnay47a877c2016-10-01 16:50:55 -0700797 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800798 vis: vis,
799 static_token: static_,
David Tolnay24237fb2017-12-29 02:15:26 -0500800 mutability: mutability,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800801 ident: ident,
802 colon_token: colon,
803 ty: Box::new(ty),
804 eq_token: eq,
805 expr: Box::new(value),
806 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800807 })
David Tolnay47a877c2016-10-01 16:50:55 -0700808 ));
809
David Tolnay4c614be2017-11-10 00:02:38 -0800810 impl_synom!(ItemConst "const item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500811 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700812 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800813 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -0700814 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800815 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800816 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800817 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700818 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800819 semi: punct!(;) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800820 (ItemConst {
David Tolnay47a877c2016-10-01 16:50:55 -0700821 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800822 vis: vis,
823 const_token: const_,
824 ident: ident,
825 colon_token: colon,
826 ty: Box::new(ty),
827 eq_token: eq,
828 expr: Box::new(value),
829 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -0800830 })
David Tolnay47a877c2016-10-01 16:50:55 -0700831 ));
832
David Tolnay4c614be2017-11-10 00:02:38 -0800833 impl_synom!(ItemFn "fn item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500834 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700835 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -0500836 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500837 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700838 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800839 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -0700840 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700841 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -0500842 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800843 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -0500844 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700845 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -0500846 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -0700847 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -0400848 )) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800849 (ItemFn {
David Tolnay3b9783a2016-10-29 22:37:09 -0700850 attrs: {
851 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -0500852 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -0700853 attrs
854 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800855 vis: vis,
856 constness: constness,
857 unsafety: unsafety,
858 abi: abi,
859 decl: Box::new(FnDecl {
David Tolnayc6b55bc2017-11-09 22:48:38 -0800860 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500861 paren_token: inputs.0,
862 inputs: inputs.1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800863 output: ret,
David Tolnayd2836e22017-12-27 23:13:00 -0500864 variadic: None,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800865 generics: Generics {
866 where_clause: where_clause,
867 .. generics
868 },
869 }),
870 ident: ident,
871 block: Box::new(Block {
David Tolnay8875fca2017-12-31 13:52:37 -0500872 brace_token: inner_attrs_stmts.0,
873 stmts: (inner_attrs_stmts.1).1,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800874 }),
David Tolnay4c614be2017-11-10 00:02:38 -0800875 })
David Tolnay42602292016-10-01 22:25:45 -0700876 ));
877
Alex Crichton954046c2017-05-30 21:49:42 -0700878 impl Synom for FnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400879 named!(parse -> Self, alt!(
880 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800881 and: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400882 lt: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500883 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800884 self_: keyword!(self) >>
885 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400886 (ArgSelfRef {
887 lifetime: lt,
David Tolnay24237fb2017-12-29 02:15:26 -0500888 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400889 and_token: and,
890 self_token: self_,
891 }.into())
892 )
893 |
894 do_parse!(
David Tolnay24237fb2017-12-29 02:15:26 -0500895 mutability: option!(keyword!(mut)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800896 self_: keyword!(self) >>
897 not!(punct!(:)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400898 (ArgSelf {
David Tolnay24237fb2017-12-29 02:15:26 -0500899 mutability: mutability,
Michael Layzell92639a52017-06-01 00:07:44 -0400900 self_token: self_,
901 }.into())
902 )
903 |
904 do_parse!(
905 pat: syn!(Pat) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800906 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800907 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400908 (ArgCaptured {
909 pat: pat,
910 ty: ty,
911 colon_token: colon,
912 }.into())
913 )
914 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800915 syn!(Type) => { FnArg::Ignored }
Michael Layzell92639a52017-06-01 00:07:44 -0400916 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800917
918 fn description() -> Option<&'static str> {
919 Some("function argument")
920 }
Alex Crichton954046c2017-05-30 21:49:42 -0700921 }
David Tolnay62f374c2016-10-02 13:37:00 -0700922
David Tolnay4c614be2017-11-10 00:02:38 -0800923 impl_synom!(ItemMod "mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500924 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700925 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800926 mod_: keyword!(mod) >>
David Tolnay570695e2017-06-03 16:15:13 -0700927 ident: syn!(Ident) >>
928 content_semi: alt!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800929 punct!(;) => {|semi| (
David Tolnay570695e2017-06-03 16:15:13 -0700930 Vec::new(),
931 None,
932 Some(semi),
933 )}
David Tolnay37d10332016-10-13 20:51:04 -0700934 |
Alex Crichton954046c2017-05-30 21:49:42 -0700935 braces!(
David Tolnay7b8009b2016-10-25 22:36:00 -0700936 tuple!(
David Tolnay2c136452017-12-27 14:13:32 -0500937 many0!(Attribute::parse_inner),
938 many0!(Item::parse)
Michael Layzell416724e2017-05-24 21:12:34 -0400939 )
David Tolnay8875fca2017-12-31 13:52:37 -0500940 ) => {|(brace, (inner_attrs, items))| (
David Tolnay570695e2017-06-03 16:15:13 -0700941 inner_attrs,
942 Some((brace, items)),
943 None,
944 )}
David Tolnay37d10332016-10-13 20:51:04 -0700945 ) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800946 (ItemMod {
David Tolnay570695e2017-06-03 16:15:13 -0700947 attrs: {
948 let mut attrs = outer_attrs;
949 attrs.extend(content_semi.0);
950 attrs
David Tolnay7b8009b2016-10-25 22:36:00 -0700951 },
David Tolnayc6b55bc2017-11-09 22:48:38 -0800952 vis: vis,
953 mod_token: mod_,
954 ident: ident,
955 content: content_semi.1,
956 semi: content_semi.2,
David Tolnay4c614be2017-11-10 00:02:38 -0800957 })
David Tolnay35902302016-10-06 01:11:08 -0700958 ));
959
David Tolnay4c614be2017-11-10 00:02:38 -0800960 impl_synom!(ItemForeignMod "foreign mod item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500961 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700962 abi: syn!(Abi) >>
David Tolnay2c136452017-12-27 14:13:32 -0500963 items: braces!(many0!(ForeignItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -0800964 (ItemForeignMod {
David Tolnay35902302016-10-06 01:11:08 -0700965 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -0800966 abi: abi,
David Tolnay8875fca2017-12-31 13:52:37 -0500967 brace_token: items.0,
968 items: items.1,
David Tolnay4c614be2017-11-10 00:02:38 -0800969 })
David Tolnay35902302016-10-06 01:11:08 -0700970 ));
971
David Tolnay8894f602017-11-11 12:11:04 -0800972 impl_synom!(ForeignItem "foreign item" alt!(
973 syn!(ForeignItemFn) => { ForeignItem::Fn }
974 |
975 syn!(ForeignItemStatic) => { ForeignItem::Static }
David Tolnay199bcbb2017-11-12 10:33:52 -0800976 |
977 syn!(ForeignItemType) => { ForeignItem::Type }
David Tolnay8894f602017-11-11 12:11:04 -0800978 ));
David Tolnay35902302016-10-06 01:11:08 -0700979
David Tolnay8894f602017-11-11 12:11:04 -0800980 impl_synom!(ForeignItemFn "foreign function" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500981 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700982 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800983 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -0700984 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700985 generics: syn!(Generics) >>
986 inputs: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500987 args: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500988 variadic: option!(cond_reduce!(args.empty_or_trailing(), punct!(...))) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700989 (args, variadic)
990 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800991 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -0500992 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800993 semi: punct!(;) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700994 ({
David Tolnay8875fca2017-12-31 13:52:37 -0500995 let (parens, (inputs, variadic)) = inputs;
David Tolnay8894f602017-11-11 12:11:04 -0800996 ForeignItemFn {
David Tolnay570695e2017-06-03 16:15:13 -0700997 ident: ident,
Alex Crichton954046c2017-05-30 21:49:42 -0700998 attrs: attrs,
999 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001000 decl: Box::new(FnDecl {
1001 fn_token: fn_,
1002 paren_token: parens,
1003 inputs: inputs,
David Tolnayd2836e22017-12-27 23:13:00 -05001004 variadic: variadic,
David Tolnay8894f602017-11-11 12:11:04 -08001005 output: ret,
1006 generics: Generics {
1007 where_clause: where_clause,
1008 .. generics
1009 },
1010 }),
Alex Crichton954046c2017-05-30 21:49:42 -07001011 vis: vis,
1012 }
David Tolnay35902302016-10-06 01:11:08 -07001013 })
1014 ));
1015
David Tolnay8894f602017-11-11 12:11:04 -08001016 impl_synom!(ForeignItemStatic "foreign static" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001017 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001018 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001019 static_: keyword!(static) >>
David Tolnay24237fb2017-12-29 02:15:26 -05001020 mutability: option!(keyword!(mut)) >>
David Tolnay570695e2017-06-03 16:15:13 -07001021 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001022 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001023 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001024 semi: punct!(;) >>
David Tolnay8894f602017-11-11 12:11:04 -08001025 (ForeignItemStatic {
David Tolnay570695e2017-06-03 16:15:13 -07001026 ident: ident,
David Tolnay35902302016-10-06 01:11:08 -07001027 attrs: attrs,
Alex Crichton954046c2017-05-30 21:49:42 -07001028 semi_token: semi,
David Tolnay8894f602017-11-11 12:11:04 -08001029 ty: Box::new(ty),
David Tolnay24237fb2017-12-29 02:15:26 -05001030 mutability: mutability,
David Tolnay8894f602017-11-11 12:11:04 -08001031 static_token: static_,
1032 colon_token: colon,
David Tolnay35902302016-10-06 01:11:08 -07001033 vis: vis,
1034 })
1035 ));
1036
David Tolnay199bcbb2017-11-12 10:33:52 -08001037 impl_synom!(ForeignItemType "foreign type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001038 attrs: many0!(Attribute::parse_outer) >>
David Tolnay199bcbb2017-11-12 10:33:52 -08001039 vis: syn!(Visibility) >>
1040 type_: keyword!(type) >>
1041 ident: syn!(Ident) >>
1042 semi: punct!(;) >>
1043 (ForeignItemType {
1044 attrs: attrs,
1045 vis: vis,
1046 type_token: type_,
1047 ident: ident,
1048 semi_token: semi,
1049 })
1050 ));
1051
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001052 impl_synom!(ItemType "type item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001053 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001054 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001055 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001056 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001057 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001058 where_clause: option!(syn!(WhereClause)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001059 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001060 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001061 semi: punct!(;) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001062 (ItemType {
David Tolnay3cf52982016-10-01 17:11:37 -07001063 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001064 vis: vis,
1065 type_token: type_,
1066 ident: ident,
1067 generics: Generics {
1068 where_clause: where_clause,
1069 ..generics
1070 },
1071 eq_token: eq,
1072 ty: Box::new(ty),
1073 semi_token: semi,
David Tolnay4c614be2017-11-10 00:02:38 -08001074 })
David Tolnay3cf52982016-10-01 17:11:37 -07001075 ));
1076
David Tolnay4c614be2017-11-10 00:02:38 -08001077 impl_synom!(ItemStruct "struct item" switch!(
1078 map!(syn!(DeriveInput), Into::into),
1079 Item::Struct(item) => value!(item)
1080 |
1081 _ => reject!()
1082 ));
David Tolnay42602292016-10-01 22:25:45 -07001083
David Tolnay4c614be2017-11-10 00:02:38 -08001084 impl_synom!(ItemEnum "enum item" switch!(
1085 map!(syn!(DeriveInput), Into::into),
1086 Item::Enum(item) => value!(item)
1087 |
1088 _ => reject!()
1089 ));
1090
1091 impl_synom!(ItemUnion "union item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001092 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001093 vis: syn!(Visibility) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001094 union_: keyword!(union) >>
David Tolnay570695e2017-06-03 16:15:13 -07001095 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001096 generics: syn!(Generics) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001097 where_clause: option!(syn!(WhereClause)) >>
David Tolnaye3d41b72017-12-31 15:24:00 -05001098 fields: syn!(FieldsNamed) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001099 (ItemUnion {
David Tolnay2f9fa632016-10-03 22:08:48 -07001100 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001101 vis: vis,
1102 union_token: union_,
1103 ident: ident,
1104 generics: Generics {
1105 where_clause: where_clause,
1106 .. generics
1107 },
David Tolnaye3d41b72017-12-31 15:24:00 -05001108 fields: fields,
David Tolnay4c614be2017-11-10 00:02:38 -08001109 })
David Tolnay2f9fa632016-10-03 22:08:48 -07001110 ));
1111
David Tolnay4c614be2017-11-10 00:02:38 -08001112 impl_synom!(ItemTrait "trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001113 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001114 vis: syn!(Visibility) >>
David Tolnay9b258702017-12-29 02:24:41 -05001115 unsafety: option!(keyword!(unsafe)) >>
Nika Layzell0dc6e632017-11-18 12:55:25 -05001116 auto_: option!(keyword!(auto)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001117 trait_: keyword!(trait) >>
David Tolnay570695e2017-06-03 16:15:13 -07001118 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001119 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001120 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001121 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001122 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001123 body: braces!(many0!(TraitItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001124 (ItemTrait {
David Tolnay0aecb732016-10-03 23:03:50 -07001125 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001126 vis: vis,
1127 unsafety: unsafety,
Nika Layzell0dc6e632017-11-18 12:55:25 -05001128 auto_token: auto_,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001129 trait_token: trait_,
1130 ident: ident,
1131 generics: Generics {
1132 where_clause: where_clause,
1133 .. generics
1134 },
1135 colon_token: colon,
1136 supertraits: bounds.unwrap_or_default(),
David Tolnay8875fca2017-12-31 13:52:37 -05001137 brace_token: body.0,
1138 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001139 })
David Tolnay0aecb732016-10-03 23:03:50 -07001140 ));
1141
David Tolnay03342952017-12-29 11:52:00 -05001142 fn grab_cursor(cursor: Cursor) -> PResult<Cursor> {
1143 Ok((cursor, cursor))
1144 }
1145
1146 named!(deprecated_default_impl -> ItemVerbatim, do_parse!(
1147 begin: call!(grab_cursor) >>
1148 many0!(Attribute::parse_outer) >>
1149 option!(keyword!(unsafe)) >>
1150 keyword!(impl) >>
1151 syn!(Path) >>
1152 keyword!(for) >>
1153 punct!(..) >>
1154 braces!(epsilon!()) >>
1155 end: call!(grab_cursor) >>
1156 ({
David Tolnay61037c62018-01-05 16:21:03 -08001157 let tts = begin.token_stream().into_iter().collect::<Vec<_>>();
David Tolnay03342952017-12-29 11:52:00 -05001158 let len = tts.len() - end.token_stream().into_iter().count();
1159 ItemVerbatim {
1160 tts: tts.into_iter().take(len).collect(),
1161 }
David Tolnay4c614be2017-11-10 00:02:38 -08001162 })
David Tolnayf94e2362016-10-04 00:29:51 -07001163 ));
1164
David Tolnayda705bd2017-11-10 21:58:05 -08001165 impl_synom!(TraitItem "trait item" alt!(
1166 syn!(TraitItemConst) => { TraitItem::Const }
1167 |
1168 syn!(TraitItemMethod) => { TraitItem::Method }
1169 |
1170 syn!(TraitItemType) => { TraitItem::Type }
1171 |
David Tolnaydecf28d2017-11-11 11:56:45 -08001172 syn!(TraitItemMacro) => { TraitItem::Macro }
David Tolnayda705bd2017-11-10 21:58:05 -08001173 ));
David Tolnay0aecb732016-10-03 23:03:50 -07001174
David Tolnayda705bd2017-11-10 21:58:05 -08001175 impl_synom!(TraitItemConst "const trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001176 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001177 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001178 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001179 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001180 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001181 default: option!(tuple!(punct!(=), syn!(Expr))) >>
1182 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001183 (TraitItemConst {
David Tolnay0aecb732016-10-03 23:03:50 -07001184 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001185 const_token: const_,
1186 ident: ident,
1187 colon_token: colon,
1188 ty: ty,
1189 default: default,
1190 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001191 })
1192 ));
1193
David Tolnayda705bd2017-11-10 21:58:05 -08001194 impl_synom!(TraitItemMethod "method trait item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001195 outer_attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001196 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001197 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001198 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001199 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001200 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001201 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001202 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001203 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001204 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001205 body: option!(braces!(
David Tolnay2c136452017-12-27 14:13:32 -05001206 tuple!(many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001207 call!(Block::parse_within))
David Tolnay5859df12016-10-29 22:49:54 -07001208 )) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001209 semi: cond!(body.is_none(), punct!(;)) >>
David Tolnay5859df12016-10-29 22:49:54 -07001210 ({
1211 let (inner_attrs, stmts) = match body {
David Tolnay8875fca2017-12-31 13:52:37 -05001212 Some((b, (inner_attrs, stmts))) => (inner_attrs, Some((stmts, b))),
David Tolnay5859df12016-10-29 22:49:54 -07001213 None => (Vec::new(), None),
1214 };
David Tolnayda705bd2017-11-10 21:58:05 -08001215 TraitItemMethod {
David Tolnay5859df12016-10-29 22:49:54 -07001216 attrs: {
1217 let mut attrs = outer_attrs;
1218 attrs.extend(inner_attrs);
1219 attrs
David Tolnay0aecb732016-10-03 23:03:50 -07001220 },
David Tolnayda705bd2017-11-10 21:58:05 -08001221 sig: MethodSig {
1222 constness: constness,
1223 unsafety: unsafety,
1224 abi: abi,
1225 ident: ident,
1226 decl: FnDecl {
David Tolnay8875fca2017-12-31 13:52:37 -05001227 inputs: inputs.1,
David Tolnayda705bd2017-11-10 21:58:05 -08001228 output: ret,
David Tolnayda705bd2017-11-10 21:58:05 -08001229 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001230 paren_token: inputs.0,
David Tolnayd2836e22017-12-27 23:13:00 -05001231 variadic: None,
David Tolnayda705bd2017-11-10 21:58:05 -08001232 generics: Generics {
1233 where_clause: where_clause,
1234 .. generics
David Tolnay5859df12016-10-29 22:49:54 -07001235 },
1236 },
David Tolnayda705bd2017-11-10 21:58:05 -08001237 },
1238 default: stmts.map(|stmts| {
1239 Block {
1240 stmts: stmts.0,
1241 brace_token: stmts.1,
1242 }
1243 }),
1244 semi_token: semi,
David Tolnay5859df12016-10-29 22:49:54 -07001245 }
David Tolnay0aecb732016-10-03 23:03:50 -07001246 })
1247 ));
1248
David Tolnayda705bd2017-11-10 21:58:05 -08001249 impl_synom!(TraitItemType "trait item type" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001250 attrs: many0!(Attribute::parse_outer) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001251 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001252 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001253 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001254 colon: option!(punct!(:)) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001255 bounds: cond!(colon.is_some(), Punctuated::parse_separated_nonempty) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001256 where_clause: option!(syn!(WhereClause)) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001257 default: option!(tuple!(punct!(=), syn!(Type))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001258 semi: punct!(;) >>
David Tolnayda705bd2017-11-10 21:58:05 -08001259 (TraitItemType {
David Tolnay0aecb732016-10-03 23:03:50 -07001260 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001261 type_token: type_,
1262 ident: ident,
Nika Layzell0183ca32017-12-05 15:24:01 -05001263 generics: Generics {
1264 where_clause: where_clause,
1265 .. generics
1266 },
David Tolnayda705bd2017-11-10 21:58:05 -08001267 colon_token: colon,
1268 bounds: bounds.unwrap_or_default(),
1269 default: default,
1270 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001271 })
1272 ));
1273
David Tolnaydecf28d2017-11-11 11:56:45 -08001274 impl_synom!(TraitItemMacro "trait item macro" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001275 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001276 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001277 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001278 (TraitItemMacro {
David Tolnay0aecb732016-10-03 23:03:50 -07001279 attrs: attrs,
David Tolnayda705bd2017-11-10 21:58:05 -08001280 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001281 semi_token: semi,
David Tolnay0aecb732016-10-03 23:03:50 -07001282 })
1283 ));
1284
David Tolnay4c614be2017-11-10 00:02:38 -08001285 impl_synom!(ItemImpl "impl item" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001286 attrs: many0!(Attribute::parse_outer) >>
David Tolnay360a6342017-12-29 02:22:11 -05001287 defaultness: option!(keyword!(default)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001288 unsafety: option!(keyword!(unsafe)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001289 impl_: keyword!(impl) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001290 generics: syn!(Generics) >>
David Tolnay4c9be372016-10-06 00:47:37 -07001291 polarity_path: alt!(
1292 do_parse!(
David Tolnay360a6342017-12-29 02:22:11 -05001293 polarity: option!(punct!(!)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001294 path: syn!(Path) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001295 for_: keyword!(for) >>
David Tolnay570695e2017-06-03 16:15:13 -07001296 (Some((polarity, path, for_)))
David Tolnay4c9be372016-10-06 00:47:37 -07001297 )
1298 |
David Tolnay570695e2017-06-03 16:15:13 -07001299 epsilon!() => { |_| None }
David Tolnay4c9be372016-10-06 00:47:37 -07001300 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001301 self_ty: syn!(Type) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001302 where_clause: option!(syn!(WhereClause)) >>
David Tolnay2c136452017-12-27 14:13:32 -05001303 body: braces!(many0!(ImplItem::parse)) >>
David Tolnay4c614be2017-11-10 00:02:38 -08001304 (ItemImpl {
David Tolnay4c9be372016-10-06 00:47:37 -07001305 attrs: attrs,
David Tolnayc6b55bc2017-11-09 22:48:38 -08001306 defaultness: defaultness,
1307 unsafety: unsafety,
1308 impl_token: impl_,
1309 generics: Generics {
1310 where_clause: where_clause,
1311 .. generics
1312 },
1313 trait_: polarity_path,
1314 self_ty: Box::new(self_ty),
David Tolnay8875fca2017-12-31 13:52:37 -05001315 brace_token: body.0,
1316 items: body.1,
David Tolnay4c614be2017-11-10 00:02:38 -08001317 })
David Tolnay4c9be372016-10-06 00:47:37 -07001318 ));
1319
David Tolnay857628c2017-11-11 12:25:31 -08001320 impl_synom!(ImplItem "item in impl block" alt!(
1321 syn!(ImplItemConst) => { ImplItem::Const }
1322 |
1323 syn!(ImplItemMethod) => { ImplItem::Method }
1324 |
1325 syn!(ImplItemType) => { ImplItem::Type }
1326 |
1327 syn!(ImplItemMacro) => { ImplItem::Macro }
1328 ));
David Tolnay4c9be372016-10-06 00:47:37 -07001329
David Tolnay857628c2017-11-11 12:25:31 -08001330 impl_synom!(ImplItemConst "const item in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001331 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001332 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001333 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001334 const_: keyword!(const) >>
David Tolnay570695e2017-06-03 16:15:13 -07001335 ident: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001336 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001337 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001338 eq: punct!(=) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001339 value: syn!(Expr) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001340 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001341 (ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001342 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001343 vis: vis,
1344 defaultness: defaultness,
1345 const_token: const_,
1346 ident: ident,
1347 colon_token: colon,
1348 ty: ty,
1349 eq_token: eq,
1350 expr: value,
1351 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001352 })
1353 ));
1354
David Tolnay857628c2017-11-11 12:25:31 -08001355 impl_synom!(ImplItemMethod "method in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001356 outer_attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001357 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001358 defaultness: option!(keyword!(default)) >>
1359 constness: option!(keyword!(const)) >>
David Tolnay9b258702017-12-29 02:24:41 -05001360 unsafety: option!(keyword!(unsafe)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001361 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001362 fn_: keyword!(fn) >>
David Tolnay570695e2017-06-03 16:15:13 -07001363 ident: syn!(Ident) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001364 generics: syn!(Generics) >>
David Tolnayf2cfd722017-12-31 18:02:51 -05001365 inputs: parens!(Punctuated::parse_terminated) >>
David Tolnayf93b90d2017-11-11 19:21:26 -08001366 ret: syn!(ReturnType) >>
David Tolnayac997dd2017-12-27 23:18:22 -05001367 where_clause: option!(syn!(WhereClause)) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001368 inner_attrs_stmts: braces!(tuple!(
David Tolnay2c136452017-12-27 14:13:32 -05001369 many0!(Attribute::parse_inner),
Alex Crichton954046c2017-05-30 21:49:42 -07001370 call!(Block::parse_within)
Michael Layzell416724e2017-05-24 21:12:34 -04001371 )) >>
David Tolnay857628c2017-11-11 12:25:31 -08001372 (ImplItemMethod {
David Tolnay3b9783a2016-10-29 22:37:09 -07001373 attrs: {
1374 let mut attrs = outer_attrs;
David Tolnay8875fca2017-12-31 13:52:37 -05001375 attrs.extend((inner_attrs_stmts.1).0);
David Tolnay3b9783a2016-10-29 22:37:09 -07001376 attrs
1377 },
David Tolnay857628c2017-11-11 12:25:31 -08001378 vis: vis,
1379 defaultness: defaultness,
1380 sig: MethodSig {
1381 constness: constness,
1382 unsafety: unsafety,
1383 abi: abi,
1384 ident: ident,
1385 decl: FnDecl {
1386 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -05001387 paren_token: inputs.0,
1388 inputs: inputs.1,
David Tolnay857628c2017-11-11 12:25:31 -08001389 output: ret,
David Tolnay857628c2017-11-11 12:25:31 -08001390 generics: Generics {
1391 where_clause: where_clause,
1392 .. generics
David Tolnay4c9be372016-10-06 00:47:37 -07001393 },
David Tolnayd2836e22017-12-27 23:13:00 -05001394 variadic: None,
David Tolnay4c9be372016-10-06 00:47:37 -07001395 },
David Tolnay857628c2017-11-11 12:25:31 -08001396 },
1397 block: Block {
David Tolnay8875fca2017-12-31 13:52:37 -05001398 brace_token: inner_attrs_stmts.0,
1399 stmts: (inner_attrs_stmts.1).1,
David Tolnay857628c2017-11-11 12:25:31 -08001400 },
David Tolnay4c9be372016-10-06 00:47:37 -07001401 })
1402 ));
1403
David Tolnay857628c2017-11-11 12:25:31 -08001404 impl_synom!(ImplItemType "type in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001405 attrs: many0!(Attribute::parse_outer) >>
Alex Crichton954046c2017-05-30 21:49:42 -07001406 vis: syn!(Visibility) >>
David Tolnay360a6342017-12-29 02:22:11 -05001407 defaultness: option!(keyword!(default)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001408 type_: keyword!(type) >>
David Tolnay570695e2017-06-03 16:15:13 -07001409 ident: syn!(Ident) >>
Nika Layzell591528a2017-12-05 12:47:37 -05001410 generics: syn!(Generics) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001411 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001412 ty: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -08001413 semi: punct!(;) >>
David Tolnay857628c2017-11-11 12:25:31 -08001414 (ImplItemType {
David Tolnay4c9be372016-10-06 00:47:37 -07001415 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001416 vis: vis,
1417 defaultness: defaultness,
1418 type_token: type_,
1419 ident: ident,
Nika Layzell591528a2017-12-05 12:47:37 -05001420 generics: generics,
David Tolnay857628c2017-11-11 12:25:31 -08001421 eq_token: eq,
1422 ty: ty,
1423 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001424 })
1425 ));
1426
David Tolnay857628c2017-11-11 12:25:31 -08001427 impl_synom!(ImplItemMacro "macro in impl block" do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -05001428 attrs: many0!(Attribute::parse_outer) >>
David Tolnaydecf28d2017-11-11 11:56:45 -08001429 mac: syn!(Macro) >>
David Tolnayab919512017-12-30 23:31:51 -05001430 semi: cond!(!is_brace(&mac.delimiter), punct!(;)) >>
David Tolnay857628c2017-11-11 12:25:31 -08001431 (ImplItemMacro {
David Tolnay4c9be372016-10-06 00:47:37 -07001432 attrs: attrs,
David Tolnay857628c2017-11-11 12:25:31 -08001433 mac: mac,
David Tolnay57292da2017-12-27 21:03:33 -05001434 semi_token: semi,
David Tolnay4c9be372016-10-06 00:47:37 -07001435 })
1436 ));
1437
David Tolnayab919512017-12-30 23:31:51 -05001438 fn is_brace(delimiter: &MacroDelimiter) -> bool {
1439 match *delimiter {
1440 MacroDelimiter::Brace(_) => true,
1441 MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => false,
David Tolnay57292da2017-12-27 21:03:33 -05001442 }
1443 }
David Tolnayedf2b992016-09-23 20:43:45 -07001444}
David Tolnay4a51dc72016-10-01 00:40:31 -07001445
1446#[cfg(feature = "printing")]
1447mod printing {
1448 use super::*;
1449 use attr::FilterAttrs;
David Tolnay51382052017-12-27 13:46:21 -05001450 use quote::{ToTokens, Tokens};
David Tolnay4a51dc72016-10-01 00:40:31 -07001451
David Tolnay1bfa7332017-11-11 12:41:20 -08001452 impl ToTokens for ItemExternCrate {
David Tolnay4a51dc72016-10-01 00:40:31 -07001453 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001454 tokens.append_all(self.attrs.outer());
1455 self.vis.to_tokens(tokens);
1456 self.extern_token.to_tokens(tokens);
1457 self.crate_token.to_tokens(tokens);
1458 self.ident.to_tokens(tokens);
1459 if let Some((ref as_token, ref rename)) = self.rename {
1460 as_token.to_tokens(tokens);
1461 rename.to_tokens(tokens);
1462 }
1463 self.semi_token.to_tokens(tokens);
1464 }
1465 }
1466
1467 impl ToTokens for ItemUse {
1468 fn to_tokens(&self, tokens: &mut Tokens) {
1469 tokens.append_all(self.attrs.outer());
1470 self.vis.to_tokens(tokens);
1471 self.use_token.to_tokens(tokens);
David Tolnay5f332a92017-12-26 00:42:45 -05001472 self.leading_colon.to_tokens(tokens);
1473 self.prefix.to_tokens(tokens);
1474 self.tree.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001475 self.semi_token.to_tokens(tokens);
1476 }
1477 }
1478
1479 impl ToTokens for ItemStatic {
1480 fn to_tokens(&self, tokens: &mut Tokens) {
1481 tokens.append_all(self.attrs.outer());
1482 self.vis.to_tokens(tokens);
1483 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001484 self.mutability.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001485 self.ident.to_tokens(tokens);
1486 self.colon_token.to_tokens(tokens);
1487 self.ty.to_tokens(tokens);
1488 self.eq_token.to_tokens(tokens);
1489 self.expr.to_tokens(tokens);
1490 self.semi_token.to_tokens(tokens);
1491 }
1492 }
1493
1494 impl ToTokens for ItemConst {
1495 fn to_tokens(&self, tokens: &mut Tokens) {
1496 tokens.append_all(self.attrs.outer());
1497 self.vis.to_tokens(tokens);
1498 self.const_token.to_tokens(tokens);
1499 self.ident.to_tokens(tokens);
1500 self.colon_token.to_tokens(tokens);
1501 self.ty.to_tokens(tokens);
1502 self.eq_token.to_tokens(tokens);
1503 self.expr.to_tokens(tokens);
1504 self.semi_token.to_tokens(tokens);
1505 }
1506 }
1507
1508 impl ToTokens for ItemFn {
1509 fn to_tokens(&self, tokens: &mut Tokens) {
1510 tokens.append_all(self.attrs.outer());
1511 self.vis.to_tokens(tokens);
1512 self.constness.to_tokens(tokens);
1513 self.unsafety.to_tokens(tokens);
1514 self.abi.to_tokens(tokens);
1515 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1516 self.block.brace_token.surround(tokens, |tokens| {
1517 tokens.append_all(self.attrs.inner());
1518 tokens.append_all(&self.block.stmts);
1519 });
1520 }
1521 }
1522
1523 impl ToTokens for ItemMod {
1524 fn to_tokens(&self, tokens: &mut Tokens) {
1525 tokens.append_all(self.attrs.outer());
1526 self.vis.to_tokens(tokens);
1527 self.mod_token.to_tokens(tokens);
1528 self.ident.to_tokens(tokens);
1529 if let Some((ref brace, ref items)) = self.content {
1530 brace.surround(tokens, |tokens| {
1531 tokens.append_all(self.attrs.inner());
1532 tokens.append_all(items);
1533 });
1534 } else {
1535 TokensOrDefault(&self.semi).to_tokens(tokens);
1536 }
1537 }
1538 }
1539
1540 impl ToTokens for ItemForeignMod {
1541 fn to_tokens(&self, tokens: &mut Tokens) {
1542 tokens.append_all(self.attrs.outer());
1543 self.abi.to_tokens(tokens);
1544 self.brace_token.surround(tokens, |tokens| {
1545 tokens.append_all(&self.items);
1546 });
1547 }
1548 }
1549
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001550 impl ToTokens for ItemType {
David Tolnay1bfa7332017-11-11 12:41:20 -08001551 fn to_tokens(&self, tokens: &mut Tokens) {
1552 tokens.append_all(self.attrs.outer());
1553 self.vis.to_tokens(tokens);
1554 self.type_token.to_tokens(tokens);
1555 self.ident.to_tokens(tokens);
1556 self.generics.to_tokens(tokens);
1557 self.generics.where_clause.to_tokens(tokens);
1558 self.eq_token.to_tokens(tokens);
1559 self.ty.to_tokens(tokens);
1560 self.semi_token.to_tokens(tokens);
1561 }
1562 }
1563
1564 impl ToTokens for ItemEnum {
1565 fn to_tokens(&self, tokens: &mut Tokens) {
1566 tokens.append_all(self.attrs.outer());
1567 self.vis.to_tokens(tokens);
1568 self.enum_token.to_tokens(tokens);
1569 self.ident.to_tokens(tokens);
1570 self.generics.to_tokens(tokens);
1571 self.generics.where_clause.to_tokens(tokens);
1572 self.brace_token.surround(tokens, |tokens| {
1573 self.variants.to_tokens(tokens);
1574 });
1575 }
1576 }
1577
1578 impl ToTokens for ItemStruct {
1579 fn to_tokens(&self, tokens: &mut Tokens) {
1580 tokens.append_all(self.attrs.outer());
1581 self.vis.to_tokens(tokens);
1582 self.struct_token.to_tokens(tokens);
1583 self.ident.to_tokens(tokens);
1584 self.generics.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001585 match self.fields {
1586 Fields::Named(ref fields) => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001587 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001588 fields.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001589 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001590 Fields::Unnamed(ref fields) => {
1591 fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001592 self.generics.where_clause.to_tokens(tokens);
1593 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay4a057422016-10-08 00:02:31 -07001594 }
David Tolnaye3d41b72017-12-31 15:24:00 -05001595 Fields::Unit => {
David Tolnay1bfa7332017-11-11 12:41:20 -08001596 self.generics.where_clause.to_tokens(tokens);
1597 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnay47a877c2016-10-01 16:50:55 -07001598 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001599 }
1600 }
1601 }
1602
1603 impl ToTokens for ItemUnion {
1604 fn to_tokens(&self, tokens: &mut Tokens) {
1605 tokens.append_all(self.attrs.outer());
1606 self.vis.to_tokens(tokens);
1607 self.union_token.to_tokens(tokens);
1608 self.ident.to_tokens(tokens);
1609 self.generics.to_tokens(tokens);
1610 self.generics.where_clause.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -05001611 self.fields.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001612 }
1613 }
1614
1615 impl ToTokens for ItemTrait {
1616 fn to_tokens(&self, tokens: &mut Tokens) {
1617 tokens.append_all(self.attrs.outer());
1618 self.vis.to_tokens(tokens);
1619 self.unsafety.to_tokens(tokens);
Nika Layzell0dc6e632017-11-18 12:55:25 -05001620 self.auto_token.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001621 self.trait_token.to_tokens(tokens);
1622 self.ident.to_tokens(tokens);
1623 self.generics.to_tokens(tokens);
1624 if !self.supertraits.is_empty() {
1625 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1626 self.supertraits.to_tokens(tokens);
1627 }
1628 self.generics.where_clause.to_tokens(tokens);
1629 self.brace_token.surround(tokens, |tokens| {
1630 tokens.append_all(&self.items);
1631 });
1632 }
1633 }
1634
David Tolnay1bfa7332017-11-11 12:41:20 -08001635 impl ToTokens for ItemImpl {
1636 fn to_tokens(&self, tokens: &mut Tokens) {
1637 tokens.append_all(self.attrs.outer());
1638 self.defaultness.to_tokens(tokens);
1639 self.unsafety.to_tokens(tokens);
1640 self.impl_token.to_tokens(tokens);
1641 self.generics.to_tokens(tokens);
1642 if let Some((ref polarity, ref path, ref for_token)) = self.trait_ {
1643 polarity.to_tokens(tokens);
1644 path.to_tokens(tokens);
1645 for_token.to_tokens(tokens);
1646 }
1647 self.self_ty.to_tokens(tokens);
1648 self.generics.where_clause.to_tokens(tokens);
1649 self.brace_token.surround(tokens, |tokens| {
1650 tokens.append_all(&self.items);
1651 });
1652 }
1653 }
1654
1655 impl ToTokens for ItemMacro {
1656 fn to_tokens(&self, tokens: &mut Tokens) {
1657 tokens.append_all(self.attrs.outer());
1658 self.mac.path.to_tokens(tokens);
1659 self.mac.bang_token.to_tokens(tokens);
David Tolnay99a953d2017-11-11 12:51:43 -08001660 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001661 match self.mac.delimiter {
1662 MacroDelimiter::Paren(ref paren) => {
1663 paren.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1664 }
1665 MacroDelimiter::Brace(ref brace) => {
1666 brace.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1667 }
1668 MacroDelimiter::Bracket(ref bracket) => {
1669 bracket.surround(tokens, |tokens| self.mac.tts.to_tokens(tokens));
1670 }
1671 }
David Tolnay57292da2017-12-27 21:03:33 -05001672 self.semi_token.to_tokens(tokens);
David Tolnay4a51dc72016-10-01 00:40:31 -07001673 }
1674 }
David Tolnay42602292016-10-01 22:25:45 -07001675
David Tolnay500d8322017-12-18 00:32:51 -08001676 impl ToTokens for ItemMacro2 {
1677 fn to_tokens(&self, tokens: &mut Tokens) {
1678 tokens.append_all(self.attrs.outer());
1679 self.vis.to_tokens(tokens);
1680 self.macro_token.to_tokens(tokens);
1681 self.ident.to_tokens(tokens);
David Tolnayab919512017-12-30 23:31:51 -05001682 self.paren_token.surround(tokens, |tokens| {
1683 self.args.to_tokens(tokens);
1684 });
1685 self.brace_token.surround(tokens, |tokens| {
1686 self.body.to_tokens(tokens);
1687 });
David Tolnay500d8322017-12-18 00:32:51 -08001688 }
1689 }
1690
David Tolnay2ae520a2017-12-29 11:19:50 -05001691 impl ToTokens for ItemVerbatim {
1692 fn to_tokens(&self, tokens: &mut Tokens) {
1693 self.tts.to_tokens(tokens);
1694 }
1695 }
1696
David Tolnay5f332a92017-12-26 00:42:45 -05001697 impl ToTokens for UsePath {
David Tolnay4a057422016-10-08 00:02:31 -07001698 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay5f332a92017-12-26 00:42:45 -05001699 self.ident.to_tokens(tokens);
1700 if let Some((ref as_token, ref rename)) = self.rename {
1701 as_token.to_tokens(tokens);
1702 rename.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001703 }
David Tolnay4a057422016-10-08 00:02:31 -07001704 }
1705 }
1706
David Tolnay5f332a92017-12-26 00:42:45 -05001707 impl ToTokens for UseGlob {
Alex Crichton62a0a592017-05-22 13:58:53 -07001708 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001709 self.star_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001710 }
1711 }
1712
David Tolnay5f332a92017-12-26 00:42:45 -05001713 impl ToTokens for UseList {
Alex Crichton62a0a592017-05-22 13:58:53 -07001714 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001715 self.brace_token.surround(tokens, |tokens| {
1716 self.items.to_tokens(tokens);
1717 });
Alex Crichton62a0a592017-05-22 13:58:53 -07001718 }
1719 }
1720
David Tolnay1bfa7332017-11-11 12:41:20 -08001721 impl ToTokens for TraitItemConst {
David Tolnayca085422016-10-04 00:12:38 -07001722 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay1bfa7332017-11-11 12:41:20 -08001723 tokens.append_all(self.attrs.outer());
1724 self.const_token.to_tokens(tokens);
1725 self.ident.to_tokens(tokens);
1726 self.colon_token.to_tokens(tokens);
1727 self.ty.to_tokens(tokens);
1728 if let Some((ref eq_token, ref default)) = self.default {
1729 eq_token.to_tokens(tokens);
1730 default.to_tokens(tokens);
1731 }
1732 self.semi_token.to_tokens(tokens);
1733 }
1734 }
1735
1736 impl ToTokens for TraitItemMethod {
1737 fn to_tokens(&self, tokens: &mut Tokens) {
1738 tokens.append_all(self.attrs.outer());
1739 self.sig.to_tokens(tokens);
1740 match self.default {
1741 Some(ref block) => {
1742 block.brace_token.surround(tokens, |tokens| {
1743 tokens.append_all(self.attrs.inner());
1744 tokens.append_all(&block.stmts);
1745 });
David Tolnayca085422016-10-04 00:12:38 -07001746 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001747 None => {
1748 TokensOrDefault(&self.semi_token).to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001749 }
David Tolnay1bfa7332017-11-11 12:41:20 -08001750 }
1751 }
1752 }
1753
1754 impl ToTokens for TraitItemType {
1755 fn to_tokens(&self, tokens: &mut Tokens) {
1756 tokens.append_all(self.attrs.outer());
1757 self.type_token.to_tokens(tokens);
1758 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001759 self.generics.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001760 if !self.bounds.is_empty() {
1761 TokensOrDefault(&self.colon_token).to_tokens(tokens);
1762 self.bounds.to_tokens(tokens);
1763 }
Nika Layzell0183ca32017-12-05 15:24:01 -05001764 self.generics.where_clause.to_tokens(tokens);
David Tolnay1bfa7332017-11-11 12:41:20 -08001765 if let Some((ref eq_token, ref default)) = self.default {
1766 eq_token.to_tokens(tokens);
1767 default.to_tokens(tokens);
1768 }
1769 self.semi_token.to_tokens(tokens);
1770 }
1771 }
1772
1773 impl ToTokens for TraitItemMacro {
1774 fn to_tokens(&self, tokens: &mut Tokens) {
1775 tokens.append_all(self.attrs.outer());
1776 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001777 self.semi_token.to_tokens(tokens);
David Tolnayca085422016-10-04 00:12:38 -07001778 }
1779 }
1780
David Tolnay2ae520a2017-12-29 11:19:50 -05001781 impl ToTokens for TraitItemVerbatim {
1782 fn to_tokens(&self, tokens: &mut Tokens) {
1783 self.tts.to_tokens(tokens);
1784 }
1785 }
1786
David Tolnay857628c2017-11-11 12:25:31 -08001787 impl ToTokens for ImplItemConst {
David Tolnay4c9be372016-10-06 00:47:37 -07001788 fn to_tokens(&self, tokens: &mut Tokens) {
1789 tokens.append_all(self.attrs.outer());
David Tolnay857628c2017-11-11 12:25:31 -08001790 self.vis.to_tokens(tokens);
1791 self.defaultness.to_tokens(tokens);
1792 self.const_token.to_tokens(tokens);
1793 self.ident.to_tokens(tokens);
1794 self.colon_token.to_tokens(tokens);
1795 self.ty.to_tokens(tokens);
1796 self.eq_token.to_tokens(tokens);
1797 self.expr.to_tokens(tokens);
1798 self.semi_token.to_tokens(tokens);
1799 }
1800 }
1801
1802 impl ToTokens for ImplItemMethod {
1803 fn to_tokens(&self, tokens: &mut Tokens) {
1804 tokens.append_all(self.attrs.outer());
1805 self.vis.to_tokens(tokens);
1806 self.defaultness.to_tokens(tokens);
1807 self.sig.to_tokens(tokens);
1808 self.block.brace_token.surround(tokens, |tokens| {
1809 tokens.append_all(self.attrs.inner());
1810 tokens.append_all(&self.block.stmts);
1811 });
1812 }
1813 }
1814
1815 impl ToTokens for ImplItemType {
1816 fn to_tokens(&self, tokens: &mut Tokens) {
1817 tokens.append_all(self.attrs.outer());
1818 self.vis.to_tokens(tokens);
1819 self.defaultness.to_tokens(tokens);
1820 self.type_token.to_tokens(tokens);
1821 self.ident.to_tokens(tokens);
Nika Layzell591528a2017-12-05 12:47:37 -05001822 self.generics.to_tokens(tokens);
David Tolnay857628c2017-11-11 12:25:31 -08001823 self.eq_token.to_tokens(tokens);
1824 self.ty.to_tokens(tokens);
1825 self.semi_token.to_tokens(tokens);
1826 }
1827 }
1828
1829 impl ToTokens for ImplItemMacro {
1830 fn to_tokens(&self, tokens: &mut Tokens) {
1831 tokens.append_all(self.attrs.outer());
1832 self.mac.to_tokens(tokens);
David Tolnay57292da2017-12-27 21:03:33 -05001833 self.semi_token.to_tokens(tokens);
David Tolnay4c9be372016-10-06 00:47:37 -07001834 }
1835 }
1836
David Tolnay2ae520a2017-12-29 11:19:50 -05001837 impl ToTokens for ImplItemVerbatim {
1838 fn to_tokens(&self, tokens: &mut Tokens) {
1839 self.tts.to_tokens(tokens);
1840 }
1841 }
1842
David Tolnay8894f602017-11-11 12:11:04 -08001843 impl ToTokens for ForeignItemFn {
David Tolnay35902302016-10-06 01:11:08 -07001844 fn to_tokens(&self, tokens: &mut Tokens) {
1845 tokens.append_all(self.attrs.outer());
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001846 self.vis.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001847 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
1848 self.semi_token.to_tokens(tokens);
1849 }
1850 }
1851
1852 impl ToTokens for ForeignItemStatic {
1853 fn to_tokens(&self, tokens: &mut Tokens) {
1854 tokens.append_all(self.attrs.outer());
1855 self.vis.to_tokens(tokens);
1856 self.static_token.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001857 self.mutability.to_tokens(tokens);
David Tolnay8894f602017-11-11 12:11:04 -08001858 self.ident.to_tokens(tokens);
1859 self.colon_token.to_tokens(tokens);
1860 self.ty.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001861 self.semi_token.to_tokens(tokens);
1862 }
1863 }
1864
David Tolnay199bcbb2017-11-12 10:33:52 -08001865 impl ToTokens for ForeignItemType {
1866 fn to_tokens(&self, tokens: &mut Tokens) {
1867 tokens.append_all(self.attrs.outer());
1868 self.vis.to_tokens(tokens);
1869 self.type_token.to_tokens(tokens);
1870 self.ident.to_tokens(tokens);
1871 self.semi_token.to_tokens(tokens);
1872 }
1873 }
1874
David Tolnay2ae520a2017-12-29 11:19:50 -05001875 impl ToTokens for ForeignItemVerbatim {
1876 fn to_tokens(&self, tokens: &mut Tokens) {
1877 self.tts.to_tokens(tokens);
1878 }
1879 }
1880
David Tolnay570695e2017-06-03 16:15:13 -07001881 impl ToTokens for MethodSig {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001882 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay570695e2017-06-03 16:15:13 -07001883 self.constness.to_tokens(tokens);
1884 self.unsafety.to_tokens(tokens);
1885 self.abi.to_tokens(tokens);
1886 NamedDecl(&self.decl, self.ident).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001887 }
1888 }
1889
David Tolnay570695e2017-06-03 16:15:13 -07001890 struct NamedDecl<'a>(&'a FnDecl, Ident);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001891
1892 impl<'a> ToTokens for NamedDecl<'a> {
1893 fn to_tokens(&self, tokens: &mut Tokens) {
1894 self.0.fn_token.to_tokens(tokens);
1895 self.1.to_tokens(tokens);
1896 self.0.generics.to_tokens(tokens);
1897 self.0.paren_token.surround(tokens, |tokens| {
1898 self.0.inputs.to_tokens(tokens);
David Tolnayd2836e22017-12-27 23:13:00 -05001899 if self.0.variadic.is_some() && !self.0.inputs.empty_or_trailing() {
1900 <Token![,]>::default().to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001901 }
David Tolnayd2836e22017-12-27 23:13:00 -05001902 self.0.variadic.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001903 });
1904 self.0.output.to_tokens(tokens);
1905 self.0.generics.where_clause.to_tokens(tokens);
David Tolnay35902302016-10-06 01:11:08 -07001906 }
1907 }
1908
Alex Crichton62a0a592017-05-22 13:58:53 -07001909 impl ToTokens for ArgSelfRef {
David Tolnay62f374c2016-10-02 13:37:00 -07001910 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001911 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001912 self.lifetime.to_tokens(tokens);
David Tolnay24237fb2017-12-29 02:15:26 -05001913 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001914 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001915 }
1916 }
1917
1918 impl ToTokens for ArgSelf {
1919 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay24237fb2017-12-29 02:15:26 -05001920 self.mutability.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001921 self.self_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001922 }
1923 }
1924
1925 impl ToTokens for ArgCaptured {
1926 fn to_tokens(&self, tokens: &mut Tokens) {
1927 self.pat.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001928 self.colon_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -07001929 self.ty.to_tokens(tokens);
David Tolnay62f374c2016-10-02 13:37:00 -07001930 }
1931 }
David Tolnay4a51dc72016-10-01 00:40:31 -07001932}