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