David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 1 | use super::*; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2 | use delimited::Delimited; |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 3 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 4 | ast_enum_of_structs! { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 5 | /// Things that can appear directly inside of a module. |
| 6 | pub enum Item { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 7 | /// An `extern crate` item, with optional original crate name. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 8 | /// |
| 9 | /// E.g. `extern crate foo` or `extern crate foo_bar as foo` |
| 10 | pub ExternCrate(ItemExternCrate { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 11 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 12 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 13 | pub extern_token: Token![extern], |
| 14 | pub crate_token: Token![crate], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 15 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 16 | pub rename: Option<(Token![as], Ident)>, |
| 17 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 18 | }), |
| 19 | /// A use declaration (`use` or `pub use`) item. |
| 20 | /// |
| 21 | /// E.g. `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;` |
| 22 | pub Use(ItemUse { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 23 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 24 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 25 | pub use_token: Token![use], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 26 | pub path: Box<ViewPath>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 27 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 28 | }), |
| 29 | /// A static item (`static` or `pub static`). |
| 30 | /// |
| 31 | /// E.g. `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";` |
| 32 | pub Static(ItemStatic { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 33 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 34 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 35 | pub static_token: Token![static], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 36 | pub mutbl: Mutability, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 37 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 38 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 39 | pub ty: Box<Type>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 40 | pub eq_token: Token![=], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 41 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 42 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 43 | }), |
| 44 | /// A constant item (`const` or `pub const`). |
| 45 | /// |
| 46 | /// E.g. `const FOO: i32 = 42;` |
| 47 | pub Const(ItemConst { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 48 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 49 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 50 | pub const_token: Token![const], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 51 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 52 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 53 | pub ty: Box<Type>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 54 | pub eq_token: Token![=], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 55 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 56 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 57 | }), |
| 58 | /// A function declaration (`fn` or `pub fn`). |
| 59 | /// |
| 60 | /// E.g. `fn foo(bar: usize) -> usize { .. }` |
| 61 | pub Fn(ItemFn { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 62 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 63 | pub vis: Visibility, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 64 | pub constness: Constness, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 65 | pub unsafety: Unsafety, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 66 | pub abi: Option<Abi>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 67 | pub decl: Box<FnDecl>, |
| 68 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 69 | pub block: Box<Block>, |
| 70 | }), |
| 71 | /// A module declaration (`mod` or `pub mod`). |
| 72 | /// |
| 73 | /// E.g. `mod foo;` or `mod foo { .. }` |
| 74 | pub Mod(ItemMod { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 75 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 76 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 77 | pub mod_token: Token![mod], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 78 | pub ident: Ident, |
| 79 | pub content: Option<(tokens::Brace, Vec<Item>)>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 80 | pub semi: Option<Token![;]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 81 | }), |
| 82 | /// An external module (`extern` or `pub extern`). |
| 83 | /// |
| 84 | /// E.g. `extern {}` or `extern "C" {}` |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 85 | pub ForeignMod(ItemForeignMod { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 86 | pub attrs: Vec<Attribute>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 87 | pub abi: Abi, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 88 | pub brace_token: tokens::Brace, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 89 | pub items: Vec<ForeignItem>, |
| 90 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 91 | /// A type alias (`type` or `pub type`). |
| 92 | /// |
| 93 | /// E.g. `type Foo = Bar<u8>;` |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 94 | pub Type(ItemType { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 95 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 96 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 97 | pub type_token: Token![type], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 98 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 99 | pub generics: Generics, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 100 | pub eq_token: Token![=], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 101 | pub ty: Box<Type>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 102 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 103 | }), |
| 104 | /// An enum definition (`enum` or `pub enum`). |
| 105 | /// |
| 106 | /// E.g. `enum Foo<A, B> { C<A>, D<B> }` |
| 107 | pub Enum(ItemEnum { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 108 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 109 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 110 | pub enum_token: Token![enum], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 111 | pub ident: Ident, |
| 112 | pub generics: Generics, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 113 | pub brace_token: tokens::Brace, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 114 | pub variants: Delimited<Variant, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 115 | }), |
| 116 | /// A struct definition (`struct` or `pub struct`). |
| 117 | /// |
| 118 | /// E.g. `struct Foo<A> { x: A }` |
| 119 | pub Struct(ItemStruct { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 120 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 121 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 122 | pub struct_token: Token![struct], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 123 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 124 | pub generics: Generics, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 125 | pub data: VariantData, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 126 | pub semi_token: Option<Token![;]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 127 | }), |
| 128 | /// A union definition (`union` or `pub union`). |
| 129 | /// |
| 130 | /// E.g. `union Foo<A, B> { x: A, y: B }` |
| 131 | pub Union(ItemUnion { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 132 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 133 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 134 | pub union_token: Token![union], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 135 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 136 | pub generics: Generics, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 137 | pub data: VariantData, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 138 | }), |
| 139 | /// A Trait declaration (`trait` or `pub trait`). |
| 140 | /// |
| 141 | /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }` |
| 142 | pub Trait(ItemTrait { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 143 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 144 | pub vis: Visibility, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 145 | pub unsafety: Unsafety, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 146 | pub trait_token: Token![trait], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 147 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 148 | pub generics: Generics, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 149 | pub colon_token: Option<Token![:]>, |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 150 | pub supertraits: Delimited<TypeParamBound, Token![+]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 151 | pub brace_token: tokens::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 152 | pub items: Vec<TraitItem>, |
| 153 | }), |
| 154 | /// Default trait implementation. |
| 155 | /// |
| 156 | /// E.g. `impl Trait for .. {}` or `impl<T> Trait<T> for .. {}` |
| 157 | pub DefaultImpl(ItemDefaultImpl { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 158 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 159 | pub unsafety: Unsafety, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 160 | pub impl_token: Token![impl], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 161 | pub path: Path, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 162 | pub for_token: Token![for], |
| 163 | pub dot2_token: Token![..], |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 164 | pub brace_token: tokens::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 165 | }), |
| 166 | /// An implementation. |
| 167 | /// |
| 168 | /// E.g. `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }` |
| 169 | pub Impl(ItemImpl { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 170 | pub attrs: Vec<Attribute>, |
Alex Crichton | f3d9ccc | 2017-08-28 09:40:13 -0700 | [diff] [blame] | 171 | pub defaultness: Defaultness, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 172 | pub unsafety: Unsafety, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 173 | pub impl_token: Token![impl], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 174 | pub generics: Generics, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 175 | /// Trait this impl implements. |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 176 | pub trait_: Option<(ImplPolarity, Path, Token![for])>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 177 | /// The Self type of the impl. |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 178 | pub self_ty: Box<Type>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 179 | pub brace_token: tokens::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 180 | pub items: Vec<ImplItem>, |
| 181 | }), |
| 182 | /// A macro invocation (which includes macro definition). |
| 183 | /// |
| 184 | /// E.g. `macro_rules! foo { .. }` or `foo!(..)` |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 185 | pub Macro(ItemMacro { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 186 | pub attrs: Vec<Attribute>, |
David Tolnay | 99a953d | 2017-11-11 12:51:43 -0800 | [diff] [blame] | 187 | /// The `example` in `macro_rules! example { ... }`. |
| 188 | pub ident: Option<Ident>, |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 189 | pub mac: Macro, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 190 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 191 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 192 | } |
| 193 | |
David Tolnay | 0e83740 | 2016-12-22 17:25:55 -0500 | [diff] [blame] | 194 | impl From<DeriveInput> for Item { |
| 195 | fn from(input: DeriveInput) -> Item { |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 196 | match input.body { |
| 197 | Body::Enum(data) => { |
| 198 | Item::Enum(ItemEnum { |
| 199 | attrs: input.attrs, |
| 200 | vis: input.vis, |
| 201 | enum_token: data.enum_token, |
| 202 | ident: input.ident, |
| 203 | generics: input.generics, |
| 204 | brace_token: data.brace_token, |
| 205 | variants: data.variants, |
| 206 | }) |
| 207 | } |
| 208 | Body::Struct(data) => { |
| 209 | Item::Struct(ItemStruct { |
| 210 | attrs: input.attrs, |
| 211 | vis: input.vis, |
| 212 | struct_token: data.struct_token, |
| 213 | ident: input.ident, |
| 214 | generics: input.generics, |
| 215 | data: data.data, |
| 216 | semi_token: data.semi_token, |
| 217 | }) |
| 218 | } |
David Tolnay | 453cfd1 | 2016-10-23 11:00:14 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 223 | ast_enum_of_structs! { |
| 224 | pub enum ViewPath { |
| 225 | /// `foo::bar::baz as quux` |
| 226 | /// |
| 227 | /// or just |
| 228 | /// |
| 229 | /// `foo::bar::baz` (with `as baz` implicitly on the right) |
| 230 | pub Simple(PathSimple { |
| 231 | pub path: Path, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 232 | pub as_token: Option<Token![as]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 233 | pub rename: Option<Ident>, |
| 234 | }), |
| 235 | |
| 236 | /// `foo::bar::*` |
| 237 | pub Glob(PathGlob { |
| 238 | pub path: Path, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 239 | pub colon2_token: Option<Token![::]>, |
| 240 | pub star_token: Token![*], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 241 | }), |
| 242 | |
| 243 | /// `foo::bar::{a, b, c}` |
| 244 | pub List(PathList { |
| 245 | pub path: Path, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 246 | pub colon2_token: Token![::], |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 247 | pub brace_token: tokens::Brace, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 248 | pub items: Delimited<PathListItem, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 249 | }), |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | ast_struct! { |
| 254 | pub struct PathListItem { |
| 255 | pub name: Ident, |
| 256 | /// renamed in list, e.g. `use foo::{bar as baz};` |
| 257 | pub rename: Option<Ident>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 258 | pub as_token: Option<Token![as]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 263 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 264 | pub enum Constness { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 265 | Const(Token![const]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 266 | NotConst, |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 271 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 272 | pub enum Defaultness { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 273 | Default(Token![default]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 274 | Final, |
| 275 | } |
| 276 | } |
| 277 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 278 | ast_enum_of_structs! { |
| 279 | /// An item within an `extern` block |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 280 | pub enum ForeignItem { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 281 | /// A foreign function |
| 282 | pub Fn(ForeignItemFn { |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 283 | pub attrs: Vec<Attribute>, |
| 284 | pub vis: Visibility, |
| 285 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 286 | pub decl: Box<FnDecl>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 287 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 288 | }), |
| 289 | /// A foreign static item (`static ext: u8`) |
| 290 | pub Static(ForeignItemStatic { |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 291 | pub attrs: Vec<Attribute>, |
| 292 | pub vis: Visibility, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 293 | pub static_token: Token![static], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 294 | pub mutbl: Mutability, |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 295 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 296 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 297 | pub ty: Box<Type>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 298 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 299 | }), |
David Tolnay | 199bcbb | 2017-11-12 10:33:52 -0800 | [diff] [blame^] | 300 | /// A foreign type |
| 301 | pub Type(ForeignItemType { |
| 302 | pub attrs: Vec<Attribute>, |
| 303 | pub vis: Visibility, |
| 304 | pub type_token: Token![type], |
| 305 | pub ident: Ident, |
| 306 | pub semi_token: Token![;], |
| 307 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 308 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 309 | } |
| 310 | |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 311 | ast_enum_of_structs! { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 312 | /// Represents an item declaration within a trait declaration, |
| 313 | /// possibly including a default implementation. A trait item is |
| 314 | /// either required (meaning it doesn't have an implementation, just a |
| 315 | /// signature) or provided (meaning it has a default implementation). |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 316 | pub enum TraitItem { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 317 | pub Const(TraitItemConst { |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 318 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 319 | pub const_token: Token![const], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 320 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 321 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 322 | pub ty: Type, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 323 | pub default: Option<(Token![=], Expr)>, |
| 324 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 325 | }), |
| 326 | pub Method(TraitItemMethod { |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 327 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 328 | pub sig: MethodSig, |
| 329 | pub default: Option<Block>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 330 | pub semi_token: Option<Token![;]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 331 | }), |
| 332 | pub Type(TraitItemType { |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 333 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 334 | pub type_token: Token![type], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 335 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 336 | pub colon_token: Option<Token![:]>, |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 337 | pub bounds: Delimited<TypeParamBound, Token![+]>, |
| 338 | pub default: Option<(Token![=], Type)>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 339 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 340 | }), |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 341 | pub Macro(TraitItemMacro { |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 342 | pub attrs: Vec<Attribute>, |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 343 | pub mac: Macro, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 344 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 345 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 349 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 350 | pub enum ImplPolarity { |
| 351 | /// `impl Trait for Type` |
| 352 | Positive, |
| 353 | /// `impl !Trait for Type` |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 354 | Negative(Token![!]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 358 | ast_enum_of_structs! { |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 359 | pub enum ImplItem { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 360 | pub Const(ImplItemConst { |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 361 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 362 | pub vis: Visibility, |
| 363 | pub defaultness: Defaultness, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 364 | pub const_token: Token![const], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 365 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 366 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 367 | pub ty: Type, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 368 | pub eq_token: Token![=], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 369 | pub expr: Expr, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 370 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 371 | }), |
| 372 | pub Method(ImplItemMethod { |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 373 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 374 | pub vis: Visibility, |
| 375 | pub defaultness: Defaultness, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 376 | pub sig: MethodSig, |
| 377 | pub block: Block, |
| 378 | }), |
| 379 | pub Type(ImplItemType { |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 380 | pub attrs: Vec<Attribute>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 381 | pub vis: Visibility, |
| 382 | pub defaultness: Defaultness, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 383 | pub type_token: Token![type], |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 384 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 385 | pub eq_token: Token![=], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 386 | pub ty: Type, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 387 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 388 | }), |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 389 | pub Macro(ImplItemMacro { |
| 390 | pub attrs: Vec<Attribute>, |
| 391 | pub mac: Macro, |
| 392 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 393 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | ast_struct! { |
| 397 | /// Represents a method's signature in a trait declaration, |
| 398 | /// or in an implementation. |
| 399 | pub struct MethodSig { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 400 | pub constness: Constness, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 401 | pub unsafety: Unsafety, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 402 | pub abi: Option<Abi>, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 403 | pub ident: Ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 404 | pub decl: FnDecl, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | ast_struct! { |
| 409 | /// Header (not the body) of a function declaration. |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 410 | /// |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 411 | /// E.g. `fn foo(bar: baz)` |
| 412 | pub struct FnDecl { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 413 | pub fn_token: Token![fn], |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 414 | pub paren_token: tokens::Paren, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 415 | pub inputs: Delimited<FnArg, Token![,]>, |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 416 | pub output: ReturnType, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 417 | pub generics: Generics, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 418 | pub variadic: bool, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 419 | pub dot_tokens: Option<Token![...]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 420 | } |
David Tolnay | f38cdf6 | 2016-09-23 19:07:09 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 423 | ast_enum_of_structs! { |
| 424 | /// An argument in a function header. |
| 425 | /// |
| 426 | /// E.g. `bar: usize` as in `fn foo(bar: usize)` |
| 427 | pub enum FnArg { |
| 428 | pub SelfRef(ArgSelfRef { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 429 | pub and_token: Token![&], |
| 430 | pub self_token: Token![self], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 431 | pub lifetime: Option<Lifetime>, |
| 432 | pub mutbl: Mutability, |
| 433 | }), |
| 434 | pub SelfValue(ArgSelf { |
| 435 | pub mutbl: Mutability, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 436 | pub self_token: Token![self], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 437 | }), |
| 438 | pub Captured(ArgCaptured { |
| 439 | pub pat: Pat, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 440 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 441 | pub ty: Type, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 442 | }), |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 443 | pub Ignored(Type), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 444 | } |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 445 | } |
| 446 | |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 447 | #[cfg(feature = "parsing")] |
| 448 | pub mod parsing { |
| 449 | use super::*; |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 450 | |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 451 | use synom::Synom; |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 452 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 453 | impl_synom!(Item "item" alt!( |
| 454 | syn!(ItemExternCrate) => { Item::ExternCrate } |
| 455 | | |
| 456 | syn!(ItemUse) => { Item::Use } |
| 457 | | |
| 458 | syn!(ItemStatic) => { Item::Static } |
| 459 | | |
| 460 | syn!(ItemConst) => { Item::Const } |
| 461 | | |
| 462 | syn!(ItemFn) => { Item::Fn } |
| 463 | | |
| 464 | syn!(ItemMod) => { Item::Mod } |
| 465 | | |
| 466 | syn!(ItemForeignMod) => { Item::ForeignMod } |
| 467 | | |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 468 | syn!(ItemType) => { Item::Type } |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 469 | | |
| 470 | syn!(ItemStruct) => { Item::Struct } |
| 471 | | |
| 472 | syn!(ItemEnum) => { Item::Enum } |
| 473 | | |
| 474 | syn!(ItemUnion) => { Item::Union } |
| 475 | | |
| 476 | syn!(ItemTrait) => { Item::Trait } |
| 477 | | |
| 478 | syn!(ItemDefaultImpl) => { Item::DefaultImpl } |
| 479 | | |
| 480 | syn!(ItemImpl) => { Item::Impl } |
| 481 | | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 482 | syn!(ItemMacro) => { Item::Macro } |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 483 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 484 | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 485 | impl_synom!(ItemMacro "macro item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 486 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 487 | what: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 488 | bang: punct!(!) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 489 | ident: option!(syn!(Ident)) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 490 | body: call!(::TokenTree::parse_delimited) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 491 | cond!(!body.is_braced(), punct!(;)) >> |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 492 | (ItemMacro { |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 493 | attrs: attrs, |
David Tolnay | 99a953d | 2017-11-11 12:51:43 -0800 | [diff] [blame] | 494 | ident: ident, |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 495 | mac: Macro { |
David Tolnay | 5d55ef7 | 2016-12-21 20:20:04 -0500 | [diff] [blame] | 496 | path: what, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 497 | bang_token: bang, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 498 | tokens: vec![body], |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 499 | }, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 500 | }) |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 501 | )); |
| 502 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 503 | impl_synom!(ItemExternCrate "extern crate item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 504 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 505 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 506 | extern_: keyword!(extern) >> |
| 507 | crate_: keyword!(crate) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 508 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 509 | rename: option!(tuple!(keyword!(as), syn!(Ident))) >> |
| 510 | semi: punct!(;) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 511 | (ItemExternCrate { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 512 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 513 | vis: vis, |
| 514 | extern_token: extern_, |
| 515 | crate_token: crate_, |
| 516 | ident: ident, |
| 517 | rename: rename, |
| 518 | semi_token: semi, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 519 | }) |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 520 | )); |
| 521 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 522 | impl_synom!(ItemUse "use item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 523 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 524 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 525 | use_: keyword!(use) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 526 | what: syn!(ViewPath) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 527 | semi: punct!(;) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 528 | (ItemUse { |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 529 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 530 | vis: vis, |
| 531 | use_token: use_, |
| 532 | path: Box::new(what), |
| 533 | semi_token: semi, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 534 | }) |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 535 | )); |
| 536 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 537 | impl Synom for ViewPath { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 538 | named!(parse -> Self, alt!( |
| 539 | syn!(PathGlob) => { ViewPath::Glob } |
| 540 | | |
| 541 | syn!(PathList) => { ViewPath::List } |
| 542 | | |
| 543 | syn!(PathSimple) => { ViewPath::Simple } // must be last |
| 544 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 545 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 546 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 547 | impl Synom for PathSimple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 548 | named!(parse -> Self, do_parse!( |
| 549 | path: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 550 | rename: option!(tuple!(keyword!(as), syn!(Ident))) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 551 | (PathSimple { |
| 552 | path: path, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 553 | as_token: rename.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 554 | rename: rename.map(|p| p.1), |
| 555 | }) |
| 556 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 557 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 558 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 559 | impl Synom for PathGlob { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 560 | named!(parse -> Self, do_parse!( |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 561 | path: option!(do_parse!( |
| 562 | path: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 563 | colon2: punct!(::) >> |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 564 | (path, colon2) |
| 565 | )) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 566 | star: punct!(*) >> |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 567 | ({ |
| 568 | match path { |
| 569 | Some((path, colon2)) => { |
| 570 | PathGlob { |
| 571 | path: path, |
| 572 | colon2_token: Some(colon2), |
| 573 | star_token: star, |
| 574 | } |
| 575 | } |
| 576 | None => { |
| 577 | PathGlob { |
| 578 | path: Path { |
| 579 | leading_colon: None, |
| 580 | segments: Default::default(), |
| 581 | }, |
| 582 | colon2_token: None, |
| 583 | star_token: star, |
| 584 | } |
| 585 | } |
| 586 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 587 | }) |
| 588 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 589 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 590 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 591 | impl Synom for PathList { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 592 | named!(parse -> Self, alt!( |
| 593 | do_parse!( |
| 594 | path: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 595 | colon2: punct!(::) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 596 | items: braces!(call!(Delimited::parse_terminated)) >> |
| 597 | (PathList { |
| 598 | path: path, |
| 599 | items: items.0, |
| 600 | brace_token: items.1, |
| 601 | colon2_token: colon2, |
| 602 | }) |
| 603 | ) |
| 604 | | |
| 605 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 606 | colon: option!(punct!(::)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 607 | items: braces!(call!(Delimited::parse_terminated)) >> |
| 608 | (PathList { |
| 609 | path: Path { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 610 | leading_colon: None, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 611 | segments: Delimited::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 612 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 613 | colon2_token: colon.unwrap_or_default(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 614 | brace_token: items.1, |
| 615 | items: items.0, |
| 616 | }) |
| 617 | ) |
| 618 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 619 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 620 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 621 | impl Synom for PathListItem { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 622 | named!(parse -> Self, do_parse!( |
| 623 | name: alt!( |
| 624 | syn!(Ident) |
| 625 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 626 | map!(keyword!(self), Into::into) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 627 | ) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 628 | rename: option!(tuple!(keyword!(as), syn!(Ident))) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 629 | (PathListItem { |
| 630 | name: name, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 631 | as_token: rename.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 632 | rename: rename.map(|p| p.1), |
| 633 | }) |
| 634 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 635 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 636 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 637 | impl_synom!(ItemStatic "static item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 638 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 639 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 640 | static_: keyword!(static) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 641 | mutability: syn!(Mutability) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 642 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 643 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 644 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 645 | eq: punct!(=) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 646 | value: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 647 | semi: punct!(;) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 648 | (ItemStatic { |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 649 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 650 | vis: vis, |
| 651 | static_token: static_, |
| 652 | mutbl: mutability, |
| 653 | ident: ident, |
| 654 | colon_token: colon, |
| 655 | ty: Box::new(ty), |
| 656 | eq_token: eq, |
| 657 | expr: Box::new(value), |
| 658 | semi_token: semi, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 659 | }) |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 660 | )); |
| 661 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 662 | impl_synom!(ItemConst "const item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 663 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 664 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 665 | const_: keyword!(const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 666 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 667 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 668 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 669 | eq: punct!(=) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 670 | value: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 671 | semi: punct!(;) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 672 | (ItemConst { |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 673 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 674 | vis: vis, |
| 675 | const_token: const_, |
| 676 | ident: ident, |
| 677 | colon_token: colon, |
| 678 | ty: Box::new(ty), |
| 679 | eq_token: eq, |
| 680 | expr: Box::new(value), |
| 681 | semi_token: semi, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 682 | }) |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 683 | )); |
| 684 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 685 | impl_synom!(ItemFn "fn item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 686 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 687 | vis: syn!(Visibility) >> |
| 688 | constness: syn!(Constness) >> |
| 689 | unsafety: syn!(Unsafety) >> |
| 690 | abi: option!(syn!(Abi)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 691 | fn_: keyword!(fn) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 692 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 693 | generics: syn!(Generics) >> |
| 694 | inputs: parens!(Delimited::parse_terminated) >> |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 695 | ret: syn!(ReturnType) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 696 | where_clause: syn!(WhereClause) >> |
| 697 | inner_attrs_stmts: braces!(tuple!( |
| 698 | many0!(call!(Attribute::parse_inner)), |
| 699 | call!(Block::parse_within) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 700 | )) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 701 | (ItemFn { |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 702 | attrs: { |
| 703 | let mut attrs = outer_attrs; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 704 | attrs.extend((inner_attrs_stmts.0).0); |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 705 | attrs |
| 706 | }, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 707 | vis: vis, |
| 708 | constness: constness, |
| 709 | unsafety: unsafety, |
| 710 | abi: abi, |
| 711 | decl: Box::new(FnDecl { |
| 712 | dot_tokens: None, |
| 713 | fn_token: fn_, |
| 714 | paren_token: inputs.1, |
| 715 | inputs: inputs.0, |
| 716 | output: ret, |
| 717 | variadic: false, |
| 718 | generics: Generics { |
| 719 | where_clause: where_clause, |
| 720 | .. generics |
| 721 | }, |
| 722 | }), |
| 723 | ident: ident, |
| 724 | block: Box::new(Block { |
| 725 | brace_token: inner_attrs_stmts.1, |
| 726 | stmts: (inner_attrs_stmts.0).1, |
| 727 | }), |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 728 | }) |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 729 | )); |
| 730 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 731 | impl Synom for FnArg { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 732 | named!(parse -> Self, alt!( |
| 733 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 734 | and: punct!(&) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 735 | lt: option!(syn!(Lifetime)) >> |
| 736 | mutability: syn!(Mutability) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 737 | self_: keyword!(self) >> |
| 738 | not!(punct!(:)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 739 | (ArgSelfRef { |
| 740 | lifetime: lt, |
| 741 | mutbl: mutability, |
| 742 | and_token: and, |
| 743 | self_token: self_, |
| 744 | }.into()) |
| 745 | ) |
| 746 | | |
| 747 | do_parse!( |
| 748 | mutability: syn!(Mutability) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 749 | self_: keyword!(self) >> |
| 750 | not!(punct!(:)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 751 | (ArgSelf { |
| 752 | mutbl: mutability, |
| 753 | self_token: self_, |
| 754 | }.into()) |
| 755 | ) |
| 756 | | |
| 757 | do_parse!( |
| 758 | pat: syn!(Pat) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 759 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 760 | ty: syn!(Type) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 761 | (ArgCaptured { |
| 762 | pat: pat, |
| 763 | ty: ty, |
| 764 | colon_token: colon, |
| 765 | }.into()) |
| 766 | ) |
| 767 | | |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 768 | syn!(Type) => { FnArg::Ignored } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 769 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 770 | } |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 771 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 772 | impl_synom!(ItemMod "mod item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 773 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 774 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 775 | mod_: keyword!(mod) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 776 | ident: syn!(Ident) >> |
| 777 | content_semi: alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 778 | punct!(;) => {|semi| ( |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 779 | Vec::new(), |
| 780 | None, |
| 781 | Some(semi), |
| 782 | )} |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 783 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 784 | braces!( |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 785 | tuple!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 786 | many0!(call!(Attribute::parse_inner)), |
| 787 | many0!(syn!(Item)) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 788 | ) |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 789 | ) => {|((inner_attrs, items), brace)| ( |
| 790 | inner_attrs, |
| 791 | Some((brace, items)), |
| 792 | None, |
| 793 | )} |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 794 | ) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 795 | (ItemMod { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 796 | attrs: { |
| 797 | let mut attrs = outer_attrs; |
| 798 | attrs.extend(content_semi.0); |
| 799 | attrs |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 800 | }, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 801 | vis: vis, |
| 802 | mod_token: mod_, |
| 803 | ident: ident, |
| 804 | content: content_semi.1, |
| 805 | semi: content_semi.2, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 806 | }) |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 807 | )); |
| 808 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 809 | impl_synom!(ItemForeignMod "foreign mod item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 810 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 811 | abi: syn!(Abi) >> |
| 812 | items: braces!(many0!(syn!(ForeignItem))) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 813 | (ItemForeignMod { |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 814 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 815 | abi: abi, |
| 816 | brace_token: items.1, |
| 817 | items: items.0, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 818 | }) |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 819 | )); |
| 820 | |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 821 | impl_synom!(ForeignItem "foreign item" alt!( |
| 822 | syn!(ForeignItemFn) => { ForeignItem::Fn } |
| 823 | | |
| 824 | syn!(ForeignItemStatic) => { ForeignItem::Static } |
David Tolnay | 199bcbb | 2017-11-12 10:33:52 -0800 | [diff] [blame^] | 825 | | |
| 826 | syn!(ForeignItemType) => { ForeignItem::Type } |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 827 | )); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 828 | |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 829 | impl_synom!(ForeignItemFn "foreign function" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 830 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 831 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 832 | fn_: keyword!(fn) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 833 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 834 | generics: syn!(Generics) >> |
| 835 | inputs: parens!(do_parse!( |
| 836 | args: call!(Delimited::parse_terminated) >> |
| 837 | variadic: cond!(args.is_empty() || args.trailing_delim(), |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 838 | option!(punct!(...))) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 839 | (args, variadic) |
| 840 | )) >> |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 841 | ret: syn!(ReturnType) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 842 | where_clause: syn!(WhereClause) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 843 | semi: punct!(;) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 844 | ({ |
| 845 | let ((inputs, variadic), parens) = inputs; |
| 846 | let variadic = variadic.and_then(|v| v); |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 847 | ForeignItemFn { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 848 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 849 | attrs: attrs, |
| 850 | semi_token: semi, |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 851 | decl: Box::new(FnDecl { |
| 852 | fn_token: fn_, |
| 853 | paren_token: parens, |
| 854 | inputs: inputs, |
| 855 | variadic: variadic.is_some(), |
| 856 | dot_tokens: variadic, |
| 857 | output: ret, |
| 858 | generics: Generics { |
| 859 | where_clause: where_clause, |
| 860 | .. generics |
| 861 | }, |
| 862 | }), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 863 | vis: vis, |
| 864 | } |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 865 | }) |
| 866 | )); |
| 867 | |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 868 | impl_synom!(ForeignItemStatic "foreign static" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 869 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 870 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 871 | static_: keyword!(static) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 872 | mutability: syn!(Mutability) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 873 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 874 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 875 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 876 | semi: punct!(;) >> |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 877 | (ForeignItemStatic { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 878 | ident: ident, |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 879 | attrs: attrs, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 880 | semi_token: semi, |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 881 | ty: Box::new(ty), |
| 882 | mutbl: mutability, |
| 883 | static_token: static_, |
| 884 | colon_token: colon, |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 885 | vis: vis, |
| 886 | }) |
| 887 | )); |
| 888 | |
David Tolnay | 199bcbb | 2017-11-12 10:33:52 -0800 | [diff] [blame^] | 889 | impl_synom!(ForeignItemType "foreign type" do_parse!( |
| 890 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 891 | vis: syn!(Visibility) >> |
| 892 | type_: keyword!(type) >> |
| 893 | ident: syn!(Ident) >> |
| 894 | semi: punct!(;) >> |
| 895 | (ForeignItemType { |
| 896 | attrs: attrs, |
| 897 | vis: vis, |
| 898 | type_token: type_, |
| 899 | ident: ident, |
| 900 | semi_token: semi, |
| 901 | }) |
| 902 | )); |
| 903 | |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 904 | impl_synom!(ItemType "type item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 905 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 906 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 907 | type_: keyword!(type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 908 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 909 | generics: syn!(Generics) >> |
| 910 | where_clause: syn!(WhereClause) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 911 | eq: punct!(=) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 912 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 913 | semi: punct!(;) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 914 | (ItemType { |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 915 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 916 | vis: vis, |
| 917 | type_token: type_, |
| 918 | ident: ident, |
| 919 | generics: Generics { |
| 920 | where_clause: where_clause, |
| 921 | ..generics |
| 922 | }, |
| 923 | eq_token: eq, |
| 924 | ty: Box::new(ty), |
| 925 | semi_token: semi, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 926 | }) |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 927 | )); |
| 928 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 929 | impl_synom!(ItemStruct "struct item" switch!( |
| 930 | map!(syn!(DeriveInput), Into::into), |
| 931 | Item::Struct(item) => value!(item) |
| 932 | | |
| 933 | _ => reject!() |
| 934 | )); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 935 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 936 | impl_synom!(ItemEnum "enum item" switch!( |
| 937 | map!(syn!(DeriveInput), Into::into), |
| 938 | Item::Enum(item) => value!(item) |
| 939 | | |
| 940 | _ => reject!() |
| 941 | )); |
| 942 | |
| 943 | impl_synom!(ItemUnion "union item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 944 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 945 | vis: syn!(Visibility) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 946 | union_: keyword!(union) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 947 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 948 | generics: syn!(Generics) >> |
| 949 | where_clause: syn!(WhereClause) >> |
| 950 | fields: braces!(call!(Delimited::parse_terminated_with, |
| 951 | Field::parse_struct)) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 952 | (ItemUnion { |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 953 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 954 | vis: vis, |
| 955 | union_token: union_, |
| 956 | ident: ident, |
| 957 | generics: Generics { |
| 958 | where_clause: where_clause, |
| 959 | .. generics |
| 960 | }, |
| 961 | data: VariantData::Struct(fields.0, fields.1), |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 962 | }) |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 963 | )); |
| 964 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 965 | impl_synom!(ItemTrait "trait item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 966 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 967 | vis: syn!(Visibility) >> |
| 968 | unsafety: syn!(Unsafety) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 969 | trait_: keyword!(trait) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 970 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 971 | generics: syn!(Generics) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 972 | colon: option!(punct!(:)) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 973 | bounds: cond!(colon.is_some(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 974 | call!(Delimited::parse_separated_nonempty) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 975 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 976 | where_clause: syn!(WhereClause) >> |
| 977 | body: braces!(many0!(syn!(TraitItem))) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 978 | (ItemTrait { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 979 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 980 | vis: vis, |
| 981 | unsafety: unsafety, |
| 982 | trait_token: trait_, |
| 983 | ident: ident, |
| 984 | generics: Generics { |
| 985 | where_clause: where_clause, |
| 986 | .. generics |
| 987 | }, |
| 988 | colon_token: colon, |
| 989 | supertraits: bounds.unwrap_or_default(), |
| 990 | brace_token: body.1, |
| 991 | items: body.0, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 992 | }) |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 993 | )); |
| 994 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 995 | impl_synom!(ItemDefaultImpl "default impl item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 996 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 997 | unsafety: syn!(Unsafety) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 998 | impl_: keyword!(impl) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 999 | path: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1000 | for_: keyword!(for) >> |
| 1001 | dot2: punct!(..) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1002 | braces: braces!(epsilon!()) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 1003 | (ItemDefaultImpl { |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 1004 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 1005 | unsafety: unsafety, |
| 1006 | impl_token: impl_, |
| 1007 | path: path, |
| 1008 | for_token: for_, |
| 1009 | dot2_token: dot2, |
| 1010 | brace_token: braces.1, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 1011 | }) |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 1012 | )); |
| 1013 | |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1014 | impl_synom!(TraitItem "trait item" alt!( |
| 1015 | syn!(TraitItemConst) => { TraitItem::Const } |
| 1016 | | |
| 1017 | syn!(TraitItemMethod) => { TraitItem::Method } |
| 1018 | | |
| 1019 | syn!(TraitItemType) => { TraitItem::Type } |
| 1020 | | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1021 | syn!(TraitItemMacro) => { TraitItem::Macro } |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1022 | )); |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1023 | |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1024 | impl_synom!(TraitItemConst "const trait item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1025 | attrs: many0!(call!(Attribute::parse_outer)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1026 | const_: keyword!(const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1027 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1028 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1029 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1030 | default: option!(tuple!(punct!(=), syn!(Expr))) >> |
| 1031 | semi: punct!(;) >> |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1032 | (TraitItemConst { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1033 | attrs: attrs, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1034 | const_token: const_, |
| 1035 | ident: ident, |
| 1036 | colon_token: colon, |
| 1037 | ty: ty, |
| 1038 | default: default, |
| 1039 | semi_token: semi, |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1040 | }) |
| 1041 | )); |
| 1042 | |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1043 | impl_synom!(TraitItemMethod "method trait item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1044 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1045 | constness: syn!(Constness) >> |
| 1046 | unsafety: syn!(Unsafety) >> |
| 1047 | abi: option!(syn!(Abi)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1048 | fn_: keyword!(fn) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1049 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1050 | generics: syn!(Generics) >> |
| 1051 | inputs: parens!(call!(Delimited::parse_terminated)) >> |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 1052 | ret: syn!(ReturnType) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1053 | where_clause: syn!(WhereClause) >> |
| 1054 | body: option!(braces!( |
| 1055 | tuple!(many0!(call!(Attribute::parse_inner)), |
| 1056 | call!(Block::parse_within)) |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1057 | )) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1058 | semi: cond!(body.is_none(), punct!(;)) >> |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1059 | ({ |
| 1060 | let (inner_attrs, stmts) = match body { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1061 | Some(((inner_attrs, stmts), b)) => (inner_attrs, Some((stmts, b))), |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1062 | None => (Vec::new(), None), |
| 1063 | }; |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1064 | TraitItemMethod { |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1065 | attrs: { |
| 1066 | let mut attrs = outer_attrs; |
| 1067 | attrs.extend(inner_attrs); |
| 1068 | attrs |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1069 | }, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1070 | sig: MethodSig { |
| 1071 | constness: constness, |
| 1072 | unsafety: unsafety, |
| 1073 | abi: abi, |
| 1074 | ident: ident, |
| 1075 | decl: FnDecl { |
| 1076 | inputs: inputs.0, |
| 1077 | output: ret, |
| 1078 | variadic: false, |
| 1079 | fn_token: fn_, |
| 1080 | paren_token: inputs.1, |
| 1081 | dot_tokens: None, |
| 1082 | generics: Generics { |
| 1083 | where_clause: where_clause, |
| 1084 | .. generics |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1085 | }, |
| 1086 | }, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1087 | }, |
| 1088 | default: stmts.map(|stmts| { |
| 1089 | Block { |
| 1090 | stmts: stmts.0, |
| 1091 | brace_token: stmts.1, |
| 1092 | } |
| 1093 | }), |
| 1094 | semi_token: semi, |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1095 | } |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1096 | }) |
| 1097 | )); |
| 1098 | |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1099 | impl_synom!(TraitItemType "trait item type" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1100 | attrs: many0!(call!(Attribute::parse_outer)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1101 | type_: keyword!(type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1102 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1103 | colon: option!(punct!(:)) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1104 | bounds: cond!(colon.is_some(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1105 | call!(Delimited::parse_separated_nonempty) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1106 | ) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1107 | default: option!(tuple!(punct!(=), syn!(Type))) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1108 | semi: punct!(;) >> |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1109 | (TraitItemType { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1110 | attrs: attrs, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1111 | type_token: type_, |
| 1112 | ident: ident, |
| 1113 | colon_token: colon, |
| 1114 | bounds: bounds.unwrap_or_default(), |
| 1115 | default: default, |
| 1116 | semi_token: semi, |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1117 | }) |
| 1118 | )); |
| 1119 | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1120 | impl_synom!(TraitItemMacro "trait item macro" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1121 | attrs: many0!(call!(Attribute::parse_outer)) >> |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1122 | mac: syn!(Macro) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1123 | cond!(!mac.is_braced(), punct!(;)) >> |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1124 | (TraitItemMacro { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1125 | attrs: attrs, |
David Tolnay | da705bd | 2017-11-10 21:58:05 -0800 | [diff] [blame] | 1126 | mac: mac, |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1127 | }) |
| 1128 | )); |
| 1129 | |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 1130 | impl_synom!(ItemImpl "impl item" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1131 | attrs: many0!(call!(Attribute::parse_outer)) >> |
Alex Crichton | f3d9ccc | 2017-08-28 09:40:13 -0700 | [diff] [blame] | 1132 | defaultness: syn!(Defaultness) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1133 | unsafety: syn!(Unsafety) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1134 | impl_: keyword!(impl) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1135 | generics: syn!(Generics) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1136 | polarity_path: alt!( |
| 1137 | do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1138 | polarity: syn!(ImplPolarity) >> |
| 1139 | path: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1140 | for_: keyword!(for) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1141 | (Some((polarity, path, for_))) |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1142 | ) |
| 1143 | | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1144 | epsilon!() => { |_| None } |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1145 | ) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1146 | self_ty: syn!(Type) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1147 | where_clause: syn!(WhereClause) >> |
| 1148 | body: braces!(many0!(syn!(ImplItem))) >> |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 1149 | (ItemImpl { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1150 | attrs: attrs, |
David Tolnay | c6b55bc | 2017-11-09 22:48:38 -0800 | [diff] [blame] | 1151 | defaultness: defaultness, |
| 1152 | unsafety: unsafety, |
| 1153 | impl_token: impl_, |
| 1154 | generics: Generics { |
| 1155 | where_clause: where_clause, |
| 1156 | .. generics |
| 1157 | }, |
| 1158 | trait_: polarity_path, |
| 1159 | self_ty: Box::new(self_ty), |
| 1160 | brace_token: body.1, |
| 1161 | items: body.0, |
David Tolnay | 4c614be | 2017-11-10 00:02:38 -0800 | [diff] [blame] | 1162 | }) |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1163 | )); |
| 1164 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1165 | impl_synom!(ImplItem "item in impl block" alt!( |
| 1166 | syn!(ImplItemConst) => { ImplItem::Const } |
| 1167 | | |
| 1168 | syn!(ImplItemMethod) => { ImplItem::Method } |
| 1169 | | |
| 1170 | syn!(ImplItemType) => { ImplItem::Type } |
| 1171 | | |
| 1172 | syn!(ImplItemMacro) => { ImplItem::Macro } |
| 1173 | )); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1174 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1175 | impl_synom!(ImplItemConst "const item in impl block" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1176 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1177 | vis: syn!(Visibility) >> |
| 1178 | defaultness: syn!(Defaultness) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1179 | const_: keyword!(const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1180 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1181 | colon: punct!(:) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1182 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1183 | eq: punct!(=) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1184 | value: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1185 | semi: punct!(;) >> |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1186 | (ImplItemConst { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1187 | attrs: attrs, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1188 | vis: vis, |
| 1189 | defaultness: defaultness, |
| 1190 | const_token: const_, |
| 1191 | ident: ident, |
| 1192 | colon_token: colon, |
| 1193 | ty: ty, |
| 1194 | eq_token: eq, |
| 1195 | expr: value, |
| 1196 | semi_token: semi, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1197 | }) |
| 1198 | )); |
| 1199 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1200 | impl_synom!(ImplItemMethod "method in impl block" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1201 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1202 | vis: syn!(Visibility) >> |
| 1203 | defaultness: syn!(Defaultness) >> |
| 1204 | constness: syn!(Constness) >> |
| 1205 | unsafety: syn!(Unsafety) >> |
| 1206 | abi: option!(syn!(Abi)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1207 | fn_: keyword!(fn) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1208 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1209 | generics: syn!(Generics) >> |
| 1210 | inputs: parens!(call!(Delimited::parse_terminated)) >> |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 1211 | ret: syn!(ReturnType) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1212 | where_clause: syn!(WhereClause) >> |
| 1213 | inner_attrs_stmts: braces!(tuple!( |
| 1214 | many0!(call!(Attribute::parse_inner)), |
| 1215 | call!(Block::parse_within) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 1216 | )) >> |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1217 | (ImplItemMethod { |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1218 | attrs: { |
| 1219 | let mut attrs = outer_attrs; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1220 | attrs.extend((inner_attrs_stmts.0).0); |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1221 | attrs |
| 1222 | }, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1223 | vis: vis, |
| 1224 | defaultness: defaultness, |
| 1225 | sig: MethodSig { |
| 1226 | constness: constness, |
| 1227 | unsafety: unsafety, |
| 1228 | abi: abi, |
| 1229 | ident: ident, |
| 1230 | decl: FnDecl { |
| 1231 | fn_token: fn_, |
| 1232 | paren_token: inputs.1, |
| 1233 | inputs: inputs.0, |
| 1234 | output: ret, |
| 1235 | variadic: false, |
| 1236 | generics: Generics { |
| 1237 | where_clause: where_clause, |
| 1238 | .. generics |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1239 | }, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1240 | dot_tokens: None, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1241 | }, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1242 | }, |
| 1243 | block: Block { |
| 1244 | brace_token: inner_attrs_stmts.1, |
| 1245 | stmts: (inner_attrs_stmts.0).1, |
| 1246 | }, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1247 | }) |
| 1248 | )); |
| 1249 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1250 | impl_synom!(ImplItemType "type in impl block" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1251 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1252 | vis: syn!(Visibility) >> |
| 1253 | defaultness: syn!(Defaultness) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1254 | type_: keyword!(type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1255 | ident: syn!(Ident) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1256 | eq: punct!(=) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1257 | ty: syn!(Type) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1258 | semi: punct!(;) >> |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1259 | (ImplItemType { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1260 | attrs: attrs, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1261 | vis: vis, |
| 1262 | defaultness: defaultness, |
| 1263 | type_token: type_, |
| 1264 | ident: ident, |
| 1265 | eq_token: eq, |
| 1266 | ty: ty, |
| 1267 | semi_token: semi, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1268 | }) |
| 1269 | )); |
| 1270 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1271 | impl_synom!(ImplItemMacro "macro in impl block" do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1272 | attrs: many0!(call!(Attribute::parse_outer)) >> |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1273 | mac: syn!(Macro) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1274 | cond!(!mac.is_braced(), punct!(;)) >> |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1275 | (ImplItemMacro { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1276 | attrs: attrs, |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1277 | mac: mac, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1278 | }) |
| 1279 | )); |
| 1280 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1281 | impl Synom for ImplPolarity { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1282 | named!(parse -> Self, alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1283 | punct!(!) => { ImplPolarity::Negative } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1284 | | |
| 1285 | epsilon!() => { |_| ImplPolarity::Positive } |
| 1286 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1287 | } |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1288 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1289 | impl Synom for Constness { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1290 | named!(parse -> Self, alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1291 | keyword!(const) => { Constness::Const } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1292 | | |
| 1293 | epsilon!() => { |_| Constness::NotConst } |
| 1294 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1295 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1296 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1297 | impl Synom for Defaultness { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1298 | named!(parse -> Self, alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1299 | keyword!(default) => { Defaultness::Default } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1300 | | |
| 1301 | epsilon!() => { |_| Defaultness::Final } |
| 1302 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1303 | } |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 1304 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1305 | |
| 1306 | #[cfg(feature = "printing")] |
| 1307 | mod printing { |
| 1308 | use super::*; |
| 1309 | use attr::FilterAttrs; |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 1310 | use data::VariantData; |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1311 | use quote::{Tokens, ToTokens}; |
| 1312 | |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1313 | impl ToTokens for ItemExternCrate { |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1314 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1315 | tokens.append_all(self.attrs.outer()); |
| 1316 | self.vis.to_tokens(tokens); |
| 1317 | self.extern_token.to_tokens(tokens); |
| 1318 | self.crate_token.to_tokens(tokens); |
| 1319 | self.ident.to_tokens(tokens); |
| 1320 | if let Some((ref as_token, ref rename)) = self.rename { |
| 1321 | as_token.to_tokens(tokens); |
| 1322 | rename.to_tokens(tokens); |
| 1323 | } |
| 1324 | self.semi_token.to_tokens(tokens); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | impl ToTokens for ItemUse { |
| 1329 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1330 | tokens.append_all(self.attrs.outer()); |
| 1331 | self.vis.to_tokens(tokens); |
| 1332 | self.use_token.to_tokens(tokens); |
| 1333 | self.path.to_tokens(tokens); |
| 1334 | self.semi_token.to_tokens(tokens); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | impl ToTokens for ItemStatic { |
| 1339 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1340 | tokens.append_all(self.attrs.outer()); |
| 1341 | self.vis.to_tokens(tokens); |
| 1342 | self.static_token.to_tokens(tokens); |
| 1343 | self.mutbl.to_tokens(tokens); |
| 1344 | self.ident.to_tokens(tokens); |
| 1345 | self.colon_token.to_tokens(tokens); |
| 1346 | self.ty.to_tokens(tokens); |
| 1347 | self.eq_token.to_tokens(tokens); |
| 1348 | self.expr.to_tokens(tokens); |
| 1349 | self.semi_token.to_tokens(tokens); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | impl ToTokens for ItemConst { |
| 1354 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1355 | tokens.append_all(self.attrs.outer()); |
| 1356 | self.vis.to_tokens(tokens); |
| 1357 | self.const_token.to_tokens(tokens); |
| 1358 | self.ident.to_tokens(tokens); |
| 1359 | self.colon_token.to_tokens(tokens); |
| 1360 | self.ty.to_tokens(tokens); |
| 1361 | self.eq_token.to_tokens(tokens); |
| 1362 | self.expr.to_tokens(tokens); |
| 1363 | self.semi_token.to_tokens(tokens); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | impl ToTokens for ItemFn { |
| 1368 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1369 | tokens.append_all(self.attrs.outer()); |
| 1370 | self.vis.to_tokens(tokens); |
| 1371 | self.constness.to_tokens(tokens); |
| 1372 | self.unsafety.to_tokens(tokens); |
| 1373 | self.abi.to_tokens(tokens); |
| 1374 | NamedDecl(&self.decl, self.ident).to_tokens(tokens); |
| 1375 | self.block.brace_token.surround(tokens, |tokens| { |
| 1376 | tokens.append_all(self.attrs.inner()); |
| 1377 | tokens.append_all(&self.block.stmts); |
| 1378 | }); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | impl ToTokens for ItemMod { |
| 1383 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1384 | tokens.append_all(self.attrs.outer()); |
| 1385 | self.vis.to_tokens(tokens); |
| 1386 | self.mod_token.to_tokens(tokens); |
| 1387 | self.ident.to_tokens(tokens); |
| 1388 | if let Some((ref brace, ref items)) = self.content { |
| 1389 | brace.surround(tokens, |tokens| { |
| 1390 | tokens.append_all(self.attrs.inner()); |
| 1391 | tokens.append_all(items); |
| 1392 | }); |
| 1393 | } else { |
| 1394 | TokensOrDefault(&self.semi).to_tokens(tokens); |
| 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | impl ToTokens for ItemForeignMod { |
| 1400 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1401 | tokens.append_all(self.attrs.outer()); |
| 1402 | self.abi.to_tokens(tokens); |
| 1403 | self.brace_token.surround(tokens, |tokens| { |
| 1404 | tokens.append_all(&self.items); |
| 1405 | }); |
| 1406 | } |
| 1407 | } |
| 1408 | |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1409 | impl ToTokens for ItemType { |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1410 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1411 | tokens.append_all(self.attrs.outer()); |
| 1412 | self.vis.to_tokens(tokens); |
| 1413 | self.type_token.to_tokens(tokens); |
| 1414 | self.ident.to_tokens(tokens); |
| 1415 | self.generics.to_tokens(tokens); |
| 1416 | self.generics.where_clause.to_tokens(tokens); |
| 1417 | self.eq_token.to_tokens(tokens); |
| 1418 | self.ty.to_tokens(tokens); |
| 1419 | self.semi_token.to_tokens(tokens); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | impl ToTokens for ItemEnum { |
| 1424 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1425 | tokens.append_all(self.attrs.outer()); |
| 1426 | self.vis.to_tokens(tokens); |
| 1427 | self.enum_token.to_tokens(tokens); |
| 1428 | self.ident.to_tokens(tokens); |
| 1429 | self.generics.to_tokens(tokens); |
| 1430 | self.generics.where_clause.to_tokens(tokens); |
| 1431 | self.brace_token.surround(tokens, |tokens| { |
| 1432 | self.variants.to_tokens(tokens); |
| 1433 | }); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | impl ToTokens for ItemStruct { |
| 1438 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1439 | tokens.append_all(self.attrs.outer()); |
| 1440 | self.vis.to_tokens(tokens); |
| 1441 | self.struct_token.to_tokens(tokens); |
| 1442 | self.ident.to_tokens(tokens); |
| 1443 | self.generics.to_tokens(tokens); |
| 1444 | match self.data { |
| 1445 | VariantData::Struct(..) => { |
| 1446 | self.generics.where_clause.to_tokens(tokens); |
| 1447 | self.data.to_tokens(tokens); |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1448 | } |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1449 | VariantData::Tuple(..) => { |
| 1450 | self.data.to_tokens(tokens); |
| 1451 | self.generics.where_clause.to_tokens(tokens); |
| 1452 | TokensOrDefault(&self.semi_token).to_tokens(tokens); |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1453 | } |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1454 | VariantData::Unit => { |
| 1455 | self.generics.where_clause.to_tokens(tokens); |
| 1456 | TokensOrDefault(&self.semi_token).to_tokens(tokens); |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 1457 | } |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | impl ToTokens for ItemUnion { |
| 1463 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1464 | tokens.append_all(self.attrs.outer()); |
| 1465 | self.vis.to_tokens(tokens); |
| 1466 | self.union_token.to_tokens(tokens); |
| 1467 | self.ident.to_tokens(tokens); |
| 1468 | self.generics.to_tokens(tokens); |
| 1469 | self.generics.where_clause.to_tokens(tokens); |
| 1470 | // XXX: Should we handle / complain when using a |
| 1471 | // non-VariantData::Struct Variant in Union? |
| 1472 | self.data.to_tokens(tokens); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | impl ToTokens for ItemTrait { |
| 1477 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1478 | tokens.append_all(self.attrs.outer()); |
| 1479 | self.vis.to_tokens(tokens); |
| 1480 | self.unsafety.to_tokens(tokens); |
| 1481 | self.trait_token.to_tokens(tokens); |
| 1482 | self.ident.to_tokens(tokens); |
| 1483 | self.generics.to_tokens(tokens); |
| 1484 | if !self.supertraits.is_empty() { |
| 1485 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
| 1486 | self.supertraits.to_tokens(tokens); |
| 1487 | } |
| 1488 | self.generics.where_clause.to_tokens(tokens); |
| 1489 | self.brace_token.surround(tokens, |tokens| { |
| 1490 | tokens.append_all(&self.items); |
| 1491 | }); |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | impl ToTokens for ItemDefaultImpl { |
| 1496 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1497 | tokens.append_all(self.attrs.outer()); |
| 1498 | self.unsafety.to_tokens(tokens); |
| 1499 | self.impl_token.to_tokens(tokens); |
| 1500 | self.path.to_tokens(tokens); |
| 1501 | self.for_token.to_tokens(tokens); |
| 1502 | self.dot2_token.to_tokens(tokens); |
| 1503 | self.brace_token.surround(tokens, |_tokens| {}); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | impl ToTokens for ItemImpl { |
| 1508 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1509 | tokens.append_all(self.attrs.outer()); |
| 1510 | self.defaultness.to_tokens(tokens); |
| 1511 | self.unsafety.to_tokens(tokens); |
| 1512 | self.impl_token.to_tokens(tokens); |
| 1513 | self.generics.to_tokens(tokens); |
| 1514 | if let Some((ref polarity, ref path, ref for_token)) = self.trait_ { |
| 1515 | polarity.to_tokens(tokens); |
| 1516 | path.to_tokens(tokens); |
| 1517 | for_token.to_tokens(tokens); |
| 1518 | } |
| 1519 | self.self_ty.to_tokens(tokens); |
| 1520 | self.generics.where_clause.to_tokens(tokens); |
| 1521 | self.brace_token.surround(tokens, |tokens| { |
| 1522 | tokens.append_all(&self.items); |
| 1523 | }); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | impl ToTokens for ItemMacro { |
| 1528 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1529 | tokens.append_all(self.attrs.outer()); |
| 1530 | self.mac.path.to_tokens(tokens); |
| 1531 | self.mac.bang_token.to_tokens(tokens); |
David Tolnay | 99a953d | 2017-11-11 12:51:43 -0800 | [diff] [blame] | 1532 | self.ident.to_tokens(tokens); |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1533 | tokens.append_all(&self.mac.tokens); |
| 1534 | if !self.mac.is_braced() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1535 | <Token![;]>::default().to_tokens(tokens); |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1539 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1540 | impl ToTokens for PathSimple { |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1541 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1542 | self.path.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1543 | if self.rename.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1544 | TokensOrDefault(&self.as_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1545 | self.rename.to_tokens(tokens); |
| 1546 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1550 | impl ToTokens for PathGlob { |
| 1551 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 1552 | if self.path.segments.len() > 0 { |
| 1553 | self.path.to_tokens(tokens); |
| 1554 | TokensOrDefault(&self.colon2_token).to_tokens(tokens); |
| 1555 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1556 | self.star_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | impl ToTokens for PathList { |
| 1561 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1562 | self.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1563 | self.colon2_token.to_tokens(tokens); |
| 1564 | self.brace_token.surround(tokens, |tokens| { |
| 1565 | self.items.to_tokens(tokens); |
| 1566 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1570 | impl ToTokens for PathListItem { |
| 1571 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1572 | self.name.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1573 | if self.rename.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1574 | TokensOrDefault(&self.as_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1575 | self.rename.to_tokens(tokens); |
| 1576 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1580 | impl ToTokens for TraitItemConst { |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1581 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1582 | tokens.append_all(self.attrs.outer()); |
| 1583 | self.const_token.to_tokens(tokens); |
| 1584 | self.ident.to_tokens(tokens); |
| 1585 | self.colon_token.to_tokens(tokens); |
| 1586 | self.ty.to_tokens(tokens); |
| 1587 | if let Some((ref eq_token, ref default)) = self.default { |
| 1588 | eq_token.to_tokens(tokens); |
| 1589 | default.to_tokens(tokens); |
| 1590 | } |
| 1591 | self.semi_token.to_tokens(tokens); |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | impl ToTokens for TraitItemMethod { |
| 1596 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1597 | tokens.append_all(self.attrs.outer()); |
| 1598 | self.sig.to_tokens(tokens); |
| 1599 | match self.default { |
| 1600 | Some(ref block) => { |
| 1601 | block.brace_token.surround(tokens, |tokens| { |
| 1602 | tokens.append_all(self.attrs.inner()); |
| 1603 | tokens.append_all(&block.stmts); |
| 1604 | }); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1605 | } |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1606 | None => { |
| 1607 | TokensOrDefault(&self.semi_token).to_tokens(tokens); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1608 | } |
David Tolnay | 1bfa733 | 2017-11-11 12:41:20 -0800 | [diff] [blame] | 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | impl ToTokens for TraitItemType { |
| 1614 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1615 | tokens.append_all(self.attrs.outer()); |
| 1616 | self.type_token.to_tokens(tokens); |
| 1617 | self.ident.to_tokens(tokens); |
| 1618 | if !self.bounds.is_empty() { |
| 1619 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
| 1620 | self.bounds.to_tokens(tokens); |
| 1621 | } |
| 1622 | if let Some((ref eq_token, ref default)) = self.default { |
| 1623 | eq_token.to_tokens(tokens); |
| 1624 | default.to_tokens(tokens); |
| 1625 | } |
| 1626 | self.semi_token.to_tokens(tokens); |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | impl ToTokens for TraitItemMacro { |
| 1631 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1632 | tokens.append_all(self.attrs.outer()); |
| 1633 | self.mac.to_tokens(tokens); |
| 1634 | if !self.mac.is_braced() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1635 | <Token![;]>::default().to_tokens(tokens); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1640 | impl ToTokens for ImplItemConst { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1641 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1642 | tokens.append_all(self.attrs.outer()); |
David Tolnay | 857628c | 2017-11-11 12:25:31 -0800 | [diff] [blame] | 1643 | self.vis.to_tokens(tokens); |
| 1644 | self.defaultness.to_tokens(tokens); |
| 1645 | self.const_token.to_tokens(tokens); |
| 1646 | self.ident.to_tokens(tokens); |
| 1647 | self.colon_token.to_tokens(tokens); |
| 1648 | self.ty.to_tokens(tokens); |
| 1649 | self.eq_token.to_tokens(tokens); |
| 1650 | self.expr.to_tokens(tokens); |
| 1651 | self.semi_token.to_tokens(tokens); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | impl ToTokens for ImplItemMethod { |
| 1656 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1657 | tokens.append_all(self.attrs.outer()); |
| 1658 | self.vis.to_tokens(tokens); |
| 1659 | self.defaultness.to_tokens(tokens); |
| 1660 | self.sig.to_tokens(tokens); |
| 1661 | self.block.brace_token.surround(tokens, |tokens| { |
| 1662 | tokens.append_all(self.attrs.inner()); |
| 1663 | tokens.append_all(&self.block.stmts); |
| 1664 | }); |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | impl ToTokens for ImplItemType { |
| 1669 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1670 | tokens.append_all(self.attrs.outer()); |
| 1671 | self.vis.to_tokens(tokens); |
| 1672 | self.defaultness.to_tokens(tokens); |
| 1673 | self.type_token.to_tokens(tokens); |
| 1674 | self.ident.to_tokens(tokens); |
| 1675 | self.eq_token.to_tokens(tokens); |
| 1676 | self.ty.to_tokens(tokens); |
| 1677 | self.semi_token.to_tokens(tokens); |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | impl ToTokens for ImplItemMacro { |
| 1682 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1683 | tokens.append_all(self.attrs.outer()); |
| 1684 | self.mac.to_tokens(tokens); |
| 1685 | if !self.mac.is_braced() { |
| 1686 | // FIXME needs a span |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1687 | <Token![;]>::default().to_tokens(tokens); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 1692 | impl ToTokens for ForeignItemFn { |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1693 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1694 | tokens.append_all(self.attrs.outer()); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1695 | self.vis.to_tokens(tokens); |
David Tolnay | 8894f60 | 2017-11-11 12:11:04 -0800 | [diff] [blame] | 1696 | NamedDecl(&self.decl, self.ident).to_tokens(tokens); |
| 1697 | self.semi_token.to_tokens(tokens); |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | impl ToTokens for ForeignItemStatic { |
| 1702 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1703 | tokens.append_all(self.attrs.outer()); |
| 1704 | self.vis.to_tokens(tokens); |
| 1705 | self.static_token.to_tokens(tokens); |
| 1706 | self.mutbl.to_tokens(tokens); |
| 1707 | self.ident.to_tokens(tokens); |
| 1708 | self.colon_token.to_tokens(tokens); |
| 1709 | self.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1710 | self.semi_token.to_tokens(tokens); |
| 1711 | } |
| 1712 | } |
| 1713 | |
David Tolnay | 199bcbb | 2017-11-12 10:33:52 -0800 | [diff] [blame^] | 1714 | impl ToTokens for ForeignItemType { |
| 1715 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1716 | tokens.append_all(self.attrs.outer()); |
| 1717 | self.vis.to_tokens(tokens); |
| 1718 | self.type_token.to_tokens(tokens); |
| 1719 | self.ident.to_tokens(tokens); |
| 1720 | self.semi_token.to_tokens(tokens); |
| 1721 | } |
| 1722 | } |
| 1723 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1724 | impl ToTokens for MethodSig { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1725 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1726 | self.constness.to_tokens(tokens); |
| 1727 | self.unsafety.to_tokens(tokens); |
| 1728 | self.abi.to_tokens(tokens); |
| 1729 | NamedDecl(&self.decl, self.ident).to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1733 | struct NamedDecl<'a>(&'a FnDecl, Ident); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1734 | |
| 1735 | impl<'a> ToTokens for NamedDecl<'a> { |
| 1736 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1737 | self.0.fn_token.to_tokens(tokens); |
| 1738 | self.1.to_tokens(tokens); |
| 1739 | self.0.generics.to_tokens(tokens); |
| 1740 | self.0.paren_token.surround(tokens, |tokens| { |
| 1741 | self.0.inputs.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1742 | |
| 1743 | if self.0.variadic { |
| 1744 | if !self.0.inputs.empty_or_trailing() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1745 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1746 | } |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1747 | TokensOrDefault(&self.0.dot_tokens).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1748 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1749 | }); |
| 1750 | self.0.output.to_tokens(tokens); |
| 1751 | self.0.generics.where_clause.to_tokens(tokens); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1755 | impl ToTokens for ArgSelfRef { |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1756 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1757 | self.and_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1758 | self.lifetime.to_tokens(tokens); |
| 1759 | self.mutbl.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1760 | self.self_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | impl ToTokens for ArgSelf { |
| 1765 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1766 | self.mutbl.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1767 | self.self_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | impl ToTokens for ArgCaptured { |
| 1772 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1773 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1774 | self.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1775 | self.ty.to_tokens(tokens); |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1779 | impl ToTokens for Constness { |
| 1780 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1781 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1782 | Constness::Const(ref t) => t.to_tokens(tokens), |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 1783 | Constness::NotConst => { |
| 1784 | // nothing |
| 1785 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | } |
| 1789 | |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1790 | impl ToTokens for Defaultness { |
| 1791 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1792 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1793 | Defaultness::Default(ref t) => t.to_tokens(tokens), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1794 | Defaultness::Final => { |
| 1795 | // nothing |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | impl ToTokens for ImplPolarity { |
| 1802 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1803 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1804 | ImplPolarity::Negative(ref t) => t.to_tokens(tokens), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1805 | ImplPolarity::Positive => { |
| 1806 | // nothing |
| 1807 | } |
| 1808 | } |
| 1809 | } |
| 1810 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1811 | } |