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