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