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