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