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