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