blob: ed18f259e1425a4b1b23e14b0403c7414a65514c [file] [log] [blame]
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001use delimited::Delimited;
David Tolnayb79ee962016-09-04 09:39:20 -07002use super::*;
3
Alex Crichton62a0a592017-05-22 13:58:53 -07004ast_enum_of_structs! {
5 /// The different kinds of types recognized by the compiler
David Tolnayfd6bf5c2017-11-12 09:41:14 -08006 pub enum Type {
Alex Crichton62a0a592017-05-22 13:58:53 -07007 /// A variable-length array (`[T]`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -08008 pub Slice(TypeSlice {
David Tolnay32954ef2017-12-26 22:43:16 -05009 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050010 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070011 }),
12 /// A fixed length array (`[T; n]`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080013 pub Array(TypeArray {
David Tolnay32954ef2017-12-26 22:43:16 -050014 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050015 pub elem: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080016 pub semi_token: Token![;],
David Tolnayeadbda32017-12-29 02:33:47 -050017 pub len: Expr,
Alex Crichton62a0a592017-05-22 13:58:53 -070018 }),
19 /// A raw pointer (`*const T` or `*mut T`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080020 pub Ptr(TypePtr {
David Tolnayf8db7ba2017-11-11 22:52:16 -080021 pub star_token: Token![*],
22 pub const_token: Option<Token![const]>,
David Tolnayeadbda32017-12-29 02:33:47 -050023 pub elem: Box<MutType>,
Alex Crichton62a0a592017-05-22 13:58:53 -070024 }),
25 /// A reference (`&'a T` or `&'a mut T`)
David Tolnay0a89b4d2017-11-13 00:55:45 -080026 pub Reference(TypeReference {
David Tolnayf8db7ba2017-11-11 22:52:16 -080027 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -070028 pub lifetime: Option<Lifetime>,
David Tolnayeadbda32017-12-29 02:33:47 -050029 pub elem: Box<MutType>,
Alex Crichton62a0a592017-05-22 13:58:53 -070030 }),
31 /// A bare function (e.g. `fn(usize) -> bool`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080032 pub BareFn(TypeBareFn {
33 pub ty: Box<BareFnType>,
Alex Crichton62a0a592017-05-22 13:58:53 -070034 }),
35 /// The never type (`!`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080036 pub Never(TypeNever {
David Tolnayf8db7ba2017-11-11 22:52:16 -080037 pub bang_token: Token![!],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070038 }),
Alex Crichton62a0a592017-05-22 13:58:53 -070039 /// A tuple (`(A, B, C, D, ...)`)
David Tolnay05362582017-12-26 01:33:57 -050040 pub Tuple(TypeTuple {
David Tolnay32954ef2017-12-26 22:43:16 -050041 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050042 pub elems: Delimited<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070043 }),
44 /// A path (`module::module::...::Type`), optionally
45 /// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
46 ///
Nika Layzellc08227a2017-12-04 16:30:17 -050047 /// Type arguments are stored in the Path itself
David Tolnayfd6bf5c2017-11-12 09:41:14 -080048 pub Path(TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -070049 pub qself: Option<QSelf>,
50 pub path: Path,
51 }),
52 /// A trait object type `Bound1 + Bound2 + Bound3`
53 /// where `Bound` is a trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080054 pub TraitObject(TypeTraitObject {
David Tolnaye45b59f2017-12-25 18:44:49 -050055 pub dyn_token: Option<Token![dyn]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -080056 pub bounds: Delimited<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070057 }),
58 /// An `impl Bound1 + Bound2 + Bound3` type
59 /// where `Bound` is a trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080060 pub ImplTrait(TypeImplTrait {
David Tolnayf8db7ba2017-11-11 22:52:16 -080061 pub impl_token: Token![impl],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080062 pub bounds: Delimited<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070063 }),
64 /// No-op; kept solely so that we can pretty-print faithfully
David Tolnayfd6bf5c2017-11-12 09:41:14 -080065 pub Paren(TypeParen {
David Tolnay32954ef2017-12-26 22:43:16 -050066 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050067 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070068 }),
Michael Layzell93c36282017-06-04 20:43:14 -040069 /// No-op: kept solely so that we can pretty-print faithfully
David Tolnayfd6bf5c2017-11-12 09:41:14 -080070 pub Group(TypeGroup {
David Tolnay32954ef2017-12-26 22:43:16 -050071 pub group_token: token::Group,
David Tolnayeadbda32017-12-29 02:33:47 -050072 pub elem: Box<Type>,
Michael Layzell93c36282017-06-04 20:43:14 -040073 }),
David Tolnayfd6bf5c2017-11-12 09:41:14 -080074 /// TypeKind::Infer means the type should be inferred instead of it having been
Alex Crichton62a0a592017-05-22 13:58:53 -070075 /// specified. This can appear anywhere in a type.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080076 pub Infer(TypeInfer {
David Tolnayf8db7ba2017-11-11 22:52:16 -080077 pub underscore_token: Token![_],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070078 }),
Alex Crichton62a0a592017-05-22 13:58:53 -070079 /// A macro in the type position.
David Tolnaydecf28d2017-11-11 11:56:45 -080080 pub Macro(Macro),
Alex Crichton62a0a592017-05-22 13:58:53 -070081 }
82}
83
84ast_struct! {
David Tolnayfd6bf5c2017-11-12 09:41:14 -080085 pub struct MutType {
David Tolnay24237fb2017-12-29 02:15:26 -050086 pub mutability: Option<Token![mut]>,
David Tolnay4a3f59a2017-12-28 21:21:12 -050087 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -070088 }
89}
90
Alex Crichton62a0a592017-05-22 13:58:53 -070091ast_struct! {
92 /// A "Path" is essentially Rust's notion of a name.
David Tolnayb79ee962016-09-04 09:39:20 -070093 ///
Alex Crichton62a0a592017-05-22 13:58:53 -070094 /// It's represented as a sequence of identifiers,
95 /// along with a bunch of supporting information.
96 ///
97 /// E.g. `std::cmp::PartialEq`
98 pub struct Path {
99 /// A `::foo` path, is relative to the crate root rather than current
100 /// module (like paths in an import).
David Tolnayf8db7ba2017-11-11 22:52:16 -0800101 pub leading_colon: Option<Token![::]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700102 /// The segments in the path: the things separated by `::`.
David Tolnayf8db7ba2017-11-11 22:52:16 -0800103 pub segments: Delimited<PathSegment, Token![::]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700104 }
David Tolnayb79ee962016-09-04 09:39:20 -0700105}
106
David Tolnay570695e2017-06-03 16:15:13 -0700107impl Path {
108 pub fn global(&self) -> bool {
109 self.leading_colon.is_some()
110 }
111}
112
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700113#[cfg(feature = "printing")]
Nika Layzell6b38b132017-10-24 23:09:39 -0400114#[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
115#[cfg_attr(feature = "clone-impls", derive(Clone))]
116pub struct PathTokens<'a>(pub &'a Option<QSelf>, pub &'a Path);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700117
David Tolnaydaaf7742016-10-03 11:11:43 -0700118impl<T> From<T> for Path
David Tolnay51382052017-12-27 13:46:21 -0500119where
120 T: Into<PathSegment>,
David Tolnaydaaf7742016-10-03 11:11:43 -0700121{
David Tolnay84aa0752016-10-02 23:01:13 -0700122 fn from(segment: T) -> Self {
123 Path {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700124 leading_colon: None,
125 segments: vec![(segment.into(), None)].into(),
David Tolnay84aa0752016-10-02 23:01:13 -0700126 }
127 }
128}
129
Alex Crichton62a0a592017-05-22 13:58:53 -0700130ast_struct! {
131 /// A segment of a path: an identifier, an optional lifetime, and a set of types.
132 ///
133 /// E.g. `std`, `String` or `Box<T>`
134 pub struct PathSegment {
135 /// The identifier portion of this path segment.
136 pub ident: Ident,
Nika Layzellc08227a2017-12-04 16:30:17 -0500137 /// Type/lifetime arguments attached to this path. They come in
Alex Crichton62a0a592017-05-22 13:58:53 -0700138 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
139 /// this is more than just simple syntactic sugar; the use of
140 /// parens affects the region binding rules, so we preserve the
141 /// distinction.
Nika Layzellc08227a2017-12-04 16:30:17 -0500142 pub arguments: PathArguments,
Alex Crichton62a0a592017-05-22 13:58:53 -0700143 }
David Tolnayb79ee962016-09-04 09:39:20 -0700144}
145
David Tolnaydaaf7742016-10-03 11:11:43 -0700146impl<T> From<T> for PathSegment
David Tolnay51382052017-12-27 13:46:21 -0500147where
148 T: Into<Ident>,
David Tolnaydaaf7742016-10-03 11:11:43 -0700149{
David Tolnay84aa0752016-10-02 23:01:13 -0700150 fn from(ident: T) -> Self {
David Tolnayb79ee962016-09-04 09:39:20 -0700151 PathSegment {
David Tolnay84aa0752016-10-02 23:01:13 -0700152 ident: ident.into(),
Nika Layzellc08227a2017-12-04 16:30:17 -0500153 arguments: PathArguments::None,
David Tolnayb79ee962016-09-04 09:39:20 -0700154 }
155 }
156}
157
Alex Crichton62a0a592017-05-22 13:58:53 -0700158ast_enum! {
Nika Layzellc08227a2017-12-04 16:30:17 -0500159 /// Arguments of a path segment.
Alex Crichton62a0a592017-05-22 13:58:53 -0700160 ///
161 /// E.g. `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`
Nika Layzellc08227a2017-12-04 16:30:17 -0500162 pub enum PathArguments {
David Tolnay570695e2017-06-03 16:15:13 -0700163 None,
Alex Crichton62a0a592017-05-22 13:58:53 -0700164 /// The `<'a, A, B, C>` in `foo::bar::baz::<'a, A, B, C>`
Nika Layzellc08227a2017-12-04 16:30:17 -0500165 AngleBracketed(AngleBracketedGenericArguments),
Alex Crichton62a0a592017-05-22 13:58:53 -0700166 /// The `(A, B)` and `C` in `Foo(A, B) -> C`
Nika Layzellc08227a2017-12-04 16:30:17 -0500167 Parenthesized(ParenthesizedGenericArguments),
Alex Crichton62a0a592017-05-22 13:58:53 -0700168 }
David Tolnayb79ee962016-09-04 09:39:20 -0700169}
170
Nika Layzellc08227a2017-12-04 16:30:17 -0500171impl Default for PathArguments {
David Tolnay570695e2017-06-03 16:15:13 -0700172 fn default() -> Self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500173 PathArguments::None
David Tolnayb79ee962016-09-04 09:39:20 -0700174 }
David Tolnay570695e2017-06-03 16:15:13 -0700175}
David Tolnay5332d4b2016-10-30 14:25:22 -0700176
Nika Layzellc08227a2017-12-04 16:30:17 -0500177impl PathArguments {
David Tolnay5332d4b2016-10-30 14:25:22 -0700178 pub fn is_empty(&self) -> bool {
179 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500180 PathArguments::None => true,
181 PathArguments::AngleBracketed(ref bracketed) => bracketed.args.is_empty(),
182 PathArguments::Parenthesized(_) => false,
David Tolnay5332d4b2016-10-30 14:25:22 -0700183 }
184 }
David Tolnayb79ee962016-09-04 09:39:20 -0700185}
186
Nika Layzell357885a2017-12-04 15:47:07 -0500187ast_enum! {
188 /// A individual generic argument, like `'a`, `T`, or `Item=T`.
Nika Layzellc08227a2017-12-04 16:30:17 -0500189 pub enum GenericArgument {
Nika Layzell357885a2017-12-04 15:47:07 -0500190 /// The lifetime parameters for this path segment.
191 Lifetime(Lifetime),
192 /// The type parameters for this path segment, if present.
193 Type(Type),
194 /// Bindings (equality constraints) on associated types, if present.
195 ///
196 /// E.g., `Foo<A=Bar>`.
197 TypeBinding(TypeBinding),
Nika Layzellc680e612017-12-04 19:07:20 -0500198 /// Const expression. Must be inside of a block.
199 ///
200 /// NOTE: Identity expressions are represented as Type arguments, as
201 /// they are indistinguishable syntactically.
Nika Layzellce37f332017-12-05 12:01:22 -0500202 Const(Expr),
Nika Layzell357885a2017-12-04 15:47:07 -0500203 }
204}
205
Alex Crichton62a0a592017-05-22 13:58:53 -0700206ast_struct! {
207 /// A path like `Foo<'a, T>`
Nika Layzellc08227a2017-12-04 16:30:17 -0500208 pub struct AngleBracketedGenericArguments {
David Tolnay2d4e08a2017-12-28 23:54:07 -0500209 pub colon2_token: Option<Token![::]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800210 pub lt_token: Token![<],
Nika Layzellc08227a2017-12-04 16:30:17 -0500211 pub args: Delimited<GenericArgument, Token![,]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800212 pub gt_token: Token![>],
Alex Crichton62a0a592017-05-22 13:58:53 -0700213 }
214}
215
216ast_struct! {
217 /// Bind a type to an associated type: `A=Foo`.
218 pub struct TypeBinding {
219 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800220 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800221 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700222 }
223}
224
Alex Crichton62a0a592017-05-22 13:58:53 -0700225ast_struct! {
226 /// A path like `Foo(A,B) -> C`
Nika Layzellc08227a2017-12-04 16:30:17 -0500227 pub struct ParenthesizedGenericArguments {
David Tolnay32954ef2017-12-26 22:43:16 -0500228 pub paren_token: token::Paren,
Alex Crichton62a0a592017-05-22 13:58:53 -0700229 /// `(A, B)`
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800230 pub inputs: Delimited<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700231 /// `C`
David Tolnayf93b90d2017-11-11 19:21:26 -0800232 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700233 }
234}
235
236ast_struct! {
237 pub struct PolyTraitRef {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700238 /// The `for<'a>` in `for<'a> Foo<&'a T>`
239 pub bound_lifetimes: Option<BoundLifetimes>,
David Tolnay7d38c7e2017-12-25 22:31:50 -0500240 /// The `Foo<&'a T>` in `for<'a> Foo<&'a T>`
Alex Crichton62a0a592017-05-22 13:58:53 -0700241 pub trait_ref: Path,
242 }
243}
244
245ast_struct! {
246 /// The explicit Self type in a "qualified path". The actual
247 /// path, including the trait and the associated item, is stored
248 /// separately. `position` represents the index of the associated
249 /// item qualified with this Self type.
David Tolnayb79ee962016-09-04 09:39:20 -0700250 ///
David Tolnaybcf26022017-12-25 22:10:52 -0500251 /// ```text
Alex Crichton62a0a592017-05-22 13:58:53 -0700252 /// <Vec<T> as a::b::Trait>::AssociatedItem
David Tolnaybcf26022017-12-25 22:10:52 -0500253 /// ^~~~~~ ~~~~~~~~~~~~~~^
Alex Crichton62a0a592017-05-22 13:58:53 -0700254 /// ty position = 3
David Tolnayb79ee962016-09-04 09:39:20 -0700255 ///
Alex Crichton62a0a592017-05-22 13:58:53 -0700256 /// <Vec<T>>::AssociatedItem
David Tolnaybcf26022017-12-25 22:10:52 -0500257 /// ^~~~~~ ^
Alex Crichton62a0a592017-05-22 13:58:53 -0700258 /// ty position = 0
259 /// ```
260 pub struct QSelf {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800261 pub lt_token: Token![<],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800262 pub ty: Box<Type>,
Michael Layzell3936ceb2017-07-08 00:28:36 -0400263 pub position: usize,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800264 pub as_token: Option<Token![as]>,
265 pub gt_token: Token![>],
Alex Crichton62a0a592017-05-22 13:58:53 -0700266 }
267}
268
269ast_struct! {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800270 pub struct BareFnType {
David Tolnay9b258702017-12-29 02:24:41 -0500271 pub unsafety: Option<Token![unsafe]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700272 pub abi: Option<Abi>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800273 pub fn_token: Token![fn],
David Tolnay4a3f59a2017-12-28 21:21:12 -0500274 pub lifetimes: Option<BoundLifetimes>,
David Tolnay32954ef2017-12-26 22:43:16 -0500275 pub paren_token: token::Paren,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800276 pub inputs: Delimited<BareFnArg, Token![,]>,
277 pub variadic: Option<Token![...]>,
David Tolnayf93b90d2017-11-11 19:21:26 -0800278 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700279 }
280}
281
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700282ast_struct! {
283 pub struct Abi {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800284 pub extern_token: Token![extern],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700285 pub kind: AbiKind,
286 }
287}
288
Alex Crichton62a0a592017-05-22 13:58:53 -0700289ast_enum! {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700290 pub enum AbiKind {
291 Named(Lit),
292 Default,
Alex Crichton62a0a592017-05-22 13:58:53 -0700293 }
294}
295
296ast_struct! {
297 /// An argument in a function type.
298 ///
299 /// E.g. `bar: usize` as in `fn foo(bar: usize)`
300 pub struct BareFnArg {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800301 pub name: Option<(BareFnArgName, Token![:])>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800302 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700303 }
304}
305
Alex Crichton23a15f62017-08-28 12:34:23 -0700306ast_enum! {
307 /// Names of arguments in the `BareFnArg` structure
308 pub enum BareFnArgName {
309 /// Argument with the provided name
310 Named(Ident),
311 /// Argument matched with `_`
David Tolnayf8db7ba2017-11-11 22:52:16 -0800312 Wild(Token![_]),
Alex Crichton23a15f62017-08-28 12:34:23 -0700313 }
314}
Alex Crichton62a0a592017-05-22 13:58:53 -0700315
316ast_enum! {
David Tolnayf93b90d2017-11-11 19:21:26 -0800317 pub enum ReturnType {
Alex Crichton62a0a592017-05-22 13:58:53 -0700318 /// Return type is not specified.
319 ///
320 /// Functions default to `()` and
321 /// closures default to inference. Span points to where return
322 /// type would be inserted.
323 Default,
324 /// Everything else
David Tolnay4a3f59a2017-12-28 21:21:12 -0500325 Type(Token![->], Box<Type>),
Alex Crichton62a0a592017-05-22 13:58:53 -0700326 }
David Tolnayb79ee962016-09-04 09:39:20 -0700327}
328
David Tolnay86eca752016-09-04 11:26:41 -0700329#[cfg(feature = "parsing")]
David Tolnay9d8f1972016-09-04 11:58:48 -0700330pub mod parsing {
331 use super::*;
Michael Layzell92639a52017-06-01 00:07:44 -0400332 use synom::Synom;
David Tolnayda4049b2016-09-04 10:59:23 -0700333
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800334 impl Synom for Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400335 named!(parse -> Self, call!(ambig_ty, true));
David Tolnayb79ee962016-09-04 09:39:20 -0700336
Alex Crichton954046c2017-05-30 21:49:42 -0700337 fn description() -> Option<&'static str> {
338 Some("type")
339 }
340 }
David Tolnay0047c712016-12-21 21:59:25 -0500341
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800342 impl Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400343 /// In some positions, types may not contain the `+` character, to
344 /// disambiguate them. For example in the expression `1 as T`, T may not
345 /// contain a `+` character.
346 ///
347 /// This parser does not allow a `+`, while the default parser does.
Michael Layzell6a5a1642017-06-04 19:35:15 -0400348 named!(pub without_plus -> Self, call!(ambig_ty, false));
Michael Layzell9bf2b002017-06-04 18:49:53 -0400349 }
350
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800351 named!(ambig_ty(allow_plus: bool) -> Type, alt!(
352 syn!(TypeGroup) => { Type::Group }
Michael Layzell93c36282017-06-04 20:43:14 -0400353 |
David Tolnay05362582017-12-26 01:33:57 -0500354 // must be before TypeTuple
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800355 syn!(TypeParen) => { Type::Paren }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400356 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500357 // must be before TypePath
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800358 syn!(Macro) => { Type::Macro }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400359 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500360 // must be before TypeTraitObject
361 call!(TypePath::parse, allow_plus) => { Type::Path }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400362 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800363 syn!(TypeSlice) => { Type::Slice }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400364 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800365 syn!(TypeArray) => { Type::Array }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400366 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800367 syn!(TypePtr) => { Type::Ptr }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400368 |
David Tolnay0a89b4d2017-11-13 00:55:45 -0800369 syn!(TypeReference) => { Type::Reference }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400370 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800371 syn!(TypeBareFn) => { Type::BareFn }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400372 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800373 syn!(TypeNever) => { Type::Never }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400374 |
David Tolnay05362582017-12-26 01:33:57 -0500375 syn!(TypeTuple) => { Type::Tuple }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400376 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500377 // Don't try parsing more than one trait bound if we aren't allowing it
378 call!(TypeTraitObject::parse, allow_plus) => { Type::TraitObject }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400379 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800380 syn!(TypeImplTrait) => { Type::ImplTrait }
Alex Crichton23a15f62017-08-28 12:34:23 -0700381 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800382 syn!(TypeInfer) => { Type::Infer }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400383 ));
384
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800385 impl Synom for TypeSlice {
Michael Layzell92639a52017-06-01 00:07:44 -0400386 named!(parse -> Self, map!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800387 brackets!(syn!(Type)),
388 |(ty, b)| TypeSlice {
David Tolnayeadbda32017-12-29 02:33:47 -0500389 elem: Box::new(ty),
Michael Layzell92639a52017-06-01 00:07:44 -0400390 bracket_token: b,
Alex Crichton954046c2017-05-30 21:49:42 -0700391 }
Michael Layzell92639a52017-06-01 00:07:44 -0400392 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700393 }
David Tolnayb79ee962016-09-04 09:39:20 -0700394
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800395 impl Synom for TypeArray {
Michael Layzell92639a52017-06-01 00:07:44 -0400396 named!(parse -> Self, map!(
397 brackets!(do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800398 elem: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800399 semi: punct!(;) >>
Michael Layzelld7ee9102017-06-07 10:02:19 -0400400 len: syn!(Expr) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700401 (elem, semi, len)
Michael Layzell92639a52017-06-01 00:07:44 -0400402 )),
403 |((elem, semi, len), brackets)| {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800404 TypeArray {
David Tolnayeadbda32017-12-29 02:33:47 -0500405 elem: Box::new(elem),
406 len: len,
Michael Layzell92639a52017-06-01 00:07:44 -0400407 bracket_token: brackets,
408 semi_token: semi,
Alex Crichton954046c2017-05-30 21:49:42 -0700409 }
410 }
Michael Layzell92639a52017-06-01 00:07:44 -0400411 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700412 }
David Tolnayfa94b6f2016-10-05 23:26:11 -0700413
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800414 impl Synom for TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400415 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800416 star: punct!(*) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400417 mutability: alt!(
David Tolnay24237fb2017-12-29 02:15:26 -0500418 keyword!(const) => { |c| (None, Some(c)) }
Michael Layzell92639a52017-06-01 00:07:44 -0400419 |
David Tolnay24237fb2017-12-29 02:15:26 -0500420 keyword!(mut) => { |m| (Some(m), None) }
Michael Layzell92639a52017-06-01 00:07:44 -0400421 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800422 target: call!(Type::without_plus) >>
423 (TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400424 const_token: mutability.1,
425 star_token: star,
David Tolnayeadbda32017-12-29 02:33:47 -0500426 elem: Box::new(MutType {
Michael Layzell92639a52017-06-01 00:07:44 -0400427 ty: target,
428 mutability: mutability.0,
429 }),
430 })
431 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700432 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700433
David Tolnay0a89b4d2017-11-13 00:55:45 -0800434 impl Synom for TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400435 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800436 amp: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400437 life: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500438 mutability: option!(keyword!(mut)) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400439 // & binds tighter than +, so we don't allow + here.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800440 target: call!(Type::without_plus) >>
David Tolnay0a89b4d2017-11-13 00:55:45 -0800441 (TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400442 lifetime: life,
David Tolnayeadbda32017-12-29 02:33:47 -0500443 elem: Box::new(MutType {
Michael Layzell92639a52017-06-01 00:07:44 -0400444 ty: target,
445 mutability: mutability,
446 }),
447 and_token: amp,
448 })
449 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700450 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700451
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800452 impl Synom for TypeBareFn {
Michael Layzell92639a52017-06-01 00:07:44 -0400453 named!(parse -> Self, do_parse!(
454 lifetimes: option!(syn!(BoundLifetimes)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500455 unsafety: option!(keyword!(unsafe)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400456 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800457 fn_: keyword!(fn) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400458 parens: parens!(do_parse!(
459 inputs: call!(Delimited::parse_terminated) >>
460 variadic: option!(cond_reduce!(inputs.is_empty() || inputs.trailing_delim(),
David Tolnayf8db7ba2017-11-11 22:52:16 -0800461 punct!(...))) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400462 (inputs, variadic)
463 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800464 output: syn!(ReturnType) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800465 (TypeBareFn {
466 ty: Box::new(BareFnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400467 unsafety: unsafety,
468 abi: abi,
469 lifetimes: lifetimes,
470 output: output,
471 variadic: (parens.0).1,
472 fn_token: fn_,
473 paren_token: parens.1,
474 inputs: (parens.0).0,
475 }),
476 })
477 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700478 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700479
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800480 impl Synom for TypeNever {
Michael Layzell92639a52017-06-01 00:07:44 -0400481 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800482 punct!(!),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800483 |b| TypeNever { bang_token: b }
Michael Layzell92639a52017-06-01 00:07:44 -0400484 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700485 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700486
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800487 impl Synom for TypeInfer {
Alex Crichton23a15f62017-08-28 12:34:23 -0700488 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800489 punct!(_),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800490 |u| TypeInfer { underscore_token: u }
Alex Crichton23a15f62017-08-28 12:34:23 -0700491 ));
492 }
493
David Tolnay05362582017-12-26 01:33:57 -0500494 impl Synom for TypeTuple {
Michael Layzell92639a52017-06-01 00:07:44 -0400495 named!(parse -> Self, do_parse!(
496 data: parens!(call!(Delimited::parse_terminated)) >>
David Tolnay05362582017-12-26 01:33:57 -0500497 (TypeTuple {
David Tolnayeadbda32017-12-29 02:33:47 -0500498 elems: data.0,
Michael Layzell92639a52017-06-01 00:07:44 -0400499 paren_token: data.1,
Michael Layzell92639a52017-06-01 00:07:44 -0400500 })
501 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700502 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700503
David Tolnay7d38c7e2017-12-25 22:31:50 -0500504 impl TypePath {
505 named!(parse(allow_plus: bool) -> Self, do_parse!(
506 qpath: qpath >>
507 parenthesized: cond!(
508 qpath.1.segments.last().unwrap().item().arguments.is_empty(),
509 option!(syn!(ParenthesizedGenericArguments))
510 ) >>
511 cond!(allow_plus, not!(peek!(punct!(+)))) >>
512 ({
513 let (qself, mut path) = qpath;
514 if let Some(Some(parenthesized)) = parenthesized {
515 let parenthesized = PathArguments::Parenthesized(parenthesized);
516 path.segments.last_mut().unwrap().item_mut().arguments = parenthesized;
517 }
518 TypePath { qself: qself, path: path }
519 })
520 ));
521 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700522
David Tolnay9636c052016-10-02 17:11:17 -0700523 named!(pub qpath -> (Option<QSelf>, Path), alt!(
Alex Crichton954046c2017-05-30 21:49:42 -0700524 map!(syn!(Path), |p| (None, p))
David Tolnay9636c052016-10-02 17:11:17 -0700525 |
526 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800527 lt: punct!(<) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800528 this: syn!(Type) >>
David Tolnay7d38c7e2017-12-25 22:31:50 -0500529 path: option!(tuple!(keyword!(as), syn!(Path))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800530 gt: punct!(>) >>
531 colon2: punct!(::) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700532 rest: call!(Delimited::parse_separated_nonempty) >>
David Tolnay9636c052016-10-02 17:11:17 -0700533 ({
Michael Layzell3936ceb2017-07-08 00:28:36 -0400534 let (pos, as_, path) = match path {
Alex Crichton954046c2017-05-30 21:49:42 -0700535 Some((as_, mut path)) => {
David Tolnay9636c052016-10-02 17:11:17 -0700536 let pos = path.segments.len();
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700537 if !path.segments.is_empty() && !path.segments.trailing_delim() {
Alex Crichton954046c2017-05-30 21:49:42 -0700538 path.segments.push_trailing(colon2);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700539 }
Alex Crichton954046c2017-05-30 21:49:42 -0700540 for item in rest {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700541 path.segments.push(item);
542 }
Michael Layzell3936ceb2017-07-08 00:28:36 -0400543 (pos, Some(as_), path)
David Tolnay9636c052016-10-02 17:11:17 -0700544 }
545 None => {
Michael Layzell3936ceb2017-07-08 00:28:36 -0400546 (0, None, Path {
David Tolnay570695e2017-06-03 16:15:13 -0700547 leading_colon: Some(colon2),
David Tolnay9636c052016-10-02 17:11:17 -0700548 segments: rest,
David Tolnay570695e2017-06-03 16:15:13 -0700549 })
David Tolnay9636c052016-10-02 17:11:17 -0700550 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700551 };
552 (Some(QSelf {
David Tolnay570695e2017-06-03 16:15:13 -0700553 lt_token: lt,
554 ty: Box::new(this),
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700555 position: pos,
Michael Layzell3936ceb2017-07-08 00:28:36 -0400556 as_token: as_,
Alex Crichton954046c2017-05-30 21:49:42 -0700557 gt_token: gt,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700558 }), path)
David Tolnay9636c052016-10-02 17:11:17 -0700559 })
560 )
David Tolnay6cd2a232016-10-24 22:41:08 -0700561 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800562 map!(keyword!(self), |s| (None, s.into()))
David Tolnay9d8f1972016-09-04 11:58:48 -0700563 ));
David Tolnayb79ee962016-09-04 09:39:20 -0700564
Nika Layzellc08227a2017-12-04 16:30:17 -0500565 impl Synom for ParenthesizedGenericArguments {
Michael Layzell92639a52017-06-01 00:07:44 -0400566 named!(parse -> Self, do_parse!(
567 data: parens!(call!(Delimited::parse_terminated)) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800568 output: syn!(ReturnType) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500569 (ParenthesizedGenericArguments {
Michael Layzell92639a52017-06-01 00:07:44 -0400570 paren_token: data.1,
571 inputs: data.0,
572 output: output,
573 })
574 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700575 }
576
David Tolnayf93b90d2017-11-11 19:21:26 -0800577 impl Synom for ReturnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400578 named!(parse -> Self, alt!(
579 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800580 arrow: punct!(->) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800581 ty: syn!(Type) >>
David Tolnay4a3f59a2017-12-28 21:21:12 -0500582 (ReturnType::Type(arrow, Box::new(ty)))
Michael Layzell92639a52017-06-01 00:07:44 -0400583 )
584 |
David Tolnayf93b90d2017-11-11 19:21:26 -0800585 epsilon!() => { |_| ReturnType::Default }
Michael Layzell92639a52017-06-01 00:07:44 -0400586 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700587 }
588
David Tolnay7d38c7e2017-12-25 22:31:50 -0500589 impl TypeTraitObject {
590 // Only allow multiple trait references if allow_plus is true.
591 named!(parse(allow_plus: bool) -> Self, do_parse!(
592 dyn_token: option!(keyword!(dyn)) >>
593 bounds: alt!(
594 cond_reduce!(allow_plus, call!(Delimited::parse_terminated_nonempty))
595 |
596 syn!(TypeParamBound) => { |x| vec![x].into() }
597 ) >>
598 (TypeTraitObject {
599 dyn_token: dyn_token,
600 bounds: bounds,
601 })
602 ));
603 }
David Tolnay6414da72016-10-08 00:55:17 -0700604
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800605 impl Synom for TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400606 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800607 impl_: keyword!(impl) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400608 // NOTE: rust-lang/rust#34511 includes discussion about whether or
609 // not + should be allowed in ImplTrait directly without ().
Nika Layzellb49a9e52017-12-05 13:31:52 -0500610 elem: call!(Delimited::parse_terminated_nonempty) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800611 (TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400612 impl_token: impl_,
613 bounds: elem,
614 })
615 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700616 }
David Tolnayb79ee962016-09-04 09:39:20 -0700617
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800618 impl Synom for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400619 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800620 data: grouped!(syn!(Type)) >>
621 (TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400622 group_token: data.1,
David Tolnayeadbda32017-12-29 02:33:47 -0500623 elem: Box::new(data.0),
Michael Layzell93c36282017-06-04 20:43:14 -0400624 })
625 ));
626 }
627
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800628 impl Synom for TypeParen {
Michael Layzell92639a52017-06-01 00:07:44 -0400629 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800630 data: parens!(syn!(Type)) >>
631 (TypeParen {
Michael Layzell92639a52017-06-01 00:07:44 -0400632 paren_token: data.1,
David Tolnayeadbda32017-12-29 02:33:47 -0500633 elem: Box::new(data.0),
Michael Layzell92639a52017-06-01 00:07:44 -0400634 })
635 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700636 }
David Tolnayb79ee962016-09-04 09:39:20 -0700637
Alex Crichton954046c2017-05-30 21:49:42 -0700638 impl Synom for Path {
Michael Layzell92639a52017-06-01 00:07:44 -0400639 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800640 colon: option!(punct!(::)) >>
David Tolnaye45b59f2017-12-25 18:44:49 -0500641 segments: call!(Delimited::<PathSegment, Token![::]>::parse_separated_nonempty) >>
642 cond_reduce!(segments.first().map_or(true, |seg| seg.item().ident != "dyn"), epsilon!()) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400643 (Path {
David Tolnay570695e2017-06-03 16:15:13 -0700644 leading_colon: colon,
Michael Layzell92639a52017-06-01 00:07:44 -0400645 segments: segments,
Michael Layzell92639a52017-06-01 00:07:44 -0400646 })
647 ));
Alex Crichton36e91bf2017-07-06 14:59:56 -0700648
649 fn description() -> Option<&'static str> {
650 Some("path")
651 }
Alex Crichton954046c2017-05-30 21:49:42 -0700652 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700653
Nika Layzellc680e612017-12-04 19:07:20 -0500654 #[cfg(not(feature = "full"))]
Nika Layzellc08227a2017-12-04 16:30:17 -0500655 impl Synom for GenericArgument {
Nika Layzell357885a2017-12-04 15:47:07 -0500656 named!(parse -> Self, alt!(
Nika Layzellc08227a2017-12-04 16:30:17 -0500657 call!(ty_no_eq_after) => { GenericArgument::Type }
Nika Layzell357885a2017-12-04 15:47:07 -0500658 |
Nika Layzellc08227a2017-12-04 16:30:17 -0500659 syn!(Lifetime) => { GenericArgument::Lifetime }
Nika Layzell357885a2017-12-04 15:47:07 -0500660 |
Nika Layzellc08227a2017-12-04 16:30:17 -0500661 syn!(TypeBinding) => { GenericArgument::TypeBinding }
Nika Layzell357885a2017-12-04 15:47:07 -0500662 ));
663 }
664
Nika Layzellc680e612017-12-04 19:07:20 -0500665 #[cfg(feature = "full")]
666 impl Synom for GenericArgument {
667 named!(parse -> Self, alt!(
668 call!(ty_no_eq_after) => { GenericArgument::Type }
669 |
670 syn!(Lifetime) => { GenericArgument::Lifetime }
671 |
672 syn!(TypeBinding) => { GenericArgument::TypeBinding }
673 |
David Tolnay8c91b882017-12-28 23:04:32 -0500674 syn!(ExprLit) => { |l| GenericArgument::Const(Expr::Lit(l).into()) }
Nika Layzellce37f332017-12-05 12:01:22 -0500675 |
David Tolnay8c91b882017-12-28 23:04:32 -0500676 syn!(ExprBlock) => { |b| GenericArgument::Const(Expr::Block(b).into()) }
Nika Layzellc680e612017-12-04 19:07:20 -0500677 ));
678 }
679
Nika Layzellc08227a2017-12-04 16:30:17 -0500680 impl Synom for AngleBracketedGenericArguments {
Nika Layzell357885a2017-12-04 15:47:07 -0500681 named!(parse -> Self, do_parse!(
David Tolnay2d4e08a2017-12-28 23:54:07 -0500682 colon2: option!(punct!(::)) >>
Nika Layzell357885a2017-12-04 15:47:07 -0500683 lt: punct!(<) >>
684 args: call!(Delimited::parse_terminated) >>
685 gt: punct!(>) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500686 (AngleBracketedGenericArguments {
David Tolnay2d4e08a2017-12-28 23:54:07 -0500687 colon2_token: colon2,
Nika Layzell357885a2017-12-04 15:47:07 -0500688 lt_token: lt,
689 args: args,
690 gt_token: gt,
691 })
692 ));
693 }
694
Alex Crichton954046c2017-05-30 21:49:42 -0700695 impl Synom for PathSegment {
Michael Layzell92639a52017-06-01 00:07:44 -0400696 named!(parse -> Self, alt!(
697 do_parse!(
David Tolnay570695e2017-06-03 16:15:13 -0700698 ident: syn!(Ident) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500699 arguments: syn!(AngleBracketedGenericArguments) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400700 (PathSegment {
David Tolnay570695e2017-06-03 16:15:13 -0700701 ident: ident,
Nika Layzellc08227a2017-12-04 16:30:17 -0500702 arguments: PathArguments::AngleBracketed(arguments),
Michael Layzell92639a52017-06-01 00:07:44 -0400703 })
704 )
705 |
706 mod_style_path_segment
707 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700708 }
David Tolnay570695e2017-06-03 16:15:13 -0700709
David Tolnayd60cfec2017-12-29 00:21:38 -0500710 named!(pub ty_no_eq_after -> Type, terminated!(syn!(Type), not!(punct!(=))));
David Tolnay9d8f1972016-09-04 11:58:48 -0700711
Alex Crichton954046c2017-05-30 21:49:42 -0700712 impl Path {
Michael Layzell92639a52017-06-01 00:07:44 -0400713 named!(pub parse_mod_style -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800714 colon: option!(punct!(::)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400715 segments: call!(Delimited::parse_separated_nonempty_with,
716 mod_style_path_segment) >>
717 (Path {
David Tolnay570695e2017-06-03 16:15:13 -0700718 leading_colon: colon,
Michael Layzell92639a52017-06-01 00:07:44 -0400719 segments: segments,
Michael Layzell92639a52017-06-01 00:07:44 -0400720 })
721 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700722 }
Arnavionf2dada12017-04-20 23:55:20 -0700723
724 named!(mod_style_path_segment -> PathSegment, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500725 syn!(Ident) => { Into::into }
Arnavionf2dada12017-04-20 23:55:20 -0700726 |
David Tolnay5f332a92017-12-26 00:42:45 -0500727 keyword!(super) => { Into::into }
728 |
729 keyword!(self) => { Into::into }
730 |
731 keyword!(Self) => { Into::into }
732 |
733 keyword!(crate) => { Into::into }
Arnavionf2dada12017-04-20 23:55:20 -0700734 ));
735
Alex Crichton954046c2017-05-30 21:49:42 -0700736 impl Synom for TypeBinding {
Michael Layzell92639a52017-06-01 00:07:44 -0400737 named!(parse -> Self, do_parse!(
738 id: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800739 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800740 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400741 (TypeBinding {
742 ident: id,
743 eq_token: eq,
744 ty: ty,
745 })
746 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700747 }
748
749 impl Synom for PolyTraitRef {
Michael Layzell92639a52017-06-01 00:07:44 -0400750 named!(parse -> Self, do_parse!(
751 bound_lifetimes: option!(syn!(BoundLifetimes)) >>
752 trait_ref: syn!(Path) >>
753 parenthesized: option!(cond_reduce!(
Nika Layzellc08227a2017-12-04 16:30:17 -0500754 trait_ref.segments.get(trait_ref.segments.len() - 1).item().arguments.is_empty(),
755 syn!(ParenthesizedGenericArguments)
Michael Layzell92639a52017-06-01 00:07:44 -0400756 )) >>
757 ({
758 let mut trait_ref = trait_ref;
759 if let Some(parenthesized) = parenthesized {
Nika Layzellc08227a2017-12-04 16:30:17 -0500760 let parenthesized = PathArguments::Parenthesized(parenthesized);
Michael Layzell92639a52017-06-01 00:07:44 -0400761 let len = trait_ref.segments.len();
Nika Layzellc08227a2017-12-04 16:30:17 -0500762 trait_ref.segments.get_mut(len - 1).item_mut().arguments = parenthesized;
Michael Layzell92639a52017-06-01 00:07:44 -0400763 }
764 PolyTraitRef {
765 bound_lifetimes: bound_lifetimes,
766 trait_ref: trait_ref,
767 }
768 })
769 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700770 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700771
Alex Crichton954046c2017-05-30 21:49:42 -0700772 impl Synom for BareFnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400773 named!(parse -> Self, do_parse!(
774 name: option!(do_parse!(
Alex Crichton23a15f62017-08-28 12:34:23 -0700775 name: syn!(BareFnArgName) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800776 not!(punct!(::)) >>
777 colon: punct!(:) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400778 (name, colon)
779 )) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800780 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400781 (BareFnArg {
782 name: name,
783 ty: ty,
784 })
785 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700786 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700787
Alex Crichton23a15f62017-08-28 12:34:23 -0700788 impl Synom for BareFnArgName {
789 named!(parse -> Self, alt!(
790 map!(syn!(Ident), BareFnArgName::Named)
791 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800792 map!(punct!(_), BareFnArgName::Wild)
Alex Crichton23a15f62017-08-28 12:34:23 -0700793 ));
794 }
795
Alex Crichton954046c2017-05-30 21:49:42 -0700796 impl Synom for Abi {
Michael Layzell92639a52017-06-01 00:07:44 -0400797 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800798 extern_: keyword!(extern) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400799 // TODO: this parses all literals, not just strings
800 name: option!(syn!(Lit)) >>
801 (Abi {
802 extern_token: extern_,
803 kind: match name {
804 Some(name) => AbiKind::Named(name),
805 None => AbiKind::Default,
806 },
807 })
808 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700809 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700810}
David Tolnay87d0b442016-09-04 11:52:12 -0700811
812#[cfg(feature = "printing")]
813mod printing {
814 use super::*;
David Tolnay51382052017-12-27 13:46:21 -0500815 use quote::{ToTokens, Tokens};
David Tolnay87d0b442016-09-04 11:52:12 -0700816
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800817 impl ToTokens for TypeSlice {
David Tolnay87d0b442016-09-04 11:52:12 -0700818 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700819 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500820 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700821 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700822 }
823 }
824
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800825 impl ToTokens for TypeArray {
Alex Crichton62a0a592017-05-22 13:58:53 -0700826 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700827 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500828 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700829 self.semi_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500830 self.len.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700831 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700832 }
833 }
834
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800835 impl ToTokens for TypePtr {
Alex Crichton62a0a592017-05-22 13:58:53 -0700836 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700837 self.star_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500838 match self.elem.mutability {
David Tolnay24237fb2017-12-29 02:15:26 -0500839 Some(ref tok) => tok.to_tokens(tokens),
840 None => {
Alex Crichton259ee532017-07-14 06:51:02 -0700841 TokensOrDefault(&self.const_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400842 }
843 }
David Tolnayeadbda32017-12-29 02:33:47 -0500844 self.elem.ty.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700845 }
846 }
847
David Tolnay0a89b4d2017-11-13 00:55:45 -0800848 impl ToTokens for TypeReference {
Alex Crichton62a0a592017-05-22 13:58:53 -0700849 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700850 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700851 self.lifetime.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500852 self.elem.mutability.to_tokens(tokens);
853 self.elem.ty.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700854 }
855 }
856
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800857 impl ToTokens for TypeBareFn {
Alex Crichton62a0a592017-05-22 13:58:53 -0700858 fn to_tokens(&self, tokens: &mut Tokens) {
859 self.ty.to_tokens(tokens)
860 }
861 }
862
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800863 impl ToTokens for TypeNever {
Alex Crichton62a0a592017-05-22 13:58:53 -0700864 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700865 self.bang_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700866 }
867 }
868
David Tolnay05362582017-12-26 01:33:57 -0500869 impl ToTokens for TypeTuple {
Alex Crichton62a0a592017-05-22 13:58:53 -0700870 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700871 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500872 self.elems.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700873 })
Alex Crichton62a0a592017-05-22 13:58:53 -0700874 }
875 }
876
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800877 impl ToTokens for TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -0700878 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700879 PathTokens(&self.qself, &self.path).to_tokens(tokens);
880 }
881 }
882
883 impl<'a> ToTokens for PathTokens<'a> {
884 fn to_tokens(&self, tokens: &mut Tokens) {
885 let qself = match *self.0 {
Alex Crichton62a0a592017-05-22 13:58:53 -0700886 Some(ref qself) => qself,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700887 None => return self.1.to_tokens(tokens),
Alex Crichton62a0a592017-05-22 13:58:53 -0700888 };
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700889 qself.lt_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700890 qself.ty.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400891
892 // XXX: Gross.
893 let pos = if qself.position > 0 && qself.position >= self.1.segments.len() {
894 self.1.segments.len() - 1
895 } else {
896 qself.position
897 };
David Tolnay570695e2017-06-03 16:15:13 -0700898 let mut segments = self.1.segments.iter();
Michael Layzell3936ceb2017-07-08 00:28:36 -0400899 if pos > 0 {
Alex Crichton259ee532017-07-14 06:51:02 -0700900 TokensOrDefault(&qself.as_token).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700901 self.1.leading_colon.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700902 for (i, segment) in (&mut segments).take(pos).enumerate() {
903 if i + 1 == pos {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700904 segment.item().to_tokens(tokens);
905 qself.gt_token.to_tokens(tokens);
906 segment.delimiter().to_tokens(tokens);
907 } else {
908 segment.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700909 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700910 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700911 } else {
912 qself.gt_token.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700913 self.1.leading_colon.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700914 }
David Tolnay570695e2017-06-03 16:15:13 -0700915 for segment in segments {
Alex Crichton62a0a592017-05-22 13:58:53 -0700916 segment.to_tokens(tokens);
917 }
918 }
919 }
920
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800921 impl ToTokens for TypeTraitObject {
Alex Crichton62a0a592017-05-22 13:58:53 -0700922 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaye45b59f2017-12-25 18:44:49 -0500923 self.dyn_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700924 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700925 }
926 }
927
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800928 impl ToTokens for TypeImplTrait {
Alex Crichton62a0a592017-05-22 13:58:53 -0700929 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700930 self.impl_token.to_tokens(tokens);
931 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700932 }
933 }
934
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800935 impl ToTokens for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400936 fn to_tokens(&self, tokens: &mut Tokens) {
937 self.group_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500938 self.elem.to_tokens(tokens);
Michael Layzell93c36282017-06-04 20:43:14 -0400939 });
940 }
941 }
942
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800943 impl ToTokens for TypeParen {
Alex Crichton62a0a592017-05-22 13:58:53 -0700944 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700945 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500946 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700947 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700948 }
949 }
950
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800951 impl ToTokens for TypeInfer {
Alex Crichton62a0a592017-05-22 13:58:53 -0700952 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700953 self.underscore_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700954 }
955 }
956
957 impl ToTokens for Path {
958 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700959 self.leading_colon.to_tokens(tokens);
960 self.segments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700961 }
962 }
963
964 impl ToTokens for PathSegment {
965 fn to_tokens(&self, tokens: &mut Tokens) {
966 self.ident.to_tokens(tokens);
Nika Layzellc08227a2017-12-04 16:30:17 -0500967 self.arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700968 }
969 }
970
Nika Layzellc08227a2017-12-04 16:30:17 -0500971 impl ToTokens for PathArguments {
David Tolnay87d0b442016-09-04 11:52:12 -0700972 fn to_tokens(&self, tokens: &mut Tokens) {
973 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500974 PathArguments::None => {}
975 PathArguments::AngleBracketed(ref arguments) => {
976 arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700977 }
Nika Layzellc08227a2017-12-04 16:30:17 -0500978 PathArguments::Parenthesized(ref arguments) => {
979 arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700980 }
981 }
982 }
983 }
984
Nika Layzellc08227a2017-12-04 16:30:17 -0500985 impl ToTokens for GenericArgument {
David Tolnaybb4ca9f2017-12-26 12:28:58 -0500986 #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
Nika Layzell357885a2017-12-04 15:47:07 -0500987 fn to_tokens(&self, tokens: &mut Tokens) {
988 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500989 GenericArgument::Lifetime(ref lt) => lt.to_tokens(tokens),
990 GenericArgument::Type(ref ty) => ty.to_tokens(tokens),
991 GenericArgument::TypeBinding(ref tb) => tb.to_tokens(tokens),
David Tolnay8c91b882017-12-28 23:04:32 -0500992 GenericArgument::Const(ref e) => match *e {
993 Expr::Lit(_) => e.to_tokens(tokens),
Nika Layzellce37f332017-12-05 12:01:22 -0500994
995 // NOTE: We should probably support parsing blocks with only
996 // expressions in them without the full feature for const
997 // generics.
998 #[cfg(feature = "full")]
David Tolnay8c91b882017-12-28 23:04:32 -0500999 Expr::Block(_) => e.to_tokens(tokens),
Nika Layzellce37f332017-12-05 12:01:22 -05001000
1001 // ERROR CORRECTION: Add braces to make sure that the
1002 // generated code is valid.
David Tolnay32954ef2017-12-26 22:43:16 -05001003 _ => token::Brace::default().surround(tokens, |tokens| {
Nika Layzellce37f332017-12-05 12:01:22 -05001004 e.to_tokens(tokens);
1005 }),
David Tolnay51382052017-12-27 13:46:21 -05001006 },
Nika Layzell357885a2017-12-04 15:47:07 -05001007 }
1008 }
1009 }
1010
Nika Layzellc08227a2017-12-04 16:30:17 -05001011 impl ToTokens for AngleBracketedGenericArguments {
David Tolnay87d0b442016-09-04 11:52:12 -07001012 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay2d4e08a2017-12-28 23:54:07 -05001013 self.colon2_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001014 self.lt_token.to_tokens(tokens);
Nika Layzell357885a2017-12-04 15:47:07 -05001015 self.args.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001016 self.gt_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001017 }
1018 }
1019
1020 impl ToTokens for TypeBinding {
1021 fn to_tokens(&self, tokens: &mut Tokens) {
1022 self.ident.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001023 self.eq_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001024 self.ty.to_tokens(tokens);
1025 }
1026 }
1027
Nika Layzellc08227a2017-12-04 16:30:17 -05001028 impl ToTokens for ParenthesizedGenericArguments {
David Tolnay87d0b442016-09-04 11:52:12 -07001029 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001030 self.paren_token.surround(tokens, |tokens| {
1031 self.inputs.to_tokens(tokens);
1032 });
1033 self.output.to_tokens(tokens);
1034 }
1035 }
1036
David Tolnayf93b90d2017-11-11 19:21:26 -08001037 impl ToTokens for ReturnType {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001038 fn to_tokens(&self, tokens: &mut Tokens) {
1039 match *self {
David Tolnayf93b90d2017-11-11 19:21:26 -08001040 ReturnType::Default => {}
David Tolnay4a3f59a2017-12-28 21:21:12 -05001041 ReturnType::Type(ref arrow, ref ty) => {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001042 arrow.to_tokens(tokens);
1043 ty.to_tokens(tokens);
1044 }
David Tolnay87d0b442016-09-04 11:52:12 -07001045 }
1046 }
1047 }
1048
1049 impl ToTokens for PolyTraitRef {
1050 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001051 self.bound_lifetimes.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001052 self.trait_ref.to_tokens(tokens);
1053 }
1054 }
1055
David Tolnayfd6bf5c2017-11-12 09:41:14 -08001056 impl ToTokens for BareFnType {
David Tolnay87d0b442016-09-04 11:52:12 -07001057 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001058 self.lifetimes.to_tokens(tokens);
David Tolnayb8d8ef52016-10-29 14:30:08 -07001059 self.unsafety.to_tokens(tokens);
1060 self.abi.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001061 self.fn_token.to_tokens(tokens);
1062 self.paren_token.surround(tokens, |tokens| {
1063 self.inputs.to_tokens(tokens);
David Tolnay73cc6442017-12-27 22:17:57 -05001064 if let Some(ref variadic) = self.variadic {
David Tolnay0bdb0552017-12-27 21:31:51 -05001065 if !self.inputs.empty_or_trailing() {
1066 let span = variadic.0[0];
1067 <Token![,]>::new(span).to_tokens(tokens);
1068 }
1069 variadic.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -04001070 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001071 });
1072 self.output.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -07001073 }
1074 }
1075
David Tolnay62f374c2016-10-02 13:37:00 -07001076 impl ToTokens for BareFnArg {
David Tolnay42602292016-10-01 22:25:45 -07001077 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001078 if let Some((ref name, ref colon)) = self.name {
David Tolnay62f374c2016-10-02 13:37:00 -07001079 name.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001080 colon.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -07001081 }
1082 self.ty.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001083 }
1084 }
David Tolnayb8d8ef52016-10-29 14:30:08 -07001085
Alex Crichton23a15f62017-08-28 12:34:23 -07001086 impl ToTokens for BareFnArgName {
1087 fn to_tokens(&self, tokens: &mut Tokens) {
1088 match *self {
1089 BareFnArgName::Named(ref t) => t.to_tokens(tokens),
1090 BareFnArgName::Wild(ref t) => t.to_tokens(tokens),
1091 }
1092 }
1093 }
1094
David Tolnayb8d8ef52016-10-29 14:30:08 -07001095 impl ToTokens for Abi {
1096 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001097 self.extern_token.to_tokens(tokens);
1098 match self.kind {
1099 AbiKind::Named(ref named) => named.to_tokens(tokens),
1100 AbiKind::Default => {}
David Tolnayb8d8ef52016-10-29 14:30:08 -07001101 }
1102 }
1103 }
David Tolnay87d0b442016-09-04 11:52:12 -07001104}