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