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::*; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 317 | use synom::Synom; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 318 | use synom::tokens::*; |
David Tolnay | da4049b | 2016-09-04 10:59:23 -0700 | [diff] [blame] | 319 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 320 | impl Synom for Ty { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 321 | named!(parse -> Self, alt!( |
| 322 | // must be before mac |
| 323 | syn!(TyParen) => { Ty::Paren } |
| 324 | | |
| 325 | // must be before path |
| 326 | syn!(Mac) => { Ty::Mac } |
| 327 | | |
| 328 | // must be before ty_poly_trait_ref |
| 329 | ty_path |
| 330 | | |
| 331 | syn!(TySlice) => { Ty::Slice } |
| 332 | | |
| 333 | syn!(TyArray) => { Ty::Array } |
| 334 | | |
| 335 | syn!(TyPtr) => { Ty::Ptr } |
| 336 | | |
| 337 | syn!(TyRptr) => { Ty::Rptr } |
| 338 | | |
| 339 | syn!(TyBareFn) => { Ty::BareFn } |
| 340 | | |
| 341 | syn!(TyNever) => { Ty::Never } |
| 342 | | |
| 343 | syn!(TyTup) => { Ty::Tup } |
| 344 | | |
| 345 | ty_poly_trait_ref |
| 346 | | |
| 347 | syn!(TyImplTrait) => { Ty::ImplTrait } |
| 348 | )); |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 349 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 350 | fn description() -> Option<&'static str> { |
| 351 | Some("type") |
| 352 | } |
| 353 | } |
David Tolnay | 0047c71 | 2016-12-21 21:59:25 -0500 | [diff] [blame] | 354 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 355 | impl Synom for TySlice { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 356 | named!(parse -> Self, map!( |
| 357 | brackets!(syn!(Ty)), |
| 358 | |(ty, b)| TySlice { |
| 359 | ty: Box::new(ty), |
| 360 | bracket_token: b, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 361 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 362 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 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 | impl Synom for TyArray { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 366 | named!(parse -> Self, map!( |
| 367 | brackets!(do_parse!( |
| 368 | elem: syn!(Ty) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 369 | semi: syn!(Semi) >> |
| 370 | len: array_len >> |
| 371 | (elem, semi, len) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 372 | )), |
| 373 | |((elem, semi, len), brackets)| { |
| 374 | TyArray { |
| 375 | ty: Box::new(elem), |
| 376 | amt: len, |
| 377 | bracket_token: brackets, |
| 378 | semi_token: semi, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 381 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 382 | } |
David Tolnay | fa94b6f | 2016-10-05 23:26:11 -0700 | [diff] [blame] | 383 | |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 384 | #[cfg(not(feature = "full"))] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 385 | named!(array_len -> ConstExpr, syn!(ConstExpr)); |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 386 | |
David Tolnay | fe2cc9a | 2016-10-30 12:47:36 -0700 | [diff] [blame] | 387 | #[cfg(feature = "full")] |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 388 | named!(array_len -> ConstExpr, alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 389 | terminated!(syn!(ConstExpr), input_end!()) |
David Tolnay | 514f129 | 2017-02-27 12:30:57 -0800 | [diff] [blame] | 390 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 391 | terminated!(syn!(Expr), input_end!()) => { ConstExpr::Other } |
David Tolnay | fe2cc9a | 2016-10-30 12:47:36 -0700 | [diff] [blame] | 392 | )); |
| 393 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 394 | impl Synom for TyPtr { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 395 | named!(parse -> Self, do_parse!( |
| 396 | star: syn!(Star) >> |
| 397 | mutability: alt!( |
| 398 | syn!(Const) => { |c| (Mutability::Immutable, Some(c)) } |
| 399 | | |
| 400 | syn!(Mut) => { |m| (Mutability::Mutable(m), None) } |
| 401 | ) >> |
| 402 | target: syn!(Ty) >> |
| 403 | (TyPtr { |
| 404 | const_token: mutability.1, |
| 405 | star_token: star, |
| 406 | ty: Box::new(MutTy { |
| 407 | ty: target, |
| 408 | mutability: mutability.0, |
| 409 | }), |
| 410 | }) |
| 411 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 412 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 413 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 414 | impl Synom for TyRptr { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 415 | named!(parse -> Self, do_parse!( |
| 416 | amp: syn!(And) >> |
| 417 | life: option!(syn!(Lifetime)) >> |
| 418 | mutability: syn!(Mutability) >> |
| 419 | target: syn!(Ty) >> |
| 420 | (TyRptr { |
| 421 | lifetime: life, |
| 422 | ty: Box::new(MutTy { |
| 423 | ty: target, |
| 424 | mutability: mutability, |
| 425 | }), |
| 426 | and_token: amp, |
| 427 | }) |
| 428 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 429 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 430 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 431 | impl Synom for TyBareFn { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 432 | named!(parse -> Self, do_parse!( |
| 433 | lifetimes: option!(syn!(BoundLifetimes)) >> |
| 434 | unsafety: syn!(Unsafety) >> |
| 435 | abi: option!(syn!(Abi)) >> |
| 436 | fn_: syn!(Fn_) >> |
| 437 | parens: parens!(do_parse!( |
| 438 | inputs: call!(Delimited::parse_terminated) >> |
| 439 | variadic: option!(cond_reduce!(inputs.is_empty() || inputs.trailing_delim(), |
| 440 | syn!(Dot3))) >> |
| 441 | (inputs, variadic) |
| 442 | )) >> |
| 443 | output: syn!(FunctionRetTy) >> |
| 444 | (TyBareFn { |
| 445 | ty: Box::new(BareFnTy { |
| 446 | unsafety: unsafety, |
| 447 | abi: abi, |
| 448 | lifetimes: lifetimes, |
| 449 | output: output, |
| 450 | variadic: (parens.0).1, |
| 451 | fn_token: fn_, |
| 452 | paren_token: parens.1, |
| 453 | inputs: (parens.0).0, |
| 454 | }), |
| 455 | }) |
| 456 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 457 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 458 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 459 | impl Synom for TyNever { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 460 | named!(parse -> Self, map!( |
| 461 | syn!(Bang), |
| 462 | |b| TyNever { bang_token: b } |
| 463 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 464 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 465 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 466 | impl Synom for TyTup { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 467 | named!(parse -> Self, do_parse!( |
| 468 | data: parens!(call!(Delimited::parse_terminated)) >> |
| 469 | (TyTup { |
| 470 | tys: data.0, |
| 471 | paren_token: data.1, |
| 472 | lone_comma: None, // TODO: does this just not parse? |
| 473 | }) |
| 474 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 475 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 476 | |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 477 | named!(ty_path -> Ty, do_parse!( |
| 478 | qpath: qpath >> |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 479 | parenthesized: cond!( |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 480 | 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] | 481 | option!(syn!(ParenthesizedParameterData)) |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 482 | ) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 483 | bounds: many0!(tuple!(syn!(Add), syn!(TyParamBound))) >> |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 484 | ({ |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 485 | let (qself, mut path) = qpath; |
| 486 | if let Some(Some(parenthesized)) = parenthesized { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 487 | let parenthesized = PathParameters::Parenthesized(parenthesized); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 488 | let len = path.segments.len(); |
| 489 | path.segments.get_mut(len - 1).item_mut().parameters = parenthesized; |
David Tolnay | f6c7440 | 2016-10-08 02:31:26 -0700 | [diff] [blame] | 490 | } |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 491 | if bounds.is_empty() { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 492 | TyPath { qself: qself, path: path }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 493 | } else { |
David Tolnay | 02c907f | 2017-01-23 00:06:37 -0800 | [diff] [blame] | 494 | let path = TyParamBound::Trait( |
| 495 | PolyTraitRef { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 496 | bound_lifetimes: None, |
David Tolnay | 02c907f | 2017-01-23 00:06:37 -0800 | [diff] [blame] | 497 | trait_ref: path, |
| 498 | }, |
| 499 | TraitBoundModifier::None, |
| 500 | ); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 501 | let mut new_bounds = Delimited::new(); |
| 502 | new_bounds.push_first(path); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 503 | for (_tok, bound) in bounds { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 504 | new_bounds.push_default(bound); |
| 505 | } |
| 506 | TyTraitObject { bounds: new_bounds }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 507 | } |
| 508 | }) |
| 509 | )); |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 510 | |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 511 | named!(pub qpath -> (Option<QSelf>, Path), alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 512 | map!(syn!(Path), |p| (None, p)) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 513 | | |
| 514 | do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 515 | lt: syn!(Lt) >> |
| 516 | this: map!(syn!(Ty), Box::new) >> |
| 517 | path: option!(do_parse!( |
| 518 | as_: syn!(As) >> |
| 519 | path: syn!(Path) >> |
| 520 | (as_, path) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 521 | )) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 522 | gt: syn!(Gt) >> |
| 523 | colon2: syn!(Colon2) >> |
| 524 | rest: call!(Delimited::parse_separated_nonempty) >> |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 525 | ({ |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 526 | let (pos, path, as_) = match path { |
| 527 | Some((as_, mut path)) => { |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 528 | let pos = path.segments.len(); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 529 | if !path.segments.is_empty() && !path.segments.trailing_delim() { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 530 | path.segments.push_trailing(colon2); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 531 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 532 | for item in rest { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 533 | path.segments.push(item); |
| 534 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 535 | (pos, path, Some(as_)) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 536 | } |
| 537 | None => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 538 | (0, Path { |
| 539 | leading_colon: None, |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 540 | global: false, |
| 541 | segments: rest, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 542 | }, None) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 543 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 544 | }; |
| 545 | (Some(QSelf { |
| 546 | ty: this, |
| 547 | position: pos, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 548 | gt_token: gt, |
| 549 | lt_token: lt, |
| 550 | as_token: as_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 551 | }), path) |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 552 | }) |
| 553 | ) |
David Tolnay | 6cd2a23 | 2016-10-24 22:41:08 -0700 | [diff] [blame] | 554 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 555 | map!(syn!(Self_), |s: Self_| (None, s.into())) |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 556 | )); |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 557 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 558 | impl Synom for ParenthesizedParameterData { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 559 | named!(parse -> Self, do_parse!( |
| 560 | data: parens!(call!(Delimited::parse_terminated)) >> |
| 561 | output: syn!(FunctionRetTy) >> |
| 562 | (ParenthesizedParameterData { |
| 563 | paren_token: data.1, |
| 564 | inputs: data.0, |
| 565 | output: output, |
| 566 | }) |
| 567 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | impl Synom for FunctionRetTy { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 571 | named!(parse -> Self, alt!( |
| 572 | do_parse!( |
| 573 | arrow: syn!(RArrow) >> |
| 574 | ty: syn!(Ty) >> |
| 575 | (FunctionRetTy::Ty(ty, arrow)) |
| 576 | ) |
| 577 | | |
| 578 | epsilon!() => { |_| FunctionRetTy::Default } |
| 579 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 580 | } |
| 581 | |
David Tolnay | 4f0f251 | 2016-10-30 09:28:14 -0700 | [diff] [blame] | 582 | named!(ty_poly_trait_ref -> Ty, map!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 583 | call!(Delimited::parse_separated_nonempty), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 584 | |x| TyTraitObject { bounds: x }.into() |
David Tolnay | 6414da7 | 2016-10-08 00:55:17 -0700 | [diff] [blame] | 585 | )); |
| 586 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 587 | impl Synom for TyImplTrait { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 588 | named!(parse -> Self, do_parse!( |
| 589 | impl_: syn!(Impl) >> |
| 590 | elem: call!(Delimited::parse_separated_nonempty) >> |
| 591 | (TyImplTrait { |
| 592 | impl_token: impl_, |
| 593 | bounds: elem, |
| 594 | }) |
| 595 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 596 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 597 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 598 | impl Synom for TyParen { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 599 | named!(parse -> Self, do_parse!( |
| 600 | data: parens!(syn!(Ty)) >> |
| 601 | (TyParen { |
| 602 | paren_token: data.1, |
| 603 | ty: Box::new(data.0), |
| 604 | }) |
| 605 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 606 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 607 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 608 | impl Synom for Mutability { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 609 | named!(parse -> Self, alt!( |
| 610 | syn!(Mut) => { Mutability::Mutable } |
| 611 | | |
| 612 | epsilon!() => { |_| Mutability::Immutable } |
| 613 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 614 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 615 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 616 | impl Synom for Path { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 617 | named!(parse -> Self, do_parse!( |
| 618 | global: option!(syn!(Colon2)) >> |
| 619 | segments: call!(Delimited::parse_separated_nonempty) >> |
| 620 | (Path { |
| 621 | global: global.is_some(), |
| 622 | segments: segments, |
| 623 | leading_colon: global, |
| 624 | }) |
| 625 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 626 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 627 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 628 | impl Synom for PathSegment { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 629 | named!(parse -> Self, alt!( |
| 630 | do_parse!( |
| 631 | id: option!(syn!(Ident)) >> |
| 632 | lt: syn!(Lt) >> |
| 633 | lifetimes: call!(Delimited::parse_terminated) >> |
| 634 | types: cond!( |
| 635 | lifetimes.is_empty() || lifetimes.trailing_delim(), |
| 636 | call!(Delimited::parse_terminated_with, |
| 637 | ty_no_eq_after) |
| 638 | ) >> |
| 639 | bindings: cond!( |
| 640 | match types { |
| 641 | Some(ref t) => t.is_empty() || t.trailing_delim(), |
| 642 | None => lifetimes.is_empty() || lifetimes.trailing_delim(), |
| 643 | }, |
| 644 | call!(Delimited::parse_terminated) |
| 645 | ) >> |
| 646 | gt: syn!(Gt) >> |
| 647 | (PathSegment { |
| 648 | ident: id.unwrap_or_else(|| "".into()), |
| 649 | parameters: PathParameters::AngleBracketed( |
| 650 | AngleBracketedParameterData { |
| 651 | gt_token: Some(gt), |
| 652 | lt_token: Some(lt), |
| 653 | lifetimes: lifetimes, |
| 654 | types: types.unwrap_or_default(), |
| 655 | bindings: bindings.unwrap_or_default(), |
| 656 | } |
| 657 | ), |
| 658 | }) |
| 659 | ) |
| 660 | | |
| 661 | mod_style_path_segment |
| 662 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 663 | } |
| 664 | named!(ty_no_eq_after -> Ty, terminated!(syn!(Ty), not!(syn!(Eq)))); |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 665 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 666 | impl Path { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 667 | named!(pub parse_mod_style -> Self, do_parse!( |
| 668 | global: option!(syn!(Colon2)) >> |
| 669 | segments: call!(Delimited::parse_separated_nonempty_with, |
| 670 | mod_style_path_segment) >> |
| 671 | (Path { |
| 672 | global: global.is_some(), |
| 673 | segments: segments, |
| 674 | leading_colon: global, |
| 675 | }) |
| 676 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 677 | } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 678 | |
| 679 | named!(mod_style_path_segment -> PathSegment, alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 680 | map!(syn!(Ident), Into::into) |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 681 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 682 | alt!( |
| 683 | syn!(Super) => { Into::into } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 684 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 685 | syn!(Self_) => { Into::into } |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 686 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 687 | syn!(CapSelf) => { Into::into } |
| 688 | ) |
Arnavion | f2dada1 | 2017-04-20 23:55:20 -0700 | [diff] [blame] | 689 | )); |
| 690 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 691 | impl Synom for TypeBinding { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 692 | named!(parse -> Self, do_parse!( |
| 693 | id: syn!(Ident) >> |
| 694 | eq: syn!(Eq) >> |
| 695 | ty: syn!(Ty) >> |
| 696 | (TypeBinding { |
| 697 | ident: id, |
| 698 | eq_token: eq, |
| 699 | ty: ty, |
| 700 | }) |
| 701 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | impl Synom for PolyTraitRef { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 705 | named!(parse -> Self, do_parse!( |
| 706 | bound_lifetimes: option!(syn!(BoundLifetimes)) >> |
| 707 | trait_ref: syn!(Path) >> |
| 708 | parenthesized: option!(cond_reduce!( |
| 709 | trait_ref.segments.get(trait_ref.segments.len() - 1).item().parameters.is_empty(), |
| 710 | syn!(ParenthesizedParameterData) |
| 711 | )) >> |
| 712 | ({ |
| 713 | let mut trait_ref = trait_ref; |
| 714 | if let Some(parenthesized) = parenthesized { |
| 715 | let parenthesized = PathParameters::Parenthesized(parenthesized); |
| 716 | let len = trait_ref.segments.len(); |
| 717 | trait_ref.segments.get_mut(len - 1).item_mut().parameters = parenthesized; |
| 718 | } |
| 719 | PolyTraitRef { |
| 720 | bound_lifetimes: bound_lifetimes, |
| 721 | trait_ref: trait_ref, |
| 722 | } |
| 723 | }) |
| 724 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 725 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 726 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 727 | impl Synom for BareFnArg { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 728 | named!(parse -> Self, do_parse!( |
| 729 | name: option!(do_parse!( |
| 730 | name: syn!(Ident) >> |
| 731 | not!(syn!(Colon2)) >> |
| 732 | colon: syn!(Colon) >> |
| 733 | (name, colon) |
| 734 | )) >> |
| 735 | ty: syn!(Ty) >> |
| 736 | (BareFnArg { |
| 737 | name: name, |
| 738 | ty: ty, |
| 739 | }) |
| 740 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 741 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 742 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 743 | impl Synom for Unsafety { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 744 | named!(parse -> Self, alt!( |
| 745 | syn!(Unsafe) => { Unsafety::Unsafe } |
| 746 | | |
| 747 | epsilon!() => { |_| Unsafety::Normal } |
| 748 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 749 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 750 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 751 | impl Synom for Abi { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 752 | named!(parse -> Self, do_parse!( |
| 753 | extern_: syn!(Extern) >> |
| 754 | // TODO: this parses all literals, not just strings |
| 755 | name: option!(syn!(Lit)) >> |
| 756 | (Abi { |
| 757 | extern_token: extern_, |
| 758 | kind: match name { |
| 759 | Some(name) => AbiKind::Named(name), |
| 760 | None => AbiKind::Default, |
| 761 | }, |
| 762 | }) |
| 763 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 764 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 765 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 766 | |
| 767 | #[cfg(feature = "printing")] |
| 768 | mod printing { |
| 769 | use super::*; |
| 770 | use quote::{Tokens, ToTokens}; |
| 771 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 772 | impl ToTokens for TySlice { |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 773 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 774 | self.bracket_token.surround(tokens, |tokens| { |
| 775 | self.ty.to_tokens(tokens); |
| 776 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
| 780 | impl ToTokens for TyArray { |
| 781 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 782 | self.bracket_token.surround(tokens, |tokens| { |
| 783 | self.ty.to_tokens(tokens); |
| 784 | self.semi_token.to_tokens(tokens); |
| 785 | self.amt.to_tokens(tokens); |
| 786 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
| 790 | impl ToTokens for TyPtr { |
| 791 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 792 | self.star_token.to_tokens(tokens); |
| 793 | self.const_token.to_tokens(tokens); |
| 794 | self.ty.mutability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 795 | self.ty.ty.to_tokens(tokens); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | impl ToTokens for TyRptr { |
| 800 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 801 | self.and_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 802 | self.lifetime.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 803 | self.ty.mutability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 804 | self.ty.ty.to_tokens(tokens); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | impl ToTokens for TyBareFn { |
| 809 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 810 | self.ty.to_tokens(tokens) |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | impl ToTokens for TyNever { |
| 815 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 816 | self.bang_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
| 820 | impl ToTokens for TyTup { |
| 821 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 822 | self.paren_token.surround(tokens, |tokens| { |
| 823 | self.tys.to_tokens(tokens); |
| 824 | self.lone_comma.to_tokens(tokens); |
| 825 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | impl ToTokens for TyPath { |
| 830 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 831 | PathTokens(&self.qself, &self.path).to_tokens(tokens); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | impl<'a> ToTokens for PathTokens<'a> { |
| 836 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 837 | let qself = match *self.0 { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 838 | Some(ref qself) => qself, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 839 | None => return self.1.to_tokens(tokens), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 840 | }; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 841 | qself.lt_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 842 | qself.ty.to_tokens(tokens); |
| 843 | if qself.position > 0 { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 844 | qself.as_token.to_tokens(tokens); |
| 845 | self.1.leading_colon.to_tokens(tokens); |
| 846 | for (i, segment) in self.1.segments |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 847 | .iter() |
| 848 | .take(qself.position) |
| 849 | .enumerate() { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 850 | if i == qself.position - 1 { |
| 851 | segment.item().to_tokens(tokens); |
| 852 | qself.gt_token.to_tokens(tokens); |
| 853 | segment.delimiter().to_tokens(tokens); |
| 854 | } else { |
| 855 | segment.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 856 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 857 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 858 | } else { |
| 859 | qself.gt_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 860 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 861 | for segment in self.1.segments.iter().skip(qself.position) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 862 | segment.to_tokens(tokens); |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | impl ToTokens for TyTraitObject { |
| 868 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 869 | self.bounds.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| 873 | impl ToTokens for TyImplTrait { |
| 874 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 875 | self.impl_token.to_tokens(tokens); |
| 876 | self.bounds.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | impl ToTokens for TyParen { |
| 881 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 882 | self.paren_token.surround(tokens, |tokens| { |
| 883 | self.ty.to_tokens(tokens); |
| 884 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | impl ToTokens for TyInfer { |
| 889 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 890 | self.underscore_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 894 | impl ToTokens for Mutability { |
| 895 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 896 | if let Mutability::Mutable(ref t) = *self { |
| 897 | t.to_tokens(tokens); |
David Tolnay | 47a877c | 2016-10-01 16:50:55 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 902 | impl ToTokens for Path { |
| 903 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 904 | self.leading_colon.to_tokens(tokens); |
| 905 | self.segments.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
| 909 | impl ToTokens for PathSegment { |
| 910 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 911 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 912 | self.parameters.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
| 916 | impl ToTokens for PathParameters { |
| 917 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 918 | match *self { |
| 919 | PathParameters::AngleBracketed(ref parameters) => { |
| 920 | parameters.to_tokens(tokens); |
| 921 | } |
| 922 | PathParameters::Parenthesized(ref parameters) => { |
| 923 | parameters.to_tokens(tokens); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | impl ToTokens for AngleBracketedParameterData { |
| 930 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 931 | self.lt_token.to_tokens(tokens); |
| 932 | self.lifetimes.to_tokens(tokens); |
| 933 | self.types.to_tokens(tokens); |
| 934 | self.bindings.to_tokens(tokens); |
| 935 | self.gt_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
| 939 | impl ToTokens for TypeBinding { |
| 940 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 941 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 942 | self.eq_token.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 943 | self.ty.to_tokens(tokens); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | impl ToTokens for ParenthesizedParameterData { |
| 948 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 949 | self.paren_token.surround(tokens, |tokens| { |
| 950 | self.inputs.to_tokens(tokens); |
| 951 | }); |
| 952 | self.output.to_tokens(tokens); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | impl ToTokens for FunctionRetTy { |
| 957 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 958 | match *self { |
| 959 | FunctionRetTy::Default => {} |
| 960 | FunctionRetTy::Ty(ref ty, ref arrow) => { |
| 961 | arrow.to_tokens(tokens); |
| 962 | ty.to_tokens(tokens); |
| 963 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | impl ToTokens for PolyTraitRef { |
| 969 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 970 | self.bound_lifetimes.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 971 | self.trait_ref.to_tokens(tokens); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | impl ToTokens for BareFnTy { |
| 976 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 977 | self.lifetimes.to_tokens(tokens); |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 978 | self.unsafety.to_tokens(tokens); |
| 979 | self.abi.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 980 | self.fn_token.to_tokens(tokens); |
| 981 | self.paren_token.surround(tokens, |tokens| { |
| 982 | self.inputs.to_tokens(tokens); |
| 983 | self.variadic.to_tokens(tokens); |
| 984 | }); |
| 985 | self.output.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 989 | impl ToTokens for BareFnArg { |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 990 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 991 | if let Some((ref name, ref colon)) = self.name { |
David Tolnay | 62f374c | 2016-10-02 13:37:00 -0700 | [diff] [blame] | 992 | name.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 993 | colon.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 994 | } |
| 995 | self.ty.to_tokens(tokens); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 998 | |
| 999 | impl ToTokens for Unsafety { |
| 1000 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 1001 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1002 | Unsafety::Unsafe(ref t) => t.to_tokens(tokens), |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1003 | Unsafety::Normal => { |
| 1004 | // nothing |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | impl ToTokens for Abi { |
| 1011 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1012 | self.extern_token.to_tokens(tokens); |
| 1013 | match self.kind { |
| 1014 | AbiKind::Named(ref named) => named.to_tokens(tokens), |
| 1015 | AbiKind::Default => {} |
David Tolnay | b8d8ef5 | 2016-10-29 14:30:08 -0700 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 1019 | } |