Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1 | use delimited::Delimited; |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 2 | use super::*; |
| 3 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 4 | ast_enum_of_structs! { |
| 5 | /// The different kinds of types recognized by the compiler |
| 6 | pub enum Ty { |
| 7 | /// A variable-length array (`[T]`) |
| 8 | pub Slice(TySlice { |
| 9 | pub ty: Box<Ty>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 10 | pub bracket_token: tokens::Bracket, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 11 | }), |
| 12 | /// A fixed length array (`[T; n]`) |
| 13 | pub Array(TyArray { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 14 | pub bracket_token: tokens::Bracket, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 15 | pub ty: Box<Ty>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 16 | pub semi_token: tokens::Semi, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 17 | pub amt: ConstExpr, |
| 18 | }), |
| 19 | /// A raw pointer (`*const T` or `*mut T`) |
| 20 | pub Ptr(TyPtr { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 21 | pub star_token: tokens::Star, |
| 22 | pub const_token: Option<tokens::Const>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 23 | pub ty: Box<MutTy>, |
| 24 | }), |
| 25 | /// A reference (`&'a T` or `&'a mut T`) |
| 26 | pub Rptr(TyRptr { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 27 | pub and_token: tokens::And, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 28 | pub lifetime: Option<Lifetime>, |
| 29 | pub ty: Box<MutTy>, |
| 30 | }), |
| 31 | /// A bare function (e.g. `fn(usize) -> bool`) |
| 32 | pub BareFn(TyBareFn { |
| 33 | pub ty: Box<BareFnTy>, |
| 34 | }), |
| 35 | /// The never type (`!`) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 36 | pub Never(TyNever { |
| 37 | pub bang_token: tokens::Bang, |
| 38 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 39 | /// A tuple (`(A, B, C, D, ...)`) |
| 40 | pub Tup(TyTup { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 41 | pub paren_token: tokens::Paren, |
| 42 | pub tys: Delimited<Ty, tokens::Comma>, |
| 43 | pub lone_comma: Option<tokens::Comma>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 44 | }), |
| 45 | /// A path (`module::module::...::Type`), optionally |
| 46 | /// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`. |
| 47 | /// |
| 48 | /// Type parameters are stored in the Path itself |
| 49 | pub Path(TyPath { |
| 50 | pub qself: Option<QSelf>, |
| 51 | pub path: Path, |
| 52 | }), |
| 53 | /// A trait object type `Bound1 + Bound2 + Bound3` |
| 54 | /// where `Bound` is a trait or a lifetime. |
| 55 | pub TraitObject(TyTraitObject { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 56 | pub bounds: Delimited<TyParamBound, tokens::Add>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 57 | }), |
| 58 | /// An `impl Bound1 + Bound2 + Bound3` type |
| 59 | /// where `Bound` is a trait or a lifetime. |
| 60 | pub ImplTrait(TyImplTrait { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 61 | pub impl_token: tokens::Impl, |
| 62 | pub bounds: Delimited<TyParamBound, tokens::Add>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 63 | }), |
| 64 | /// No-op; kept solely so that we can pretty-print faithfully |
| 65 | pub Paren(TyParen { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 66 | pub paren_token: tokens::Paren, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 67 | pub ty: Box<Ty>, |
| 68 | }), |
| 69 | /// TyKind::Infer means the type should be inferred instead of it having been |
| 70 | /// specified. This can appear anywhere in a type. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 71 | pub Infer(TyInfer { |
| 72 | pub underscore_token: tokens::Underscore |
| 73 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 74 | /// A macro in the type position. |
| 75 | pub Mac(Mac), |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ast_struct! { |
| 80 | pub struct MutTy { |
| 81 | pub ty: Ty, |
| 82 | pub mutability: Mutability, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 87 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 88 | pub enum Mutability { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 89 | Mutable(tokens::Mut), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 90 | Immutable, |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | ast_struct! { |
| 95 | /// A "Path" is essentially Rust's notion of a name. |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 96 | /// |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 97 | /// It's represented as a sequence of identifiers, |
| 98 | /// along with a bunch of supporting information. |
| 99 | /// |
| 100 | /// E.g. `std::cmp::PartialEq` |
| 101 | pub struct Path { |
| 102 | /// A `::foo` path, is relative to the crate root rather than current |
| 103 | /// module (like paths in an import). |
| 104 | pub global: bool, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 105 | pub leading_colon: Option<tokens::Colon2>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 106 | /// The segments in the path: the things separated by `::`. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 107 | pub segments: Delimited<PathSegment, tokens::Colon2>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 108 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 111 | #[cfg(feature = "printing")] |
| 112 | ast_struct! { |
| 113 | pub struct PathTokens<'a>(pub &'a Option<QSelf>, pub &'a Path); |
| 114 | } |
| 115 | |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 116 | impl<T> From<T> for Path |
| 117 | where T: Into<PathSegment> |
| 118 | { |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 119 | fn from(segment: T) -> Self { |
| 120 | Path { |
| 121 | global: false, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 122 | leading_colon: None, |
| 123 | segments: vec![(segment.into(), None)].into(), |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 128 | ast_struct! { |
| 129 | /// A segment of a path: an identifier, an optional lifetime, and a set of types. |
| 130 | /// |
| 131 | /// E.g. `std`, `String` or `Box<T>` |
| 132 | pub struct PathSegment { |
| 133 | /// The identifier portion of this path segment. |
| 134 | pub ident: Ident, |
| 135 | /// Type/lifetime parameters attached to this path. They come in |
| 136 | /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that |
| 137 | /// this is more than just simple syntactic sugar; the use of |
| 138 | /// parens affects the region binding rules, so we preserve the |
| 139 | /// distinction. |
| 140 | pub parameters: PathParameters, |
| 141 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 142 | } |
| 143 | |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 144 | impl<T> From<T> for PathSegment |
| 145 | where T: Into<Ident> |
| 146 | { |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 147 | fn from(ident: T) -> Self { |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 148 | PathSegment { |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 149 | ident: ident.into(), |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 150 | parameters: PathParameters::none(), |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 155 | ast_enum! { |
| 156 | /// Parameters of a path segment. |
| 157 | /// |
| 158 | /// E.g. `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)` |
| 159 | pub enum PathParameters { |
| 160 | /// The `<'a, A, B, C>` in `foo::bar::baz::<'a, A, B, C>` |
| 161 | AngleBracketed(AngleBracketedParameterData), |
| 162 | /// The `(A, B)` and `C` in `Foo(A, B) -> C` |
| 163 | Parenthesized(ParenthesizedParameterData), |
| 164 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | impl PathParameters { |
| 168 | pub fn none() -> Self { |
| 169 | PathParameters::AngleBracketed(AngleBracketedParameterData::default()) |
| 170 | } |
David Tolnay | 5332d4b | 2016-10-30 14:25:22 -0700 | [diff] [blame] | 171 | |
| 172 | pub fn is_empty(&self) -> bool { |
| 173 | match *self { |
| 174 | PathParameters::AngleBracketed(ref bracketed) => { |
David Tolnay | c1fea50 | 2016-10-30 17:54:02 -0700 | [diff] [blame] | 175 | bracketed.lifetimes.is_empty() && bracketed.types.is_empty() && |
| 176 | bracketed.bindings.is_empty() |
David Tolnay | 5332d4b | 2016-10-30 14:25:22 -0700 | [diff] [blame] | 177 | } |
| 178 | PathParameters::Parenthesized(_) => false, |
| 179 | } |
| 180 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 183 | ast_struct! { |
| 184 | /// A path like `Foo<'a, T>` |
| 185 | #[derive(Default)] |
| 186 | pub struct AngleBracketedParameterData { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 187 | pub lt_token: Option<tokens::Lt>, |
| 188 | pub gt_token: Option<tokens::Gt>, |
| 189 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 190 | /// The lifetime parameters for this path segment. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 191 | pub lifetimes: Delimited<Lifetime, tokens::Comma>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 192 | /// The type parameters for this path segment, if present. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 193 | pub types: Delimited<Ty, tokens::Comma>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 194 | /// Bindings (equality constraints) on associated types, if present. |
| 195 | /// |
| 196 | /// E.g., `Foo<A=Bar>`. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 197 | pub bindings: Delimited<TypeBinding, tokens::Comma>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | ast_struct! { |
| 202 | /// Bind a type to an associated type: `A=Foo`. |
| 203 | pub struct TypeBinding { |
| 204 | pub ident: Ident, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 205 | pub eq_token: tokens::Eq, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 206 | pub ty: Ty, |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | ast_struct! { |
| 212 | /// A path like `Foo(A,B) -> C` |
| 213 | pub struct ParenthesizedParameterData { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 214 | pub paren_token: tokens::Paren, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 215 | /// `(A, B)` |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 216 | pub inputs: Delimited<Ty, tokens::Comma>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 217 | /// `C` |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 218 | pub output: FunctionRetTy, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | ast_struct! { |
| 223 | pub struct PolyTraitRef { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 224 | /// The `for<'a>` in `for<'a> Foo<&'a T>` |
| 225 | pub bound_lifetimes: Option<BoundLifetimes>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 226 | /// The `Foo<&'a T>` in `<'a> Foo<&'a T>` |
| 227 | pub trait_ref: Path, |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | ast_struct! { |
| 232 | /// The explicit Self type in a "qualified path". The actual |
| 233 | /// path, including the trait and the associated item, is stored |
| 234 | /// separately. `position` represents the index of the associated |
| 235 | /// item qualified with this Self type. |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 236 | /// |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 237 | /// ```rust,ignore |
| 238 | /// <Vec<T> as a::b::Trait>::AssociatedItem |
| 239 | /// ^~~~~ ~~~~~~~~~~~~~~^ |
| 240 | /// ty position = 3 |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 241 | /// |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 242 | /// <Vec<T>>::AssociatedItem |
| 243 | /// ^~~~~ ^ |
| 244 | /// ty position = 0 |
| 245 | /// ``` |
| 246 | pub struct QSelf { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 247 | pub lt_token: tokens::Lt, |
| 248 | pub gt_token: tokens::Gt, |
| 249 | pub as_token: Option<tokens::As>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 250 | pub ty: Box<Ty>, |
| 251 | pub position: usize, |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | ast_struct! { |
| 256 | pub struct BareFnTy { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 257 | pub lifetimes: Option<BoundLifetimes>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 258 | pub unsafety: Unsafety, |
| 259 | pub abi: Option<Abi>, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 260 | pub fn_token: tokens::Fn_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 261 | pub paren_token: tokens::Paren, |
| 262 | pub inputs: Delimited<BareFnArg, tokens::Comma>, |
| 263 | pub variadic: Option<tokens::Dot3>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 264 | pub output: FunctionRetTy, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 269 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 270 | pub enum Unsafety { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 271 | Unsafe(tokens::Unsafe), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 272 | Normal, |
| 273 | } |
| 274 | } |
| 275 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 276 | ast_struct! { |
| 277 | pub struct Abi { |
| 278 | pub extern_token: tokens::Extern, |
| 279 | pub kind: AbiKind, |
| 280 | } |
| 281 | } |
| 282 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 283 | ast_enum! { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 284 | pub enum AbiKind { |
| 285 | Named(Lit), |
| 286 | Default, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | ast_struct! { |
| 291 | /// An argument in a function type. |
| 292 | /// |
| 293 | /// E.g. `bar: usize` as in `fn foo(bar: usize)` |
| 294 | pub struct BareFnArg { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 295 | pub name: Option<(Ident, tokens::Colon)>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 296 | pub ty: Ty, |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | ast_enum! { |
| 302 | pub enum FunctionRetTy { |
| 303 | /// Return type is not specified. |
| 304 | /// |
| 305 | /// Functions default to `()` and |
| 306 | /// closures default to inference. Span points to where return |
| 307 | /// type would be inserted. |
| 308 | Default, |
| 309 | /// Everything else |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 310 | Ty(Ty, tokens::RArrow), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 311 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 312 | } |
| 313 | |
David Tolnay | 86eca75 | 2016-09-04 11:26:41 -0700 | [diff] [blame] | 314 | #[cfg(feature = "parsing")] |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 315 | pub mod parsing { |
| 316 | use super::*; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 317 | // use {TyParamBound, TraitBoundModifier}; |
| 318 | // #[cfg(feature = "full")] |
| 319 | // use ConstExpr; |
| 320 | // #[cfg(feature = "full")] |
| 321 | // use constant::parsing::const_expr; |
| 322 | // #[cfg(feature = "full")] |
| 323 | // use expr::parsing::expr; |
| 324 | // use generics::parsing::{lifetime, ty_param_bound, bound_lifetimes}; |
| 325 | // use ident::parsing::ident; |
| 326 | // use lit::parsing::string; |
| 327 | // use mac::parsing::mac; |
| 328 | use proc_macro2::TokenTree; |
| 329 | use synom::{IResult, Synom}; |
| 330 | use synom::tokens::*; |
David Tolnay | da4049b | 2016-09-04 10:59:23 -0700 | [diff] [blame] | 331 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 332 | impl Synom for Ty { |
| 333 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 334 | alt! { |
| 335 | input, |
| 336 | // must be before mac |
| 337 | syn!(TyParen) => { Ty::Paren } |
| 338 | | |
| 339 | // must be before path |
| 340 | syn!(Mac) => { Ty::Mac } |
| 341 | | |
| 342 | // must be before ty_poly_trait_ref |
| 343 | ty_path |
| 344 | | |
| 345 | syn!(TySlice) => { Ty::Slice } |
| 346 | | |
| 347 | syn!(TyArray) => { Ty::Array } |
| 348 | | |
| 349 | syn!(TyPtr) => { Ty::Ptr } |
| 350 | | |
| 351 | syn!(TyRptr) => { Ty::Rptr } |
| 352 | | |
| 353 | syn!(TyBareFn) => { Ty::BareFn } |
| 354 | | |
| 355 | syn!(TyNever) => { Ty::Never } |
| 356 | | |
| 357 | syn!(TyTup) => { Ty::Tup } |
| 358 | | |
| 359 | ty_poly_trait_ref |
| 360 | | |
| 361 | syn!(TyImplTrait) => { Ty::ImplTrait } |
| 362 | } |
| 363 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 364 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 365 | fn description() -> Option<&'static str> { |
| 366 | Some("type") |
| 367 | } |
| 368 | } |
David Tolnay | 0047c71 | 2016-12-21 21:59:25 -0500 | [diff] [blame] | 369 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 370 | impl Synom for TySlice { |
| 371 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 372 | map! { |
| 373 | input, |
| 374 | brackets!(syn!(Ty)), |
| 375 | |(ty, b)| TySlice { |
| 376 | ty: Box::new(ty), |
| 377 | bracket_token: b, |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 382 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 383 | impl Synom for TyArray { |
| 384 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 385 | map! { |
| 386 | input, |
| 387 | brackets!(do_parse!( |
| 388 | elem: syn!(Ty) >> |
| 389 | semi: syn!(Semi) >> |
| 390 | len: array_len >> |
| 391 | (elem, semi, len) |
| 392 | )), |
| 393 | |((elem, semi, len), brackets)| { |
| 394 | TyArray { |
| 395 | ty: Box::new(elem), |
| 396 | amt: len, |
| 397 | bracket_token: brackets, |
| 398 | semi_token: semi, |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
David Tolnay | fa94b6f | 2016-10-05 23:26:11 -0700 | [diff] [blame] | 404 | |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 405 | #[cfg(not(feature = "full"))] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 406 | named!(array_len -> ConstExpr, syn!(ConstExpr)); |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 407 | |
David Tolnay | fe2cc9a | 2016-10-30 12:47:36 -0700 | [diff] [blame] | 408 | #[cfg(feature = "full")] |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 409 | named!(array_len -> ConstExpr, alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 410 | terminated!(syn!(ConstExpr), input_end!()) |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 411 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 412 | terminated!(syn!(Expr), input_end!()) => { ConstExpr::Other } |
David Tolnay | fe2cc9a | 2016-10-30 12:47:36 -0700 | [diff] [blame] | 413 | )); |
| 414 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 415 | impl Synom for TyPtr { |
| 416 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 417 | do_parse! { |
| 418 | input, |
| 419 | star: syn!(Star) >> |
| 420 | mutability: alt!( |
| 421 | syn!(Const) => { |c| (Mutability::Immutable, Some(c)) } |
| 422 | | |
| 423 | syn!(Mut) => { |m| (Mutability::Mutable(m), None) } |
| 424 | ) >> |
| 425 | target: syn!(Ty) >> |
| 426 | (TyPtr { |
| 427 | const_token: mutability.1, |
| 428 | star_token: star, |
| 429 | ty: Box::new(MutTy { |
| 430 | ty: target, |
| 431 | mutability: mutability.0, |
| 432 | }), |
| 433 | }) |
| 434 | } |
| 435 | } |
| 436 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 437 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 438 | impl Synom for TyRptr { |
| 439 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 440 | do_parse! { |
| 441 | input, |
| 442 | amp: syn!(And) >> |
| 443 | life: option!(syn!(Lifetime)) >> |
| 444 | mutability: syn!(Mutability) >> |
| 445 | target: syn!(Ty) >> |
| 446 | (TyRptr { |
| 447 | lifetime: life, |
| 448 | ty: Box::new(MutTy { |
| 449 | ty: target, |
| 450 | mutability: mutability, |
| 451 | }), |
| 452 | and_token: amp, |
| 453 | }) |
| 454 | } |
| 455 | } |
| 456 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 457 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 458 | impl Synom for TyBareFn { |
| 459 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 460 | do_parse! { |
| 461 | input, |
| 462 | lifetimes: option!(syn!(BoundLifetimes)) >> |
| 463 | unsafety: syn!(Unsafety) >> |
| 464 | abi: option!(syn!(Abi)) >> |
| 465 | fn_: syn!(Fn_) >> |
| 466 | parens: parens!(do_parse!( |
| 467 | inputs: call!(Delimited::parse_terminated) >> |
| 468 | variadic: option!(cond_reduce!(inputs.is_empty() || inputs.trailing_delim(), |
| 469 | syn!(Dot3))) >> |
| 470 | (inputs, variadic) |
| 471 | )) >> |
| 472 | output: syn!(FunctionRetTy) >> |
| 473 | (TyBareFn { |
| 474 | ty: Box::new(BareFnTy { |
| 475 | unsafety: unsafety, |
| 476 | abi: abi, |
| 477 | lifetimes: lifetimes, |
| 478 | output: output, |
| 479 | variadic: (parens.0).1, |
| 480 | fn_token: fn_, |
| 481 | paren_token: parens.1, |
| 482 | inputs: (parens.0).0, |
| 483 | }), |
| 484 | }) |
| 485 | } |
| 486 | } |
| 487 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 488 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 489 | impl Synom for TyNever { |
| 490 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 491 | map! { |
| 492 | input, |
| 493 | syn!(Bang), |
| 494 | |b| TyNever { bang_token: b } |
| 495 | } |
| 496 | } |
| 497 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 498 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 499 | impl Synom for TyTup { |
| 500 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 501 | do_parse! { |
| 502 | input, |
| 503 | data: parens!(call!(Delimited::parse_terminated)) >> |
| 504 | (TyTup { |
| 505 | tys: data.0, |
| 506 | paren_token: data.1, |
| 507 | lone_comma: None, // TODO: does this just not parse? |
| 508 | }) |
| 509 | } |
| 510 | } |
| 511 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 512 | |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 513 | named!(ty_path -> Ty, do_parse!( |
| 514 | qpath: qpath >> |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 515 | parenthesized: cond!( |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 516 | qpath.1.segments.get(qpath.1.segments.len() - 1).item().parameters.is_empty(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 517 | option!(syn!(ParenthesizedParameterData)) |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 518 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 519 | bounds: many0!(tuple!(syn!(Add), syn!(TyParamBound))) >> |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 520 | ({ |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 521 | let (qself, mut path) = qpath; |
| 522 | if let Some(Some(parenthesized)) = parenthesized { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 523 | let parenthesized = PathParameters::Parenthesized(parenthesized); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 524 | let len = path.segments.len(); |
| 525 | path.segments.get_mut(len - 1).item_mut().parameters = parenthesized; |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 526 | } |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 527 | if bounds.is_empty() { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 528 | TyPath { qself: qself, path: path }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 529 | } else { |
David Tolnay | 02c907f | 2017-01-23 00:06:37 -0800 | [diff] [blame] | 530 | let path = TyParamBound::Trait( |
| 531 | PolyTraitRef { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 532 | bound_lifetimes: None, |
David Tolnay | 02c907f | 2017-01-23 00:06:37 -0800 | [diff] [blame] | 533 | trait_ref: path, |
| 534 | }, |
| 535 | TraitBoundModifier::None, |
| 536 | ); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 537 | let mut new_bounds = Delimited::new(); |
| 538 | new_bounds.push_first(path); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 539 | for (_tok, bound) in bounds { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 540 | new_bounds.push_default(bound); |
| 541 | } |
| 542 | TyTraitObject { bounds: new_bounds }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 543 | } |
| 544 | }) |
| 545 | )); |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 546 | |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 547 | named!(pub qpath -> (Option<QSelf>, Path), alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 548 | map!(syn!(Path), |p| (None, p)) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 549 | | |
| 550 | do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 551 | lt: syn!(Lt) >> |
| 552 | this: map!(syn!(Ty), Box::new) >> |
| 553 | path: option!(do_parse!( |
| 554 | as_: syn!(As) >> |
| 555 | path: syn!(Path) >> |
| 556 | (as_, path) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 557 | )) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 558 | gt: syn!(Gt) >> |
| 559 | colon2: syn!(Colon2) >> |
| 560 | rest: call!(Delimited::parse_separated_nonempty) >> |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 561 | ({ |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 562 | let (pos, path, as_) = match path { |
| 563 | Some((as_, mut path)) => { |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 564 | let pos = path.segments.len(); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 565 | if !path.segments.is_empty() && !path.segments.trailing_delim() { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 566 | path.segments.push_trailing(colon2); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 567 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 568 | for item in rest { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 569 | path.segments.push(item); |
| 570 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 571 | (pos, path, Some(as_)) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 572 | } |
| 573 | None => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 574 | (0, Path { |
| 575 | leading_colon: None, |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 576 | global: false, |
| 577 | segments: rest, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 578 | }, None) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 579 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 580 | }; |
| 581 | (Some(QSelf { |
| 582 | ty: this, |
| 583 | position: pos, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 584 | gt_token: gt, |
| 585 | lt_token: lt, |
| 586 | as_token: as_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 587 | }), path) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 588 | }) |
| 589 | ) |
David Tolnay | 6cd2a23 | 2016-10-24 22:41:08 -0700 | [diff] [blame] | 590 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 591 | map!(syn!(Self_), |s: Self_| (None, s.into())) |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 592 | )); |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 593 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 594 | impl Synom for ParenthesizedParameterData { |
| 595 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 596 | do_parse! { |
| 597 | input, |
| 598 | data: parens!(call!(Delimited::parse_terminated)) >> |
| 599 | output: syn!(FunctionRetTy) >> |
| 600 | (ParenthesizedParameterData { |
| 601 | paren_token: data.1, |
| 602 | inputs: data.0, |
| 603 | output: output, |
| 604 | }) |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | impl Synom for FunctionRetTy { |
| 610 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 611 | alt! { |
| 612 | input, |
| 613 | do_parse!( |
| 614 | arrow: syn!(RArrow) >> |
| 615 | ty: syn!(Ty) >> |
| 616 | (FunctionRetTy::Ty(ty, arrow)) |
| 617 | ) |
| 618 | | |
| 619 | epsilon!() => { |_| FunctionRetTy::Default } |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
David Tolnay | 4f0f251 | 2016-10-30 09:28:14 -0700 | [diff] [blame] | 624 | named!(ty_poly_trait_ref -> Ty, map!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 625 | call!(Delimited::parse_separated_nonempty), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 626 | |x| TyTraitObject { bounds: x }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 627 | )); |
| 628 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 629 | impl Synom for TyImplTrait { |
| 630 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 631 | do_parse! { |
| 632 | input, |
| 633 | impl_: syn!(Impl) >> |
| 634 | elem: call!(Delimited::parse_separated_nonempty) >> |
| 635 | (TyImplTrait { |
| 636 | impl_token: impl_, |
| 637 | bounds: elem, |
| 638 | }) |
| 639 | } |
| 640 | } |
| 641 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 642 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 643 | impl Synom for TyParen { |
| 644 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 645 | do_parse! { |
| 646 | input, |
| 647 | data: parens!(syn!(Ty)) >> |
| 648 | (TyParen { |
| 649 | paren_token: data.1, |
| 650 | ty: Box::new(data.0), |
| 651 | }) |
| 652 | } |
| 653 | } |
| 654 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 655 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 656 | impl Synom for Mutability { |
| 657 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 658 | alt! { |
| 659 | input, |
| 660 | syn!(Mut) => { Mutability::Mutable } |
| 661 | | |
| 662 | epsilon!() => { |_| Mutability::Immutable } |
| 663 | } |
| 664 | } |
| 665 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 666 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 667 | impl Synom for Path { |
| 668 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 669 | do_parse! { |
| 670 | input, |
| 671 | global: option!(syn!(Colon2)) >> |
| 672 | segments: call!(Delimited::parse_separated_nonempty) >> |
| 673 | (Path { |
| 674 | global: global.is_some(), |
| 675 | segments: segments, |
| 676 | leading_colon: global, |
| 677 | }) |
| 678 | } |
| 679 | } |
| 680 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 681 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 682 | impl Synom for PathSegment { |
| 683 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 684 | alt! { |
| 685 | input, |
| 686 | do_parse!( |
| 687 | id: option!(syn!(Ident)) >> |
| 688 | lt: syn!(Lt) >> |
| 689 | lifetimes: call!(Delimited::parse_terminated) >> |
| 690 | types: cond!( |
| 691 | lifetimes.is_empty() || lifetimes.trailing_delim(), |
| 692 | call!(Delimited::parse_terminated_with, |
| 693 | ty_no_eq_after) |
| 694 | ) >> |
| 695 | bindings: cond!( |
| 696 | match types { |
| 697 | Some(ref t) => t.is_empty() || t.trailing_delim(), |
| 698 | None => lifetimes.is_empty() || lifetimes.trailing_delim(), |
| 699 | }, |
| 700 | call!(Delimited::parse_terminated) |
| 701 | ) >> |
| 702 | gt: syn!(Gt) >> |
| 703 | (PathSegment { |
| 704 | ident: id.unwrap_or_else(|| "".into()), |
| 705 | parameters: PathParameters::AngleBracketed( |
| 706 | AngleBracketedParameterData { |
| 707 | gt_token: Some(gt), |
| 708 | lt_token: Some(lt), |
| 709 | lifetimes: lifetimes, |
| 710 | types: types.unwrap_or_default(), |
| 711 | bindings: bindings.unwrap_or_default(), |
| 712 | } |
| 713 | ), |
| 714 | }) |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 715 | ) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 716 | | |
| 717 | mod_style_path_segment |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | named!(ty_no_eq_after -> Ty, terminated!(syn!(Ty), not!(syn!(Eq)))); |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 722 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 723 | impl Path { |
| 724 | pub fn parse_mod_style(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 725 | do_parse! { |
| 726 | input, |
| 727 | global: option!(syn!(Colon2)) >> |
| 728 | segments: call!(Delimited::parse_separated_nonempty_with, |
| 729 | mod_style_path_segment) >> |
| 730 | (Path { |
| 731 | global: global.is_some(), |
| 732 | segments: segments, |
| 733 | leading_colon: global, |
| 734 | }) |
| 735 | } |
| 736 | } |
| 737 | } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 738 | |
| 739 | named!(mod_style_path_segment -> PathSegment, alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 740 | map!(syn!(Ident), Into::into) |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 741 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 742 | alt!( |
| 743 | syn!(Super) => { Into::into } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 744 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 745 | syn!(Self_) => { Into::into } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 746 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 747 | syn!(CapSelf) => { Into::into } |
| 748 | ) |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 749 | )); |
| 750 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 751 | impl Synom for TypeBinding { |
| 752 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 753 | do_parse! { |
| 754 | input, |
| 755 | id: syn!(Ident) >> |
| 756 | eq: syn!(Eq) >> |
| 757 | ty: syn!(Ty) >> |
| 758 | (TypeBinding { |
| 759 | ident: id, |
| 760 | eq_token: eq, |
| 761 | ty: ty, |
| 762 | }) |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 763 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 764 | } |
| 765 | } |
| 766 | |
| 767 | impl Synom for PolyTraitRef { |
| 768 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 769 | do_parse! { |
| 770 | input, |
| 771 | bound_lifetimes: option!(syn!(BoundLifetimes)) >> |
| 772 | trait_ref: syn!(Path) >> |
| 773 | parenthesized: option!(cond_reduce!( |
| 774 | trait_ref.segments.get(trait_ref.segments.len() - 1).item().parameters.is_empty(), |
| 775 | syn!(ParenthesizedParameterData) |
| 776 | )) >> |
| 777 | ({ |
| 778 | let mut trait_ref = trait_ref; |
| 779 | if let Some(parenthesized) = parenthesized { |
| 780 | let parenthesized = PathParameters::Parenthesized(parenthesized); |
| 781 | let len = trait_ref.segments.len(); |
| 782 | trait_ref.segments.get_mut(len - 1).item_mut().parameters = parenthesized; |
| 783 | } |
| 784 | PolyTraitRef { |
| 785 | bound_lifetimes: bound_lifetimes, |
| 786 | trait_ref: trait_ref, |
| 787 | } |
| 788 | }) |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 789 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 790 | } |
| 791 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 792 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 793 | impl Synom for BareFnArg { |
| 794 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 795 | do_parse! { |
| 796 | input, |
| 797 | name: option!(do_parse!( |
| 798 | name: syn!(Ident) >> |
| 799 | not!(syn!(Colon2)) >> |
| 800 | colon: syn!(Colon) >> |
| 801 | (name, colon) |
| 802 | )) >> |
| 803 | ty: syn!(Ty) >> |
| 804 | (BareFnArg { |
| 805 | name: name, |
| 806 | ty: ty, |
| 807 | }) |
| 808 | } |
| 809 | } |
| 810 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 811 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 812 | impl Synom for Unsafety { |
| 813 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 814 | alt! { |
| 815 | input, |
| 816 | syn!(Unsafe) => { Unsafety::Unsafe } |
| 817 | | |
| 818 | epsilon!() => { |_| Unsafety::Normal } |
| 819 | } |
| 820 | } |
| 821 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 822 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame^] | 823 | impl Synom for Abi { |
| 824 | fn parse(input: &[TokenTree]) -> IResult<&[TokenTree], Self> { |
| 825 | do_parse! { |
| 826 | input, |
| 827 | extern_: syn!(Extern) >> |
| 828 | // TODO: this parses all literals, not just strings |
| 829 | name: option!(syn!(Lit)) >> |
| 830 | (Abi { |
| 831 | extern_token: extern_, |
| 832 | kind: match name { |
| 833 | Some(name) => AbiKind::Named(name), |
| 834 | None => AbiKind::Default, |
| 835 | }, |
| 836 | }) |
| 837 | } |
| 838 | } |
| 839 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 840 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 841 | |
| 842 | #[cfg(feature = "printing")] |
| 843 | mod printing { |
| 844 | use super::*; |
| 845 | use quote::{Tokens, ToTokens}; |
| 846 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 847 | impl ToTokens for TySlice { |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 848 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 849 | self.bracket_token.surround(tokens, |tokens| { |
| 850 | self.ty.to_tokens(tokens); |
| 851 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
| 855 | impl ToTokens for TyArray { |
| 856 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 857 | self.bracket_token.surround(tokens, |tokens| { |
| 858 | self.ty.to_tokens(tokens); |
| 859 | self.semi_token.to_tokens(tokens); |
| 860 | self.amt.to_tokens(tokens); |
| 861 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
| 865 | impl ToTokens for TyPtr { |
| 866 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 867 | self.star_token.to_tokens(tokens); |
| 868 | self.const_token.to_tokens(tokens); |
| 869 | self.ty.mutability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 870 | self.ty.ty.to_tokens(tokens); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | impl ToTokens for TyRptr { |
| 875 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 876 | self.and_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 877 | self.lifetime.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 878 | self.ty.mutability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 879 | self.ty.ty.to_tokens(tokens); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | impl ToTokens for TyBareFn { |
| 884 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 885 | self.ty.to_tokens(tokens) |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | impl ToTokens for TyNever { |
| 890 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 891 | self.bang_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
| 895 | impl ToTokens for TyTup { |
| 896 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 897 | self.paren_token.surround(tokens, |tokens| { |
| 898 | self.tys.to_tokens(tokens); |
| 899 | self.lone_comma.to_tokens(tokens); |
| 900 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | impl ToTokens for TyPath { |
| 905 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 906 | PathTokens(&self.qself, &self.path).to_tokens(tokens); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | impl<'a> ToTokens for PathTokens<'a> { |
| 911 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 912 | let qself = match *self.0 { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 913 | Some(ref qself) => qself, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 914 | None => return self.1.to_tokens(tokens), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 915 | }; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 916 | qself.lt_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 917 | qself.ty.to_tokens(tokens); |
| 918 | if qself.position > 0 { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 919 | qself.as_token.to_tokens(tokens); |
| 920 | self.1.leading_colon.to_tokens(tokens); |
| 921 | for (i, segment) in self.1.segments |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 922 | .iter() |
| 923 | .take(qself.position) |
| 924 | .enumerate() { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 925 | if i == qself.position - 1 { |
| 926 | segment.item().to_tokens(tokens); |
| 927 | qself.gt_token.to_tokens(tokens); |
| 928 | segment.delimiter().to_tokens(tokens); |
| 929 | } else { |
| 930 | segment.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 931 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 932 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 933 | } else { |
| 934 | qself.gt_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 935 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 936 | for segment in self.1.segments.iter().skip(qself.position) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 937 | segment.to_tokens(tokens); |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | impl ToTokens for TyTraitObject { |
| 943 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 944 | self.bounds.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | impl ToTokens for TyImplTrait { |
| 949 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 950 | self.impl_token.to_tokens(tokens); |
| 951 | self.bounds.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
| 955 | impl ToTokens for TyParen { |
| 956 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 957 | self.paren_token.surround(tokens, |tokens| { |
| 958 | self.ty.to_tokens(tokens); |
| 959 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | |
| 963 | impl ToTokens for TyInfer { |
| 964 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 965 | self.underscore_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 969 | impl ToTokens for Mutability { |
| 970 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 971 | if let Mutability::Mutable(ref t) = *self { |
| 972 | t.to_tokens(tokens); |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 977 | impl ToTokens for Path { |
| 978 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 979 | self.leading_colon.to_tokens(tokens); |
| 980 | self.segments.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
| 984 | impl ToTokens for PathSegment { |
| 985 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 986 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 987 | self.parameters.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
| 991 | impl ToTokens for PathParameters { |
| 992 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 993 | match *self { |
| 994 | PathParameters::AngleBracketed(ref parameters) => { |
| 995 | parameters.to_tokens(tokens); |
| 996 | } |
| 997 | PathParameters::Parenthesized(ref parameters) => { |
| 998 | parameters.to_tokens(tokens); |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | impl ToTokens for AngleBracketedParameterData { |
| 1005 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1006 | self.lt_token.to_tokens(tokens); |
| 1007 | self.lifetimes.to_tokens(tokens); |
| 1008 | self.types.to_tokens(tokens); |
| 1009 | self.bindings.to_tokens(tokens); |
| 1010 | self.gt_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | impl ToTokens for TypeBinding { |
| 1015 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1016 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1017 | self.eq_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1018 | self.ty.to_tokens(tokens); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | impl ToTokens for ParenthesizedParameterData { |
| 1023 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1024 | self.paren_token.surround(tokens, |tokens| { |
| 1025 | self.inputs.to_tokens(tokens); |
| 1026 | }); |
| 1027 | self.output.to_tokens(tokens); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | impl ToTokens for FunctionRetTy { |
| 1032 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1033 | match *self { |
| 1034 | FunctionRetTy::Default => {} |
| 1035 | FunctionRetTy::Ty(ref ty, ref arrow) => { |
| 1036 | arrow.to_tokens(tokens); |
| 1037 | ty.to_tokens(tokens); |
| 1038 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | impl ToTokens for PolyTraitRef { |
| 1044 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1045 | self.bound_lifetimes.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1046 | self.trait_ref.to_tokens(tokens); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | impl ToTokens for BareFnTy { |
| 1051 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1052 | self.lifetimes.to_tokens(tokens); |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1053 | self.unsafety.to_tokens(tokens); |
| 1054 | self.abi.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1055 | self.fn_token.to_tokens(tokens); |
| 1056 | self.paren_token.surround(tokens, |tokens| { |
| 1057 | self.inputs.to_tokens(tokens); |
| 1058 | self.variadic.to_tokens(tokens); |
| 1059 | }); |
| 1060 | self.output.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1064 | impl ToTokens for BareFnArg { |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1065 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1066 | if let Some((ref name, ref colon)) = self.name { |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 1067 | name.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1068 | colon.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1069 | } |
| 1070 | self.ty.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1073 | |
| 1074 | impl ToTokens for Unsafety { |
| 1075 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1076 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1077 | Unsafety::Unsafe(ref t) => t.to_tokens(tokens), |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1078 | Unsafety::Normal => { |
| 1079 | // nothing |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | impl ToTokens for Abi { |
| 1086 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1087 | self.extern_token.to_tokens(tokens); |
| 1088 | match self.kind { |
| 1089 | AbiKind::Named(ref named) => named.to_tokens(tokens), |
| 1090 | AbiKind::Default => {} |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1094 | } |