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 | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 229 | pub colon2_token: Option<tokens::Colon2>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 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!( |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 563 | path: option!(do_parse!( |
| 564 | path: syn!(Path) >> |
| 565 | colon2: syn!(Colon2) >> |
| 566 | (path, colon2) |
| 567 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 568 | star: syn!(Star) >> |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 569 | ({ |
| 570 | match path { |
| 571 | Some((path, colon2)) => { |
| 572 | PathGlob { |
| 573 | path: path, |
| 574 | colon2_token: Some(colon2), |
| 575 | star_token: star, |
| 576 | } |
| 577 | } |
| 578 | None => { |
| 579 | PathGlob { |
| 580 | path: Path { |
| 581 | leading_colon: None, |
| 582 | segments: Default::default(), |
| 583 | }, |
| 584 | colon2_token: None, |
| 585 | star_token: star, |
| 586 | } |
| 587 | } |
| 588 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 589 | }) |
| 590 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 591 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 592 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 593 | impl Synom for PathList { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 594 | named!(parse -> Self, alt!( |
| 595 | do_parse!( |
| 596 | path: syn!(Path) >> |
| 597 | colon2: syn!(Colon2) >> |
| 598 | items: braces!(call!(Delimited::parse_terminated)) >> |
| 599 | (PathList { |
| 600 | path: path, |
| 601 | items: items.0, |
| 602 | brace_token: items.1, |
| 603 | colon2_token: colon2, |
| 604 | }) |
| 605 | ) |
| 606 | | |
| 607 | do_parse!( |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 608 | colon: option!(syn!(Colon2)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 609 | items: braces!(call!(Delimited::parse_terminated)) >> |
| 610 | (PathList { |
| 611 | path: Path { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 612 | leading_colon: None, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 613 | segments: Delimited::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 614 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 615 | colon2_token: colon.unwrap_or_default(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 616 | brace_token: items.1, |
| 617 | items: items.0, |
| 618 | }) |
| 619 | ) |
| 620 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 621 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 622 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 623 | impl Synom for PathListItem { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 624 | named!(parse -> Self, do_parse!( |
| 625 | name: alt!( |
| 626 | syn!(Ident) |
| 627 | | |
| 628 | map!(syn!(Self_), Into::into) |
| 629 | ) >> |
| 630 | rename: option!(tuple!(syn!(As), syn!(Ident))) >> |
| 631 | (PathListItem { |
| 632 | name: name, |
| 633 | as_token: rename.as_ref().map(|p| As((p.0).0)), |
| 634 | rename: rename.map(|p| p.1), |
| 635 | }) |
| 636 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 637 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 638 | |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 639 | named!(item_static -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 640 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 641 | vis: syn!(Visibility) >> |
| 642 | static_: syn!(Static) >> |
| 643 | mutability: syn!(Mutability) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 644 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 645 | colon: syn!(Colon) >> |
| 646 | ty: syn!(Ty) >> |
| 647 | eq: syn!(Eq) >> |
| 648 | value: syn!(Expr) >> |
| 649 | semi: syn!(Semi) >> |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 650 | (Item { |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 651 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 652 | node: ItemStatic { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 653 | vis: vis, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 654 | static_token: static_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 655 | mutbl: mutability, |
| 656 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 657 | colon_token: colon, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 658 | ty: Box::new(ty), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 659 | eq_token: eq, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 660 | expr: Box::new(value), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 661 | semi_token: semi, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 662 | }.into(), |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 663 | }) |
| 664 | )); |
| 665 | |
| 666 | named!(item_const -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 667 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 668 | vis: syn!(Visibility) >> |
| 669 | const_: syn!(Const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 670 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 671 | colon: syn!(Colon) >> |
| 672 | ty: syn!(Ty) >> |
| 673 | eq: syn!(Eq) >> |
| 674 | value: syn!(Expr) >> |
| 675 | semi: syn!(Semi) >> |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 676 | (Item { |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 677 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 678 | node: ItemConst { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 679 | vis: vis, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 680 | const_token: const_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 681 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 682 | colon_token: colon, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 683 | ty: Box::new(ty), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 684 | eq_token: eq, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 685 | expr: Box::new(value), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 686 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 687 | }.into(), |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 688 | }) |
| 689 | )); |
| 690 | |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 691 | named!(item_fn -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 692 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 693 | vis: syn!(Visibility) >> |
| 694 | constness: syn!(Constness) >> |
| 695 | unsafety: syn!(Unsafety) >> |
| 696 | abi: option!(syn!(Abi)) >> |
| 697 | fn_: syn!(Fn_) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 698 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 699 | generics: syn!(Generics) >> |
| 700 | inputs: parens!(Delimited::parse_terminated) >> |
| 701 | ret: syn!(FunctionRetTy) >> |
| 702 | where_clause: syn!(WhereClause) >> |
| 703 | inner_attrs_stmts: braces!(tuple!( |
| 704 | many0!(call!(Attribute::parse_inner)), |
| 705 | call!(Block::parse_within) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 706 | )) >> |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 707 | (Item { |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 708 | attrs: { |
| 709 | let mut attrs = outer_attrs; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 710 | attrs.extend((inner_attrs_stmts.0).0); |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 711 | attrs |
| 712 | }, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 713 | node: ItemFn { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 714 | vis: vis, |
| 715 | constness: constness, |
| 716 | unsafety: unsafety, |
| 717 | abi: abi, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 718 | decl: Box::new(FnDecl { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 719 | dot_tokens: None, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 720 | fn_token: fn_, |
| 721 | paren_token: inputs.1, |
| 722 | inputs: inputs.0, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 723 | output: ret, |
David Tolnay | 292e600 | 2016-10-29 22:03:51 -0700 | [diff] [blame] | 724 | variadic: false, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 725 | generics: Generics { |
| 726 | where_clause: where_clause, |
| 727 | .. generics |
| 728 | }, |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 729 | }), |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 730 | ident: ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 731 | block: Box::new(Block { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 732 | brace_token: inner_attrs_stmts.1, |
| 733 | stmts: (inner_attrs_stmts.0).1, |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 734 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 735 | }.into(), |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 736 | }) |
| 737 | )); |
| 738 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 739 | impl Synom for FnArg { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 740 | named!(parse -> Self, alt!( |
| 741 | do_parse!( |
| 742 | and: syn!(And) >> |
| 743 | lt: option!(syn!(Lifetime)) >> |
| 744 | mutability: syn!(Mutability) >> |
| 745 | self_: syn!(Self_) >> |
| 746 | not!(syn!(Colon)) >> |
| 747 | (ArgSelfRef { |
| 748 | lifetime: lt, |
| 749 | mutbl: mutability, |
| 750 | and_token: and, |
| 751 | self_token: self_, |
| 752 | }.into()) |
| 753 | ) |
| 754 | | |
| 755 | do_parse!( |
| 756 | mutability: syn!(Mutability) >> |
| 757 | self_: syn!(Self_) >> |
| 758 | not!(syn!(Colon)) >> |
| 759 | (ArgSelf { |
| 760 | mutbl: mutability, |
| 761 | self_token: self_, |
| 762 | }.into()) |
| 763 | ) |
| 764 | | |
| 765 | do_parse!( |
| 766 | pat: syn!(Pat) >> |
| 767 | colon: syn!(Colon) >> |
| 768 | ty: syn!(Ty) >> |
| 769 | (ArgCaptured { |
| 770 | pat: pat, |
| 771 | ty: ty, |
| 772 | colon_token: colon, |
| 773 | }.into()) |
| 774 | ) |
| 775 | | |
| 776 | syn!(Ty) => { FnArg::Ignored } |
| 777 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 778 | } |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 779 | |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 780 | named!(item_mod -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 781 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 782 | vis: syn!(Visibility) >> |
| 783 | mod_: syn!(Mod) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 784 | ident: syn!(Ident) >> |
| 785 | content_semi: alt!( |
| 786 | syn!(Semi) => {|semi| ( |
| 787 | Vec::new(), |
| 788 | None, |
| 789 | Some(semi), |
| 790 | )} |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 791 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 792 | braces!( |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 793 | tuple!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 794 | many0!(call!(Attribute::parse_inner)), |
| 795 | many0!(syn!(Item)) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 796 | ) |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 797 | ) => {|((inner_attrs, items), brace)| ( |
| 798 | inner_attrs, |
| 799 | Some((brace, items)), |
| 800 | None, |
| 801 | )} |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 802 | ) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 803 | (Item { |
| 804 | attrs: { |
| 805 | let mut attrs = outer_attrs; |
| 806 | attrs.extend(content_semi.0); |
| 807 | attrs |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 808 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 809 | node: ItemMod { |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 810 | vis: vis, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 811 | mod_token: mod_, |
| 812 | ident: ident, |
| 813 | content: content_semi.1, |
| 814 | semi: content_semi.2, |
| 815 | }.into(), |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 816 | }) |
| 817 | )); |
| 818 | |
| 819 | named!(item_foreign_mod -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 820 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 821 | abi: syn!(Abi) >> |
| 822 | items: braces!(many0!(syn!(ForeignItem))) >> |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 823 | (Item { |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 824 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 825 | node: ItemForeignMod { |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 826 | abi: abi, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 827 | brace_token: items.1, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 828 | items: items.0, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 829 | }.into(), |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 830 | }) |
| 831 | )); |
| 832 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 833 | impl Synom for ForeignItem { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 834 | named!(parse -> Self, alt!( |
| 835 | foreign_fn |
| 836 | | |
| 837 | foreign_static |
| 838 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 839 | } |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 840 | |
| 841 | named!(foreign_fn -> ForeignItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 842 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 843 | vis: syn!(Visibility) >> |
| 844 | fn_: syn!(Fn_) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 845 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 846 | generics: syn!(Generics) >> |
| 847 | inputs: parens!(do_parse!( |
| 848 | args: call!(Delimited::parse_terminated) >> |
| 849 | variadic: cond!(args.is_empty() || args.trailing_delim(), |
| 850 | option!(syn!(Dot3))) >> |
| 851 | (args, variadic) |
| 852 | )) >> |
| 853 | ret: syn!(FunctionRetTy) >> |
| 854 | where_clause: syn!(WhereClause) >> |
| 855 | semi: syn!(Semi) >> |
| 856 | ({ |
| 857 | let ((inputs, variadic), parens) = inputs; |
| 858 | let variadic = variadic.and_then(|v| v); |
| 859 | ForeignItem { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 860 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 861 | attrs: attrs, |
| 862 | semi_token: semi, |
| 863 | node: ForeignItemFn { |
| 864 | decl: Box::new(FnDecl { |
| 865 | fn_token: fn_, |
| 866 | paren_token: parens, |
| 867 | inputs: inputs, |
| 868 | variadic: variadic.is_some(), |
| 869 | dot_tokens: variadic, |
| 870 | output: ret, |
| 871 | generics: Generics { |
| 872 | where_clause: where_clause, |
| 873 | .. generics |
| 874 | }, |
| 875 | }), |
| 876 | }.into(), |
| 877 | vis: vis, |
| 878 | } |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 879 | }) |
| 880 | )); |
| 881 | |
| 882 | named!(foreign_static -> ForeignItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 883 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 884 | vis: syn!(Visibility) >> |
| 885 | static_: syn!(Static) >> |
| 886 | mutability: syn!(Mutability) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 887 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 888 | colon: syn!(Colon) >> |
| 889 | ty: syn!(Ty) >> |
| 890 | semi: syn!(Semi) >> |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 891 | (ForeignItem { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 892 | ident: ident, |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 893 | attrs: attrs, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 894 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 895 | node: ForeignItemStatic { |
| 896 | ty: Box::new(ty), |
| 897 | mutbl: mutability, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 898 | static_token: static_, |
| 899 | colon_token: colon, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 900 | }.into(), |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 901 | vis: vis, |
| 902 | }) |
| 903 | )); |
| 904 | |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 905 | named!(item_ty -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 906 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 907 | vis: syn!(Visibility) >> |
| 908 | type_: syn!(Type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 909 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 910 | generics: syn!(Generics) >> |
| 911 | where_clause: syn!(WhereClause) >> |
| 912 | eq: syn!(Eq) >> |
| 913 | ty: syn!(Ty) >> |
| 914 | semi: syn!(Semi) >> |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 915 | (Item { |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 916 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 917 | node: ItemTy { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 918 | vis: vis, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 919 | type_token: type_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 920 | ident: ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 921 | generics: Generics { |
David Tolnay | 04bb3ad | 2016-10-30 10:59:01 -0700 | [diff] [blame] | 922 | where_clause: where_clause, |
| 923 | ..generics |
| 924 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 925 | eq_token: eq, |
| 926 | ty: Box::new(ty), |
| 927 | semi_token: semi, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 928 | }.into(), |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 929 | }) |
| 930 | )); |
| 931 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 932 | named!(item_struct_or_enum -> Item, map!(syn!(DeriveInput), Into::into)); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 933 | |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 934 | named!(item_union -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 935 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 936 | vis: syn!(Visibility) >> |
| 937 | union_: syn!(Union) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 938 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 939 | generics: syn!(Generics) >> |
| 940 | where_clause: syn!(WhereClause) >> |
| 941 | fields: braces!(call!(Delimited::parse_terminated_with, |
| 942 | Field::parse_struct)) >> |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 943 | (Item { |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 944 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 945 | node: ItemUnion { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 946 | vis: vis, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 947 | union_token: union_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 948 | ident: ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 949 | generics: Generics { |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 950 | where_clause: where_clause, |
| 951 | .. generics |
| 952 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 953 | data: VariantData::Struct(fields.0, fields.1), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 954 | }.into(), |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 955 | }) |
| 956 | )); |
| 957 | |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 958 | named!(item_trait -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 959 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 960 | vis: syn!(Visibility) >> |
| 961 | unsafety: syn!(Unsafety) >> |
| 962 | trait_: syn!(Trait) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 963 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 964 | generics: syn!(Generics) >> |
| 965 | colon: option!(syn!(Colon)) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 966 | bounds: cond!(colon.is_some(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 967 | call!(Delimited::parse_separated_nonempty) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 968 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 969 | where_clause: syn!(WhereClause) >> |
| 970 | body: braces!(many0!(syn!(TraitItem))) >> |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 971 | (Item { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 972 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 973 | node: ItemTrait { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 974 | vis: vis, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 975 | unsafety: unsafety, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 976 | trait_token: trait_, |
| 977 | ident: ident, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 978 | generics: Generics { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 979 | where_clause: where_clause, |
| 980 | .. generics |
| 981 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 982 | colon_token: colon, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 983 | supertraits: bounds.unwrap_or_default(), |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 984 | brace_token: body.1, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 985 | items: body.0, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 986 | }.into(), |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 987 | }) |
| 988 | )); |
| 989 | |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 990 | named!(item_default_impl -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 991 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 992 | unsafety: syn!(Unsafety) >> |
| 993 | impl_: syn!(Impl) >> |
| 994 | path: syn!(Path) >> |
| 995 | for_: syn!(For) >> |
| 996 | dot2: syn!(Dot2) >> |
| 997 | braces: braces!(epsilon!()) >> |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 998 | (Item { |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 999 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1000 | node: ItemDefaultImpl { |
| 1001 | unsafety: unsafety, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1002 | impl_token: impl_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1003 | path: path, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1004 | for_token: for_, |
| 1005 | dot2_token: dot2, |
| 1006 | brace_token: braces.1, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1007 | }.into(), |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 1008 | }) |
| 1009 | )); |
| 1010 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1011 | impl Synom for TraitItem { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1012 | named!(parse -> Self, alt!( |
| 1013 | trait_item_const |
| 1014 | | |
| 1015 | trait_item_method |
| 1016 | | |
| 1017 | trait_item_type |
| 1018 | | |
| 1019 | trait_item_mac |
| 1020 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1021 | } |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1022 | |
| 1023 | named!(trait_item_const -> TraitItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1024 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1025 | const_: syn!(Const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1026 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1027 | colon: syn!(Colon) >> |
| 1028 | ty: syn!(Ty) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1029 | default: option!(tuple!(syn!(Eq), syn!(Expr))) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1030 | semi: syn!(Semi) >> |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1031 | (TraitItem { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1032 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1033 | node: TraitItemConst { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1034 | const_token: const_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1035 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1036 | colon_token: colon, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1037 | ty: ty, |
| 1038 | default: default, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1039 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1040 | }.into(), |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1041 | }) |
| 1042 | )); |
| 1043 | |
| 1044 | named!(trait_item_method -> TraitItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1045 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1046 | constness: syn!(Constness) >> |
| 1047 | unsafety: syn!(Unsafety) >> |
| 1048 | abi: option!(syn!(Abi)) >> |
| 1049 | fn_: syn!(Fn_) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1050 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1051 | generics: syn!(Generics) >> |
| 1052 | inputs: parens!(call!(Delimited::parse_terminated)) >> |
| 1053 | ret: syn!(FunctionRetTy) >> |
| 1054 | where_clause: syn!(WhereClause) >> |
| 1055 | body: option!(braces!( |
| 1056 | tuple!(many0!(call!(Attribute::parse_inner)), |
| 1057 | call!(Block::parse_within)) |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1058 | )) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1059 | semi: cond!(body.is_none(), syn!(Semi)) >> |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1060 | ({ |
| 1061 | let (inner_attrs, stmts) = match body { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1062 | Some(((inner_attrs, stmts), b)) => (inner_attrs, Some((stmts, b))), |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1063 | None => (Vec::new(), None), |
| 1064 | }; |
| 1065 | TraitItem { |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1066 | attrs: { |
| 1067 | let mut attrs = outer_attrs; |
| 1068 | attrs.extend(inner_attrs); |
| 1069 | attrs |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1070 | }, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1071 | node: TraitItemMethod { |
| 1072 | sig: MethodSig { |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1073 | constness: constness, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1074 | unsafety: unsafety, |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1075 | abi: abi, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1076 | ident: ident, |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1077 | decl: FnDecl { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1078 | inputs: inputs.0, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1079 | output: ret, |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1080 | variadic: false, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1081 | fn_token: fn_, |
| 1082 | paren_token: inputs.1, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1083 | dot_tokens: None, |
| 1084 | generics: Generics { |
| 1085 | where_clause: where_clause, |
| 1086 | .. generics |
| 1087 | }, |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1088 | }, |
| 1089 | }, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1090 | default: stmts.map(|stmts| { |
| 1091 | Block { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1092 | stmts: stmts.0, |
| 1093 | brace_token: stmts.1, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1094 | } |
| 1095 | }), |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1096 | semi_token: semi, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1097 | }.into(), |
David Tolnay | 5859df1 | 2016-10-29 22:49:54 -0700 | [diff] [blame] | 1098 | } |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1099 | }) |
| 1100 | )); |
| 1101 | |
| 1102 | named!(trait_item_type -> TraitItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1103 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1104 | type_: syn!(Type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1105 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1106 | colon: option!(syn!(Colon)) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1107 | bounds: cond!(colon.is_some(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1108 | call!(Delimited::parse_separated_nonempty) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1109 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1110 | default: option!(tuple!(syn!(Eq), syn!(Ty))) >> |
| 1111 | semi: syn!(Semi) >> |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1112 | (TraitItem { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1113 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1114 | node: TraitItemType { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1115 | type_token: type_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1116 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1117 | colon_token: colon, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1118 | bounds: bounds.unwrap_or_default(), |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1119 | default: default, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1120 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1121 | }.into(), |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1122 | }) |
| 1123 | )); |
| 1124 | |
| 1125 | named!(trait_item_mac -> TraitItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1126 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1127 | mac: syn!(Mac) >> |
| 1128 | cond!(!mac.is_braced(), syn!(Semi)) >> |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1129 | (TraitItem { |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1130 | attrs: attrs, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1131 | node: TraitItemKind::Macro(mac), |
David Tolnay | 0aecb73 | 2016-10-03 23:03:50 -0700 | [diff] [blame] | 1132 | }) |
| 1133 | )); |
| 1134 | |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1135 | named!(item_impl -> Item, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1136 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1137 | unsafety: syn!(Unsafety) >> |
| 1138 | impl_: syn!(Impl) >> |
| 1139 | generics: syn!(Generics) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1140 | polarity_path: alt!( |
| 1141 | do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1142 | polarity: syn!(ImplPolarity) >> |
| 1143 | path: syn!(Path) >> |
| 1144 | for_: syn!(For) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1145 | (Some((polarity, path, for_))) |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1146 | ) |
| 1147 | | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1148 | epsilon!() => { |_| None } |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1149 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1150 | self_ty: syn!(Ty) >> |
| 1151 | where_clause: syn!(WhereClause) >> |
| 1152 | body: braces!(many0!(syn!(ImplItem))) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1153 | (Item { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1154 | attrs: attrs, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1155 | node: ItemImpl { |
| 1156 | unsafety: unsafety, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1157 | impl_token: impl_, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1158 | generics: Generics { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1159 | where_clause: where_clause, |
| 1160 | .. generics |
| 1161 | }, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1162 | trait_: polarity_path, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1163 | self_ty: Box::new(self_ty), |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1164 | brace_token: body.1, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1165 | items: body.0, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1166 | }.into(), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1167 | }) |
| 1168 | )); |
| 1169 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1170 | impl Synom for ImplItem { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1171 | named!(parse -> Self, alt!( |
| 1172 | impl_item_const |
| 1173 | | |
| 1174 | impl_item_method |
| 1175 | | |
| 1176 | impl_item_type |
| 1177 | | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1178 | impl_item_mac |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1179 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1180 | } |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1181 | |
| 1182 | named!(impl_item_const -> ImplItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1183 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1184 | vis: syn!(Visibility) >> |
| 1185 | defaultness: syn!(Defaultness) >> |
| 1186 | const_: syn!(Const) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1187 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1188 | colon: syn!(Colon) >> |
| 1189 | ty: syn!(Ty) >> |
| 1190 | eq: syn!(Eq) >> |
| 1191 | value: syn!(Expr) >> |
| 1192 | semi: syn!(Semi) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1193 | (ImplItem { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1194 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1195 | node: ImplItemConst { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1196 | vis: vis, |
| 1197 | defaultness: defaultness, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1198 | const_token: const_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1199 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1200 | colon_token: colon, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1201 | ty: ty, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1202 | eq_token: eq, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1203 | expr: value, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1204 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1205 | }.into(), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1206 | }) |
| 1207 | )); |
| 1208 | |
| 1209 | named!(impl_item_method -> ImplItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1210 | outer_attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1211 | vis: syn!(Visibility) >> |
| 1212 | defaultness: syn!(Defaultness) >> |
| 1213 | constness: syn!(Constness) >> |
| 1214 | unsafety: syn!(Unsafety) >> |
| 1215 | abi: option!(syn!(Abi)) >> |
| 1216 | fn_: syn!(Fn_) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1217 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1218 | generics: syn!(Generics) >> |
| 1219 | inputs: parens!(call!(Delimited::parse_terminated)) >> |
| 1220 | ret: syn!(FunctionRetTy) >> |
| 1221 | where_clause: syn!(WhereClause) >> |
| 1222 | inner_attrs_stmts: braces!(tuple!( |
| 1223 | many0!(call!(Attribute::parse_inner)), |
| 1224 | call!(Block::parse_within) |
Michael Layzell | 416724e | 2017-05-24 21:12:34 -0400 | [diff] [blame] | 1225 | )) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1226 | (ImplItem { |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1227 | attrs: { |
| 1228 | let mut attrs = outer_attrs; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1229 | attrs.extend((inner_attrs_stmts.0).0); |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1230 | attrs |
| 1231 | }, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1232 | node: ImplItemMethod { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1233 | vis: vis, |
| 1234 | defaultness: defaultness, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1235 | sig: MethodSig { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1236 | constness: constness, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1237 | unsafety: unsafety, |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1238 | abi: abi, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1239 | ident: ident, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1240 | decl: FnDecl { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1241 | fn_token: fn_, |
| 1242 | paren_token: inputs.1, |
| 1243 | inputs: inputs.0, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1244 | output: ret, |
David Tolnay | 292e600 | 2016-10-29 22:03:51 -0700 | [diff] [blame] | 1245 | variadic: false, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1246 | generics: Generics { |
| 1247 | where_clause: where_clause, |
| 1248 | .. generics |
| 1249 | }, |
| 1250 | dot_tokens: None, |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1251 | }, |
| 1252 | }, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1253 | block: Block { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1254 | brace_token: inner_attrs_stmts.1, |
| 1255 | stmts: (inner_attrs_stmts.0).1, |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1256 | }, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1257 | }.into(), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1258 | }) |
| 1259 | )); |
| 1260 | |
| 1261 | named!(impl_item_type -> ImplItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1262 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1263 | vis: syn!(Visibility) >> |
| 1264 | defaultness: syn!(Defaultness) >> |
| 1265 | type_: syn!(Type) >> |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1266 | ident: syn!(Ident) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1267 | eq: syn!(Eq) >> |
| 1268 | ty: syn!(Ty) >> |
| 1269 | semi: syn!(Semi) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1270 | (ImplItem { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1271 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1272 | node: ImplItemType { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1273 | vis: vis, |
| 1274 | defaultness: defaultness, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1275 | type_token: type_, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1276 | ident: ident, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1277 | eq_token: eq, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1278 | ty: ty, |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1279 | semi_token: semi, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1280 | }.into(), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1281 | }) |
| 1282 | )); |
| 1283 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1284 | named!(impl_item_mac -> ImplItem, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1285 | attrs: many0!(call!(Attribute::parse_outer)) >> |
| 1286 | mac: syn!(Mac) >> |
| 1287 | cond!(!mac.is_braced(), syn!(Semi)) >> |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1288 | (ImplItem { |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1289 | attrs: attrs, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1290 | node: ImplItemKind::Macro(mac), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1291 | }) |
| 1292 | )); |
| 1293 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1294 | impl Synom for ImplPolarity { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1295 | named!(parse -> Self, alt!( |
| 1296 | syn!(Bang) => { ImplPolarity::Negative } |
| 1297 | | |
| 1298 | epsilon!() => { |_| ImplPolarity::Positive } |
| 1299 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1300 | } |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1301 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1302 | impl Synom for Constness { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1303 | named!(parse -> Self, alt!( |
| 1304 | syn!(Const) => { Constness::Const } |
| 1305 | | |
| 1306 | epsilon!() => { |_| Constness::NotConst } |
| 1307 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1308 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1309 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1310 | impl Synom for Defaultness { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1311 | named!(parse -> Self, alt!( |
| 1312 | syn!(Default_) => { Defaultness::Default } |
| 1313 | | |
| 1314 | epsilon!() => { |_| Defaultness::Final } |
| 1315 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1316 | } |
David Tolnay | edf2b99 | 2016-09-23 20:43:45 -0700 | [diff] [blame] | 1317 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1318 | |
| 1319 | #[cfg(feature = "printing")] |
| 1320 | mod printing { |
| 1321 | use super::*; |
| 1322 | use attr::FilterAttrs; |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 1323 | use data::VariantData; |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1324 | use quote::{Tokens, ToTokens}; |
| 1325 | |
| 1326 | impl ToTokens for Item { |
| 1327 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1328 | tokens.append_all(self.attrs.outer()); |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1329 | match self.node { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1330 | ItemKind::ExternCrate(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1331 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1332 | item.extern_token.to_tokens(tokens); |
| 1333 | item.crate_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1334 | item.ident.to_tokens(tokens); |
David Tolnay | b99e1b0 | 2017-06-03 19:00:55 -0700 | [diff] [blame] | 1335 | if let Some((ref as_token, ref rename)) = item.rename { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1336 | as_token.to_tokens(tokens); |
| 1337 | rename.to_tokens(tokens); |
| 1338 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1339 | item.semi_token.to_tokens(tokens); |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1340 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1341 | ItemKind::Use(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1342 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1343 | item.use_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1344 | item.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1345 | item.semi_token.to_tokens(tokens); |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1346 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1347 | ItemKind::Static(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1348 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1349 | item.static_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1350 | item.mutbl.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1351 | item.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1352 | item.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1353 | item.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1354 | item.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1355 | item.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1356 | item.semi_token.to_tokens(tokens); |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 1357 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1358 | ItemKind::Const(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1359 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1360 | item.const_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1361 | item.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1362 | item.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1363 | item.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1364 | item.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1365 | item.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1366 | item.semi_token.to_tokens(tokens); |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 1367 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1368 | ItemKind::Fn(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1369 | item.vis.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1370 | item.constness.to_tokens(tokens); |
| 1371 | item.unsafety.to_tokens(tokens); |
| 1372 | item.abi.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1373 | NamedDecl(&item.decl, item.ident).to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1374 | item.block.brace_token.surround(tokens, |tokens| { |
| 1375 | tokens.append_all(self.attrs.inner()); |
| 1376 | tokens.append_all(&item.block.stmts); |
| 1377 | }); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1378 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1379 | ItemKind::Mod(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1380 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1381 | item.mod_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1382 | item.ident.to_tokens(tokens); |
David Tolnay | b99e1b0 | 2017-06-03 19:00:55 -0700 | [diff] [blame] | 1383 | if let Some((ref brace, ref items)) = item.content { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1384 | brace.surround(tokens, |tokens| { |
David Tolnay | 7b8009b | 2016-10-25 22:36:00 -0700 | [diff] [blame] | 1385 | tokens.append_all(self.attrs.inner()); |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 1386 | tokens.append_all(items); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1387 | }); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1388 | } else { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1389 | TokensOrDefault(&item.semi).to_tokens(tokens); |
David Tolnay | 37d1033 | 2016-10-13 20:51:04 -0700 | [diff] [blame] | 1390 | } |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1391 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1392 | ItemKind::ForeignMod(ref item) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1393 | item.abi.to_tokens(tokens); |
| 1394 | item.brace_token.surround(tokens, |tokens| { |
| 1395 | tokens.append_all(&item.items); |
| 1396 | }); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1397 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1398 | ItemKind::Ty(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.type_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 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1404 | item.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1405 | item.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1406 | item.semi_token.to_tokens(tokens); |
David Tolnay | 3cf5298 | 2016-10-01 17:11:37 -0700 | [diff] [blame] | 1407 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1408 | ItemKind::Enum(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1409 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1410 | item.enum_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1411 | item.ident.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1412 | item.generics.to_tokens(tokens); |
| 1413 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1414 | item.brace_token.surround(tokens, |tokens| { |
| 1415 | item.variants.to_tokens(tokens); |
| 1416 | }); |
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::Struct(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.struct_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 | match item.data { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1424 | VariantData::Struct(..) => { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1425 | item.generics.where_clause.to_tokens(tokens); |
| 1426 | item.data.to_tokens(tokens); |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 1427 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1428 | VariantData::Tuple(..) => { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1429 | item.data.to_tokens(tokens); |
| 1430 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1431 | TokensOrDefault(&item.semi_token).to_tokens(tokens); |
David Tolnay | 28c1db6 | 2016-10-27 22:48:18 -0700 | [diff] [blame] | 1432 | } |
| 1433 | VariantData::Unit => { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1434 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1435 | TokensOrDefault(&item.semi_token).to_tokens(tokens); |
David Tolnay | 28c1db6 | 2016-10-27 22:48:18 -0700 | [diff] [blame] | 1436 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1437 | } |
| 1438 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1439 | ItemKind::Union(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1440 | item.vis.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1441 | item.union_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1442 | item.ident.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1443 | item.generics.to_tokens(tokens); |
| 1444 | item.generics.where_clause.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1445 | // XXX: Should we handle / complain when using a |
| 1446 | // non-VariantData::Struct Variant in Union? |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1447 | item.data.to_tokens(tokens); |
David Tolnay | 2f9fa63 | 2016-10-03 22:08:48 -0700 | [diff] [blame] | 1448 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1449 | ItemKind::Trait(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1450 | item.vis.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1451 | item.unsafety.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1452 | item.trait_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1453 | item.ident.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1454 | item.generics.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1455 | if !item.supertraits.is_empty() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1456 | TokensOrDefault(&item.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1457 | item.supertraits.to_tokens(tokens); |
| 1458 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1459 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1460 | item.brace_token.surround(tokens, |tokens| { |
| 1461 | tokens.append_all(&item.items); |
| 1462 | }); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1463 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1464 | ItemKind::DefaultImpl(ref item) => { |
| 1465 | item.unsafety.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1466 | item.impl_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1467 | item.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1468 | item.for_token.to_tokens(tokens); |
| 1469 | item.dot2_token.to_tokens(tokens); |
| 1470 | item.brace_token.surround(tokens, |_tokens| {}); |
David Tolnay | f94e236 | 2016-10-04 00:29:51 -0700 | [diff] [blame] | 1471 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1472 | ItemKind::Impl(ref item) => { |
| 1473 | item.unsafety.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1474 | item.impl_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1475 | item.generics.to_tokens(tokens); |
David Tolnay | b99e1b0 | 2017-06-03 19:00:55 -0700 | [diff] [blame] | 1476 | if let Some((ref polarity, ref path, ref for_token)) = item.trait_ { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1477 | polarity.to_tokens(tokens); |
| 1478 | path.to_tokens(tokens); |
| 1479 | for_token.to_tokens(tokens); |
| 1480 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1481 | item.self_ty.to_tokens(tokens); |
| 1482 | item.generics.where_clause.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1483 | item.brace_token.surround(tokens, |tokens| { |
| 1484 | tokens.append_all(&item.items); |
| 1485 | }); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1486 | } |
David Tolnay | cc3d66e | 2016-10-02 23:36:05 -0700 | [diff] [blame] | 1487 | ItemKind::Mac(ref mac) => { |
| 1488 | mac.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1489 | mac.bang_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1490 | mac.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1491 | tokens.append_all(&mac.tokens); |
| 1492 | if !mac.is_braced() { |
| 1493 | tokens::Semi::default().to_tokens(tokens); |
David Tolnay | cc3d66e | 2016-10-02 23:36:05 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1499 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1500 | impl ToTokens for PathSimple { |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1501 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1502 | self.path.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1503 | if self.rename.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1504 | TokensOrDefault(&self.as_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1505 | self.rename.to_tokens(tokens); |
| 1506 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1510 | impl ToTokens for PathGlob { |
| 1511 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | af9d295 | 2017-08-27 10:19:54 -0700 | [diff] [blame] | 1512 | if self.path.segments.len() > 0 { |
| 1513 | self.path.to_tokens(tokens); |
| 1514 | TokensOrDefault(&self.colon2_token).to_tokens(tokens); |
| 1515 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1516 | self.star_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | impl ToTokens for PathList { |
| 1521 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1522 | self.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1523 | self.colon2_token.to_tokens(tokens); |
| 1524 | self.brace_token.surround(tokens, |tokens| { |
| 1525 | self.items.to_tokens(tokens); |
| 1526 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1530 | impl ToTokens for PathListItem { |
| 1531 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1532 | self.name.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1533 | if self.rename.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1534 | TokensOrDefault(&self.as_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1535 | self.rename.to_tokens(tokens); |
| 1536 | } |
David Tolnay | 4a05742 | 2016-10-08 00:02:31 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1540 | impl ToTokens for TraitItem { |
| 1541 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1542 | tokens.append_all(self.attrs.outer()); |
| 1543 | match self.node { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1544 | TraitItemKind::Const(ref item) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1545 | item.const_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1546 | item.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1547 | item.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1548 | item.ty.to_tokens(tokens); |
David Tolnay | b99e1b0 | 2017-06-03 19:00:55 -0700 | [diff] [blame] | 1549 | if let Some((ref eq_token, ref default)) = item.default { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1550 | eq_token.to_tokens(tokens); |
| 1551 | default.to_tokens(tokens); |
| 1552 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1553 | item.semi_token.to_tokens(tokens); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1554 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1555 | TraitItemKind::Method(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1556 | item.sig.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1557 | match item.default { |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1558 | Some(ref block) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1559 | block.brace_token.surround(tokens, |tokens| { |
| 1560 | tokens.append_all(self.attrs.inner()); |
| 1561 | tokens.append_all(&block.stmts); |
| 1562 | }); |
David Tolnay | 3b9783a | 2016-10-29 22:37:09 -0700 | [diff] [blame] | 1563 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1564 | None => { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1565 | TokensOrDefault(&item.semi_token).to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1566 | } |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1569 | TraitItemKind::Type(ref item) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1570 | item.type_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1571 | item.ident.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1572 | if !item.bounds.is_empty() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1573 | TokensOrDefault(&item.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1574 | item.bounds.to_tokens(tokens); |
| 1575 | } |
David Tolnay | b99e1b0 | 2017-06-03 19:00:55 -0700 | [diff] [blame] | 1576 | if let Some((ref eq_token, ref default)) = item.default { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1577 | eq_token.to_tokens(tokens); |
| 1578 | default.to_tokens(tokens); |
| 1579 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1580 | item.semi_token.to_tokens(tokens); |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1581 | } |
| 1582 | TraitItemKind::Macro(ref mac) => { |
| 1583 | mac.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1584 | if !mac.is_braced() { |
| 1585 | tokens::Semi::default().to_tokens(tokens); |
David Tolnay | e319893 | 2016-10-04 00:21:34 -0700 | [diff] [blame] | 1586 | } |
David Tolnay | ca08542 | 2016-10-04 00:12:38 -0700 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1592 | impl ToTokens for ImplItem { |
| 1593 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1594 | tokens.append_all(self.attrs.outer()); |
| 1595 | match self.node { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1596 | ImplItemKind::Const(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1597 | item.vis.to_tokens(tokens); |
| 1598 | item.defaultness.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1599 | item.const_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1600 | item.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1601 | item.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1602 | item.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1603 | item.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1604 | item.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1605 | item.semi_token.to_tokens(tokens); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1606 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1607 | ImplItemKind::Method(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1608 | item.vis.to_tokens(tokens); |
| 1609 | item.defaultness.to_tokens(tokens); |
| 1610 | item.sig.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1611 | item.block.brace_token.surround(tokens, |tokens| { |
| 1612 | tokens.append_all(self.attrs.inner()); |
| 1613 | tokens.append_all(&item.block.stmts); |
| 1614 | }); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1615 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1616 | ImplItemKind::Type(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1617 | item.vis.to_tokens(tokens); |
| 1618 | item.defaultness.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1619 | item.type_token.to_tokens(tokens); |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1620 | item.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1621 | item.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1622 | item.ty.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1623 | item.semi_token.to_tokens(tokens); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1624 | } |
| 1625 | ImplItemKind::Macro(ref mac) => { |
| 1626 | mac.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1627 | if !mac.is_braced() { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1628 | // FIXME needs a span |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1629 | tokens::Semi::default().to_tokens(tokens); |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | } |
| 1635 | |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1636 | impl ToTokens for ForeignItem { |
| 1637 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1638 | tokens.append_all(self.attrs.outer()); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1639 | self.vis.to_tokens(tokens); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1640 | match self.node { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1641 | ForeignItemKind::Fn(ref item) => { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1642 | NamedDecl(&item.decl, self.ident).to_tokens(tokens) |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1643 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1644 | ForeignItemKind::Static(ref item) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1645 | item.static_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1646 | item.mutbl.to_tokens(tokens); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1647 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1648 | item.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1649 | item.ty.to_tokens(tokens); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1652 | self.semi_token.to_tokens(tokens); |
| 1653 | } |
| 1654 | } |
| 1655 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1656 | impl ToTokens for MethodSig { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1657 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1658 | self.constness.to_tokens(tokens); |
| 1659 | self.unsafety.to_tokens(tokens); |
| 1660 | self.abi.to_tokens(tokens); |
| 1661 | NamedDecl(&self.decl, self.ident).to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | |
David Tolnay | 570695e | 2017-06-03 16:15:13 -0700 | [diff] [blame] | 1665 | struct NamedDecl<'a>(&'a FnDecl, Ident); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1666 | |
| 1667 | impl<'a> ToTokens for NamedDecl<'a> { |
| 1668 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1669 | self.0.fn_token.to_tokens(tokens); |
| 1670 | self.1.to_tokens(tokens); |
| 1671 | self.0.generics.to_tokens(tokens); |
| 1672 | self.0.paren_token.surround(tokens, |tokens| { |
| 1673 | self.0.inputs.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1674 | |
| 1675 | if self.0.variadic { |
| 1676 | if !self.0.inputs.empty_or_trailing() { |
| 1677 | tokens::Comma::default().to_tokens(tokens); |
| 1678 | } |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 1679 | TokensOrDefault(&self.0.dot_tokens).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1680 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1681 | }); |
| 1682 | self.0.output.to_tokens(tokens); |
| 1683 | self.0.generics.where_clause.to_tokens(tokens); |
David Tolnay | 3590230 | 2016-10-06 01:11:08 -0700 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1687 | impl ToTokens for ArgSelfRef { |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1688 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1689 | self.and_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1690 | self.lifetime.to_tokens(tokens); |
| 1691 | self.mutbl.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1692 | self.self_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | impl ToTokens for ArgSelf { |
| 1697 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1698 | self.mutbl.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1699 | self.self_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | impl ToTokens for ArgCaptured { |
| 1704 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1705 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1706 | self.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1707 | self.ty.to_tokens(tokens); |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1711 | impl ToTokens for Constness { |
| 1712 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1713 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1714 | Constness::Const(ref t) => t.to_tokens(tokens), |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 1715 | Constness::NotConst => { |
| 1716 | // nothing |
| 1717 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1722 | impl ToTokens for Defaultness { |
| 1723 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1724 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1725 | Defaultness::Default(ref t) => t.to_tokens(tokens), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1726 | Defaultness::Final => { |
| 1727 | // nothing |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | impl ToTokens for ImplPolarity { |
| 1734 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1735 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1736 | ImplPolarity::Negative(ref t) => t.to_tokens(tokens), |
David Tolnay | 4c9be37 | 2016-10-06 00:47:37 -0700 | [diff] [blame] | 1737 | ImplPolarity::Positive => { |
| 1738 | // nothing |
| 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1743 | } |