blob: bfc03d8f6bacdc8bf5c069287390261877aabf83 [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// Copyright 2018 Syn Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
David Tolnayf2cfd722017-12-31 18:02:51 -05009use punctuated::Punctuated;
David Tolnayb79ee962016-09-04 09:39:20 -070010use super::*;
David Tolnay2ae520a2017-12-29 11:19:50 -050011use proc_macro2::TokenStream;
12#[cfg(feature = "extra-traits")]
13use std::hash::{Hash, Hasher};
14#[cfg(feature = "extra-traits")]
David Tolnayc43b44e2017-12-30 23:55:54 -050015use tt::TokenStreamHelper;
David Tolnayb79ee962016-09-04 09:39:20 -070016
Alex Crichton62a0a592017-05-22 13:58:53 -070017ast_enum_of_structs! {
David Tolnay7949ae22018-01-07 00:14:51 -080018 /// The possible types that a Rust value could have.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080019 pub enum Type {
David Tolnay7949ae22018-01-07 00:14:51 -080020 /// A dynamically sized slice type: `[T]`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080021 pub Slice(TypeSlice {
David Tolnay32954ef2017-12-26 22:43:16 -050022 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050023 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070024 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080025
David Tolnay7949ae22018-01-07 00:14:51 -080026 /// A fixed size array type: `[T; n]`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080027 pub Array(TypeArray {
David Tolnay32954ef2017-12-26 22:43:16 -050028 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050029 pub elem: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080030 pub semi_token: Token![;],
David Tolnayeadbda32017-12-29 02:33:47 -050031 pub len: Expr,
Alex Crichton62a0a592017-05-22 13:58:53 -070032 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080033
David Tolnay7949ae22018-01-07 00:14:51 -080034 /// A raw pointer type: `*const T` or `*mut T`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080035 pub Ptr(TypePtr {
David Tolnayf8db7ba2017-11-11 22:52:16 -080036 pub star_token: Token![*],
37 pub const_token: Option<Token![const]>,
David Tolnay136aaa32017-12-29 02:37:36 -050038 pub mutability: Option<Token![mut]>,
39 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070040 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080041
David Tolnay7949ae22018-01-07 00:14:51 -080042 /// A reference type: `&'a T` or `&'a mut T`.
David Tolnay0a89b4d2017-11-13 00:55:45 -080043 pub Reference(TypeReference {
David Tolnayf8db7ba2017-11-11 22:52:16 -080044 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -070045 pub lifetime: Option<Lifetime>,
David Tolnay136aaa32017-12-29 02:37:36 -050046 pub mutability: Option<Token![mut]>,
47 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070048 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080049
David Tolnay7949ae22018-01-07 00:14:51 -080050 /// A bare function type: `fn(usize) -> bool`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080051 pub BareFn(TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -050052 pub unsafety: Option<Token![unsafe]>,
53 pub abi: Option<Abi>,
54 pub fn_token: Token![fn],
55 pub lifetimes: Option<BoundLifetimes>,
56 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050057 pub inputs: Punctuated<BareFnArg, Token![,]>,
David Tolnaybe7a9592017-12-29 02:39:53 -050058 pub variadic: Option<Token![...]>,
59 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -070060 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080061
David Tolnay7949ae22018-01-07 00:14:51 -080062 /// The never type: `!`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080063 pub Never(TypeNever {
David Tolnayf8db7ba2017-11-11 22:52:16 -080064 pub bang_token: Token![!],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070065 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080066
David Tolnay7949ae22018-01-07 00:14:51 -080067 /// A tuple type: `(A, B, C, String)`.
David Tolnay05362582017-12-26 01:33:57 -050068 pub Tuple(TypeTuple {
David Tolnay32954ef2017-12-26 22:43:16 -050069 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050070 pub elems: Punctuated<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070071 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080072
73 /// A path like `std::slice::Iter`, optionally qualified with a
David Tolnay7949ae22018-01-07 00:14:51 -080074 /// self-type as in `<Vec<T> as SomeTrait>::Associated`.
Alex Crichton62a0a592017-05-22 13:58:53 -070075 ///
David Tolnay7949ae22018-01-07 00:14:51 -080076 /// Type arguments are stored in the Path itself.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080077 pub Path(TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -070078 pub qself: Option<QSelf>,
79 pub path: Path,
80 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080081
David Tolnay7949ae22018-01-07 00:14:51 -080082 /// A trait object type `Bound1 + Bound2 + Bound3` where `Bound` is a
83 /// trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080084 pub TraitObject(TypeTraitObject {
David Tolnaye45b59f2017-12-25 18:44:49 -050085 pub dyn_token: Option<Token![dyn]>,
David Tolnayf2cfd722017-12-31 18:02:51 -050086 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070087 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080088
David Tolnay7949ae22018-01-07 00:14:51 -080089 /// An `impl Bound1 + Bound2 + Bound3` type where `Bound` is a trait or
90 /// a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080091 pub ImplTrait(TypeImplTrait {
David Tolnayf8db7ba2017-11-11 22:52:16 -080092 pub impl_token: Token![impl],
David Tolnayf2cfd722017-12-31 18:02:51 -050093 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070094 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080095
96 /// A parenthesized type equivalent to the inner type.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080097 pub Paren(TypeParen {
David Tolnay32954ef2017-12-26 22:43:16 -050098 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050099 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700100 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800101
102 /// A type contained within invisible delimiters.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800103 pub Group(TypeGroup {
David Tolnay32954ef2017-12-26 22:43:16 -0500104 pub group_token: token::Group,
David Tolnayeadbda32017-12-29 02:33:47 -0500105 pub elem: Box<Type>,
Michael Layzell93c36282017-06-04 20:43:14 -0400106 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800107
David Tolnay7949ae22018-01-07 00:14:51 -0800108 /// Indication that a type should be inferred by the compiler: `_`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800109 pub Infer(TypeInfer {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800110 pub underscore_token: Token![_],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700111 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800112
Alex Crichton62a0a592017-05-22 13:58:53 -0700113 /// A macro in the type position.
David Tolnay323279a2017-12-29 11:26:32 -0500114 pub Macro(TypeMacro {
115 pub mac: Macro,
116 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800117
David Tolnay7949ae22018-01-07 00:14:51 -0800118 /// Tokens in type position not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500119 pub Verbatim(TypeVerbatim #manual_extra_traits {
120 pub tts: TokenStream,
121 }),
122 }
123}
124
125#[cfg(feature = "extra-traits")]
126impl Eq for TypeVerbatim {}
127
128#[cfg(feature = "extra-traits")]
129impl PartialEq for TypeVerbatim {
130 fn eq(&self, other: &Self) -> bool {
131 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
132 }
133}
134
135#[cfg(feature = "extra-traits")]
136impl Hash for TypeVerbatim {
137 fn hash<H>(&self, state: &mut H)
138 where
139 H: Hasher,
140 {
141 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700142 }
143}
144
145ast_struct! {
David Tolnayf01e37b2018-01-06 23:38:26 -0800146 /// The binary interface of a function: `extern "C"`.
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700147 pub struct Abi {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800148 pub extern_token: Token![extern],
David Tolnayf01e37b2018-01-06 23:38:26 -0800149 pub name: Option<LitStr>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700150 }
151}
152
153ast_struct! {
David Tolnay7949ae22018-01-07 00:14:51 -0800154 /// An argument in a function type: the `usize` in `fn(usize) -> bool`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700155 pub struct BareFnArg {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800156 pub name: Option<(BareFnArgName, Token![:])>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800157 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700158 }
159}
160
Alex Crichton23a15f62017-08-28 12:34:23 -0700161ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800162 /// Name of an argument in a function type: the `n` in `fn(n: usize)`.
Alex Crichton23a15f62017-08-28 12:34:23 -0700163 pub enum BareFnArgName {
David Tolnay7949ae22018-01-07 00:14:51 -0800164 /// Argument given a name.
Alex Crichton23a15f62017-08-28 12:34:23 -0700165 Named(Ident),
David Tolnay7949ae22018-01-07 00:14:51 -0800166 /// Argument not given a name, matched with `_`.
David Tolnayf8db7ba2017-11-11 22:52:16 -0800167 Wild(Token![_]),
Alex Crichton23a15f62017-08-28 12:34:23 -0700168 }
169}
Alex Crichton62a0a592017-05-22 13:58:53 -0700170
171ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800172 /// Return type of a function signature.
David Tolnayf93b90d2017-11-11 19:21:26 -0800173 pub enum ReturnType {
Alex Crichton62a0a592017-05-22 13:58:53 -0700174 /// Return type is not specified.
175 ///
David Tolnay7949ae22018-01-07 00:14:51 -0800176 /// Functions default to `()` and closures default to type inference.
Alex Crichton62a0a592017-05-22 13:58:53 -0700177 Default,
David Tolnay7949ae22018-01-07 00:14:51 -0800178 /// A particular type is returned.
David Tolnay4a3f59a2017-12-28 21:21:12 -0500179 Type(Token![->], Box<Type>),
Alex Crichton62a0a592017-05-22 13:58:53 -0700180 }
David Tolnayb79ee962016-09-04 09:39:20 -0700181}
182
David Tolnay86eca752016-09-04 11:26:41 -0700183#[cfg(feature = "parsing")]
David Tolnay9d8f1972016-09-04 11:58:48 -0700184pub mod parsing {
185 use super::*;
Michael Layzell92639a52017-06-01 00:07:44 -0400186 use synom::Synom;
David Tolnay056de302018-01-05 14:29:05 -0800187 use path::parsing::qpath;
David Tolnayda4049b2016-09-04 10:59:23 -0700188
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800189 impl Synom for Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400190 named!(parse -> Self, call!(ambig_ty, true));
David Tolnayb79ee962016-09-04 09:39:20 -0700191
Alex Crichton954046c2017-05-30 21:49:42 -0700192 fn description() -> Option<&'static str> {
193 Some("type")
194 }
195 }
David Tolnay0047c712016-12-21 21:59:25 -0500196
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800197 impl Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400198 /// In some positions, types may not contain the `+` character, to
199 /// disambiguate them. For example in the expression `1 as T`, T may not
200 /// contain a `+` character.
201 ///
202 /// This parser does not allow a `+`, while the default parser does.
Michael Layzell6a5a1642017-06-04 19:35:15 -0400203 named!(pub without_plus -> Self, call!(ambig_ty, false));
Michael Layzell9bf2b002017-06-04 18:49:53 -0400204 }
205
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800206 named!(ambig_ty(allow_plus: bool) -> Type, alt!(
207 syn!(TypeGroup) => { Type::Group }
Michael Layzell93c36282017-06-04 20:43:14 -0400208 |
David Tolnay05362582017-12-26 01:33:57 -0500209 // must be before TypeTuple
David Tolnay0a169d42017-12-29 17:57:29 -0500210 call!(TypeParen::parse, allow_plus) => { Type::Paren }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400211 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500212 // must be before TypePath
David Tolnay323279a2017-12-29 11:26:32 -0500213 syn!(TypeMacro) => { Type::Macro }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400214 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500215 // must be before TypeTraitObject
216 call!(TypePath::parse, allow_plus) => { Type::Path }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400217 |
David Tolnay0a169d42017-12-29 17:57:29 -0500218 // Don't try parsing more than one trait bound if we aren't allowing it.
219 // must be before TypeTuple
220 call!(TypeTraitObject::parse, allow_plus) => { Type::TraitObject }
221 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800222 syn!(TypeSlice) => { Type::Slice }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400223 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800224 syn!(TypeArray) => { Type::Array }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400225 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800226 syn!(TypePtr) => { Type::Ptr }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400227 |
David Tolnay0a89b4d2017-11-13 00:55:45 -0800228 syn!(TypeReference) => { Type::Reference }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400229 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800230 syn!(TypeBareFn) => { Type::BareFn }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400231 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800232 syn!(TypeNever) => { Type::Never }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400233 |
David Tolnay05362582017-12-26 01:33:57 -0500234 syn!(TypeTuple) => { Type::Tuple }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400235 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800236 syn!(TypeImplTrait) => { Type::ImplTrait }
Alex Crichton23a15f62017-08-28 12:34:23 -0700237 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800238 syn!(TypeInfer) => { Type::Infer }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400239 ));
240
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800241 impl Synom for TypeSlice {
Michael Layzell92639a52017-06-01 00:07:44 -0400242 named!(parse -> Self, map!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800243 brackets!(syn!(Type)),
David Tolnay8875fca2017-12-31 13:52:37 -0500244 |(b, ty)| TypeSlice {
David Tolnayeadbda32017-12-29 02:33:47 -0500245 elem: Box::new(ty),
Michael Layzell92639a52017-06-01 00:07:44 -0400246 bracket_token: b,
Alex Crichton954046c2017-05-30 21:49:42 -0700247 }
Michael Layzell92639a52017-06-01 00:07:44 -0400248 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800249
250 fn description() -> Option<&'static str> {
251 Some("slice type")
252 }
Alex Crichton954046c2017-05-30 21:49:42 -0700253 }
David Tolnayb79ee962016-09-04 09:39:20 -0700254
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800255 impl Synom for TypeArray {
Michael Layzell92639a52017-06-01 00:07:44 -0400256 named!(parse -> Self, map!(
257 brackets!(do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800258 elem: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800259 semi: punct!(;) >>
Michael Layzelld7ee9102017-06-07 10:02:19 -0400260 len: syn!(Expr) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700261 (elem, semi, len)
Michael Layzell92639a52017-06-01 00:07:44 -0400262 )),
David Tolnay8875fca2017-12-31 13:52:37 -0500263 |(brackets, (elem, semi, len))| {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800264 TypeArray {
David Tolnayeadbda32017-12-29 02:33:47 -0500265 elem: Box::new(elem),
266 len: len,
Michael Layzell92639a52017-06-01 00:07:44 -0400267 bracket_token: brackets,
268 semi_token: semi,
Alex Crichton954046c2017-05-30 21:49:42 -0700269 }
270 }
Michael Layzell92639a52017-06-01 00:07:44 -0400271 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800272
273 fn description() -> Option<&'static str> {
274 Some("array type")
275 }
Alex Crichton954046c2017-05-30 21:49:42 -0700276 }
David Tolnayfa94b6f2016-10-05 23:26:11 -0700277
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800278 impl Synom for TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400279 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800280 star: punct!(*) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400281 mutability: alt!(
David Tolnay24237fb2017-12-29 02:15:26 -0500282 keyword!(const) => { |c| (None, Some(c)) }
Michael Layzell92639a52017-06-01 00:07:44 -0400283 |
David Tolnay24237fb2017-12-29 02:15:26 -0500284 keyword!(mut) => { |m| (Some(m), None) }
Michael Layzell92639a52017-06-01 00:07:44 -0400285 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800286 target: call!(Type::without_plus) >>
287 (TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400288 const_token: mutability.1,
289 star_token: star,
David Tolnay136aaa32017-12-29 02:37:36 -0500290 mutability: mutability.0,
291 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400292 })
293 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800294
295 fn description() -> Option<&'static str> {
296 Some("raw pointer type")
297 }
Alex Crichton954046c2017-05-30 21:49:42 -0700298 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700299
David Tolnay0a89b4d2017-11-13 00:55:45 -0800300 impl Synom for TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400301 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800302 amp: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400303 life: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500304 mutability: option!(keyword!(mut)) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400305 // & binds tighter than +, so we don't allow + here.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800306 target: call!(Type::without_plus) >>
David Tolnay0a89b4d2017-11-13 00:55:45 -0800307 (TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400308 lifetime: life,
David Tolnay136aaa32017-12-29 02:37:36 -0500309 mutability: mutability,
310 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400311 and_token: amp,
312 })
313 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800314
315 fn description() -> Option<&'static str> {
316 Some("reference type")
317 }
Alex Crichton954046c2017-05-30 21:49:42 -0700318 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700319
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800320 impl Synom for TypeBareFn {
Michael Layzell92639a52017-06-01 00:07:44 -0400321 named!(parse -> Self, do_parse!(
322 lifetimes: option!(syn!(BoundLifetimes)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500323 unsafety: option!(keyword!(unsafe)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400324 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800325 fn_: keyword!(fn) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400326 parens: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500327 inputs: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500328 variadic: option!(cond_reduce!(inputs.empty_or_trailing(), punct!(...))) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400329 (inputs, variadic)
330 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800331 output: syn!(ReturnType) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800332 (TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -0500333 unsafety: unsafety,
334 abi: abi,
335 lifetimes: lifetimes,
336 output: output,
David Tolnay8875fca2017-12-31 13:52:37 -0500337 variadic: (parens.1).1,
David Tolnaybe7a9592017-12-29 02:39:53 -0500338 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500339 paren_token: parens.0,
340 inputs: (parens.1).0,
Michael Layzell92639a52017-06-01 00:07:44 -0400341 })
342 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800343
344 fn description() -> Option<&'static str> {
345 Some("`fn` type")
346 }
Alex Crichton954046c2017-05-30 21:49:42 -0700347 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700348
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800349 impl Synom for TypeNever {
Michael Layzell92639a52017-06-01 00:07:44 -0400350 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800351 punct!(!),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800352 |b| TypeNever { bang_token: b }
Michael Layzell92639a52017-06-01 00:07:44 -0400353 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800354
355 fn description() -> Option<&'static str> {
356 Some("never type: `!`")
357 }
Alex Crichton954046c2017-05-30 21:49:42 -0700358 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700359
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800360 impl Synom for TypeInfer {
Alex Crichton23a15f62017-08-28 12:34:23 -0700361 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800362 punct!(_),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800363 |u| TypeInfer { underscore_token: u }
Alex Crichton23a15f62017-08-28 12:34:23 -0700364 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800365
366 fn description() -> Option<&'static str> {
367 Some("inferred type: `_`")
368 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700369 }
370
David Tolnay05362582017-12-26 01:33:57 -0500371 impl Synom for TypeTuple {
Michael Layzell92639a52017-06-01 00:07:44 -0400372 named!(parse -> Self, do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500373 data: parens!(Punctuated::parse_terminated) >>
David Tolnay05362582017-12-26 01:33:57 -0500374 (TypeTuple {
David Tolnay8875fca2017-12-31 13:52:37 -0500375 paren_token: data.0,
376 elems: data.1,
Michael Layzell92639a52017-06-01 00:07:44 -0400377 })
378 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800379
380 fn description() -> Option<&'static str> {
381 Some("tuple type")
382 }
Alex Crichton954046c2017-05-30 21:49:42 -0700383 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700384
David Tolnay323279a2017-12-29 11:26:32 -0500385 impl Synom for TypeMacro {
386 named!(parse -> Self, map!(syn!(Macro), |mac| TypeMacro { mac: mac }));
387 }
388
David Tolnay0a169d42017-12-29 17:57:29 -0500389 impl Synom for TypePath {
390 named!(parse -> Self, call!(Self::parse, false));
391 }
392
David Tolnay7d38c7e2017-12-25 22:31:50 -0500393 impl TypePath {
394 named!(parse(allow_plus: bool) -> Self, do_parse!(
395 qpath: qpath >>
David Tolnay660fd1f2017-12-31 01:52:57 -0500396 parenthesized: option!(cond_reduce!(
David Tolnay56080682018-01-06 14:01:52 -0800397 qpath.1.segments.last().unwrap().value().arguments.is_empty(),
David Tolnay660fd1f2017-12-31 01:52:57 -0500398 syn!(ParenthesizedGenericArguments)
399 )) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500400 cond!(allow_plus, not!(punct!(+))) >>
David Tolnay7d38c7e2017-12-25 22:31:50 -0500401 ({
402 let (qself, mut path) = qpath;
David Tolnay660fd1f2017-12-31 01:52:57 -0500403 if let Some(parenthesized) = parenthesized {
David Tolnay7d38c7e2017-12-25 22:31:50 -0500404 let parenthesized = PathArguments::Parenthesized(parenthesized);
David Tolnay56080682018-01-06 14:01:52 -0800405 path.segments.last_mut().unwrap().value_mut().arguments = parenthesized;
David Tolnay7d38c7e2017-12-25 22:31:50 -0500406 }
407 TypePath { qself: qself, path: path }
408 })
409 ));
410 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700411
David Tolnayf93b90d2017-11-11 19:21:26 -0800412 impl Synom for ReturnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400413 named!(parse -> Self, alt!(
414 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800415 arrow: punct!(->) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800416 ty: syn!(Type) >>
David Tolnay4a3f59a2017-12-28 21:21:12 -0500417 (ReturnType::Type(arrow, Box::new(ty)))
Michael Layzell92639a52017-06-01 00:07:44 -0400418 )
419 |
David Tolnayf93b90d2017-11-11 19:21:26 -0800420 epsilon!() => { |_| ReturnType::Default }
Michael Layzell92639a52017-06-01 00:07:44 -0400421 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800422
423 fn description() -> Option<&'static str> {
424 Some("return type")
425 }
Alex Crichton954046c2017-05-30 21:49:42 -0700426 }
427
David Tolnay0a169d42017-12-29 17:57:29 -0500428 impl Synom for TypeTraitObject {
429 named!(parse -> Self, call!(Self::parse, true));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800430
431 fn description() -> Option<&'static str> {
432 Some("trait object type")
433 }
David Tolnay0a169d42017-12-29 17:57:29 -0500434 }
435
David Tolnay7d38c7e2017-12-25 22:31:50 -0500436 impl TypeTraitObject {
David Tolnay0a169d42017-12-29 17:57:29 -0500437 named!(pub without_plus -> Self, call!(Self::parse, false));
438
David Tolnay7d38c7e2017-12-25 22:31:50 -0500439 // Only allow multiple trait references if allow_plus is true.
440 named!(parse(allow_plus: bool) -> Self, do_parse!(
441 dyn_token: option!(keyword!(dyn)) >>
442 bounds: alt!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500443 cond_reduce!(allow_plus, Punctuated::parse_terminated_nonempty)
David Tolnay7d38c7e2017-12-25 22:31:50 -0500444 |
David Tolnay660fd1f2017-12-31 01:52:57 -0500445 syn!(TypeParamBound) => {|x| {
David Tolnayf2cfd722017-12-31 18:02:51 -0500446 let mut bounds = Punctuated::new();
David Tolnay56080682018-01-06 14:01:52 -0800447 bounds.push_value(x);
David Tolnayf2cfd722017-12-31 18:02:51 -0500448 bounds
David Tolnay660fd1f2017-12-31 01:52:57 -0500449 }}
David Tolnay7d38c7e2017-12-25 22:31:50 -0500450 ) >>
451 (TypeTraitObject {
452 dyn_token: dyn_token,
453 bounds: bounds,
454 })
455 ));
456 }
David Tolnay6414da72016-10-08 00:55:17 -0700457
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800458 impl Synom for TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400459 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800460 impl_: keyword!(impl) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400461 // NOTE: rust-lang/rust#34511 includes discussion about whether or
462 // not + should be allowed in ImplTrait directly without ().
David Tolnayf2cfd722017-12-31 18:02:51 -0500463 elem: call!(Punctuated::parse_terminated_nonempty) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800464 (TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400465 impl_token: impl_,
466 bounds: elem,
467 })
468 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800469
470 fn description() -> Option<&'static str> {
471 Some("`impl Trait` type")
472 }
Alex Crichton954046c2017-05-30 21:49:42 -0700473 }
David Tolnayb79ee962016-09-04 09:39:20 -0700474
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800475 impl Synom for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400476 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800477 data: grouped!(syn!(Type)) >>
478 (TypeGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500479 group_token: data.0,
480 elem: Box::new(data.1),
Michael Layzell93c36282017-06-04 20:43:14 -0400481 })
482 ));
483 }
484
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800485 impl Synom for TypeParen {
David Tolnay0a169d42017-12-29 17:57:29 -0500486 named!(parse -> Self, call!(Self::parse, false));
487 }
488
489 impl TypeParen {
490 named!(parse(allow_plus: bool) -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800491 data: parens!(syn!(Type)) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500492 cond!(allow_plus, not!(punct!(+))) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800493 (TypeParen {
David Tolnay8875fca2017-12-31 13:52:37 -0500494 paren_token: data.0,
495 elem: Box::new(data.1),
Michael Layzell92639a52017-06-01 00:07:44 -0400496 })
497 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700498 }
David Tolnayb79ee962016-09-04 09:39:20 -0700499
Alex Crichton954046c2017-05-30 21:49:42 -0700500 impl Synom for BareFnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400501 named!(parse -> Self, do_parse!(
502 name: option!(do_parse!(
Alex Crichton23a15f62017-08-28 12:34:23 -0700503 name: syn!(BareFnArgName) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800504 not!(punct!(::)) >>
505 colon: punct!(:) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400506 (name, colon)
507 )) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800508 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400509 (BareFnArg {
510 name: name,
511 ty: ty,
512 })
513 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800514
515 fn description() -> Option<&'static str> {
516 Some("function type argument")
517 }
Alex Crichton954046c2017-05-30 21:49:42 -0700518 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700519
Alex Crichton23a15f62017-08-28 12:34:23 -0700520 impl Synom for BareFnArgName {
521 named!(parse -> Self, alt!(
522 map!(syn!(Ident), BareFnArgName::Named)
523 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800524 map!(punct!(_), BareFnArgName::Wild)
Alex Crichton23a15f62017-08-28 12:34:23 -0700525 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800526
527 fn description() -> Option<&'static str> {
528 Some("function argument name")
529 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700530 }
531
Alex Crichton954046c2017-05-30 21:49:42 -0700532 impl Synom for Abi {
Michael Layzell92639a52017-06-01 00:07:44 -0400533 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800534 extern_: keyword!(extern) >>
David Tolnayf01e37b2018-01-06 23:38:26 -0800535 name: option!(syn!(LitStr)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400536 (Abi {
537 extern_token: extern_,
David Tolnayd5125762017-12-29 02:42:17 -0500538 name: name,
Michael Layzell92639a52017-06-01 00:07:44 -0400539 })
540 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800541
542 fn description() -> Option<&'static str> {
543 Some("ABI qualifier")
544 }
Alex Crichton954046c2017-05-30 21:49:42 -0700545 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700546}
David Tolnay87d0b442016-09-04 11:52:12 -0700547
548#[cfg(feature = "printing")]
549mod printing {
550 use super::*;
David Tolnay51382052017-12-27 13:46:21 -0500551 use quote::{ToTokens, Tokens};
David Tolnay87d0b442016-09-04 11:52:12 -0700552
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800553 impl ToTokens for TypeSlice {
David Tolnay87d0b442016-09-04 11:52:12 -0700554 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700555 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500556 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700557 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700558 }
559 }
560
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800561 impl ToTokens for TypeArray {
Alex Crichton62a0a592017-05-22 13:58:53 -0700562 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700563 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500564 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700565 self.semi_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500566 self.len.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700567 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700568 }
569 }
570
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800571 impl ToTokens for TypePtr {
Alex Crichton62a0a592017-05-22 13:58:53 -0700572 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700573 self.star_token.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500574 match self.mutability {
David Tolnay24237fb2017-12-29 02:15:26 -0500575 Some(ref tok) => tok.to_tokens(tokens),
576 None => {
Alex Crichton259ee532017-07-14 06:51:02 -0700577 TokensOrDefault(&self.const_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400578 }
579 }
David Tolnay136aaa32017-12-29 02:37:36 -0500580 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700581 }
582 }
583
David Tolnay0a89b4d2017-11-13 00:55:45 -0800584 impl ToTokens for TypeReference {
Alex Crichton62a0a592017-05-22 13:58:53 -0700585 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700586 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700587 self.lifetime.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500588 self.mutability.to_tokens(tokens);
589 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700590 }
591 }
592
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800593 impl ToTokens for TypeBareFn {
Alex Crichton62a0a592017-05-22 13:58:53 -0700594 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaybe7a9592017-12-29 02:39:53 -0500595 self.lifetimes.to_tokens(tokens);
596 self.unsafety.to_tokens(tokens);
597 self.abi.to_tokens(tokens);
598 self.fn_token.to_tokens(tokens);
599 self.paren_token.surround(tokens, |tokens| {
600 self.inputs.to_tokens(tokens);
601 if let Some(ref variadic) = self.variadic {
602 if !self.inputs.empty_or_trailing() {
603 let span = variadic.0[0];
604 <Token![,]>::new(span).to_tokens(tokens);
605 }
606 variadic.to_tokens(tokens);
607 }
608 });
609 self.output.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700610 }
611 }
612
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800613 impl ToTokens for TypeNever {
Alex Crichton62a0a592017-05-22 13:58:53 -0700614 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700615 self.bang_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700616 }
617 }
618
David Tolnay05362582017-12-26 01:33:57 -0500619 impl ToTokens for TypeTuple {
Alex Crichton62a0a592017-05-22 13:58:53 -0700620 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700621 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500622 self.elems.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700623 })
Alex Crichton62a0a592017-05-22 13:58:53 -0700624 }
625 }
626
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800627 impl ToTokens for TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -0700628 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700629 PathTokens(&self.qself, &self.path).to_tokens(tokens);
630 }
631 }
632
633 impl<'a> ToTokens for PathTokens<'a> {
634 fn to_tokens(&self, tokens: &mut Tokens) {
635 let qself = match *self.0 {
Alex Crichton62a0a592017-05-22 13:58:53 -0700636 Some(ref qself) => qself,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700637 None => return self.1.to_tokens(tokens),
Alex Crichton62a0a592017-05-22 13:58:53 -0700638 };
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700639 qself.lt_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700640 qself.ty.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400641
642 // XXX: Gross.
643 let pos = if qself.position > 0 && qself.position >= self.1.segments.len() {
644 self.1.segments.len() - 1
645 } else {
646 qself.position
647 };
David Tolnay56080682018-01-06 14:01:52 -0800648 let mut segments = self.1.segments.pairs();
Michael Layzell3936ceb2017-07-08 00:28:36 -0400649 if pos > 0 {
Alex Crichton259ee532017-07-14 06:51:02 -0700650 TokensOrDefault(&qself.as_token).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700651 self.1.leading_colon.to_tokens(tokens);
David Tolnay6eff4da2018-01-01 20:27:45 -0800652 for (i, segment) in segments.by_ref().take(pos).enumerate() {
David Tolnay570695e2017-06-03 16:15:13 -0700653 if i + 1 == pos {
David Tolnay56080682018-01-06 14:01:52 -0800654 segment.value().to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700655 qself.gt_token.to_tokens(tokens);
David Tolnayf2cfd722017-12-31 18:02:51 -0500656 segment.punct().to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700657 } else {
658 segment.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700659 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700660 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700661 } else {
662 qself.gt_token.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700663 self.1.leading_colon.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700664 }
David Tolnay570695e2017-06-03 16:15:13 -0700665 for segment in segments {
Alex Crichton62a0a592017-05-22 13:58:53 -0700666 segment.to_tokens(tokens);
667 }
668 }
669 }
670
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800671 impl ToTokens for TypeTraitObject {
Alex Crichton62a0a592017-05-22 13:58:53 -0700672 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaye45b59f2017-12-25 18:44:49 -0500673 self.dyn_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700674 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700675 }
676 }
677
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800678 impl ToTokens for TypeImplTrait {
Alex Crichton62a0a592017-05-22 13:58:53 -0700679 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700680 self.impl_token.to_tokens(tokens);
681 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700682 }
683 }
684
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800685 impl ToTokens for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400686 fn to_tokens(&self, tokens: &mut Tokens) {
687 self.group_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500688 self.elem.to_tokens(tokens);
Michael Layzell93c36282017-06-04 20:43:14 -0400689 });
690 }
691 }
692
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800693 impl ToTokens for TypeParen {
Alex Crichton62a0a592017-05-22 13:58:53 -0700694 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700695 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500696 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700697 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700698 }
699 }
700
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800701 impl ToTokens for TypeInfer {
Alex Crichton62a0a592017-05-22 13:58:53 -0700702 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700703 self.underscore_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700704 }
705 }
706
David Tolnay323279a2017-12-29 11:26:32 -0500707 impl ToTokens for TypeMacro {
708 fn to_tokens(&self, tokens: &mut Tokens) {
709 self.mac.to_tokens(tokens);
710 }
711 }
712
David Tolnay2ae520a2017-12-29 11:19:50 -0500713 impl ToTokens for TypeVerbatim {
714 fn to_tokens(&self, tokens: &mut Tokens) {
715 self.tts.to_tokens(tokens);
716 }
717 }
718
David Tolnayf93b90d2017-11-11 19:21:26 -0800719 impl ToTokens for ReturnType {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700720 fn to_tokens(&self, tokens: &mut Tokens) {
721 match *self {
David Tolnayf93b90d2017-11-11 19:21:26 -0800722 ReturnType::Default => {}
David Tolnay4a3f59a2017-12-28 21:21:12 -0500723 ReturnType::Type(ref arrow, ref ty) => {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700724 arrow.to_tokens(tokens);
725 ty.to_tokens(tokens);
726 }
David Tolnay87d0b442016-09-04 11:52:12 -0700727 }
728 }
729 }
730
David Tolnay62f374c2016-10-02 13:37:00 -0700731 impl ToTokens for BareFnArg {
David Tolnay42602292016-10-01 22:25:45 -0700732 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700733 if let Some((ref name, ref colon)) = self.name {
David Tolnay62f374c2016-10-02 13:37:00 -0700734 name.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700735 colon.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -0700736 }
737 self.ty.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700738 }
739 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700740
Alex Crichton23a15f62017-08-28 12:34:23 -0700741 impl ToTokens for BareFnArgName {
742 fn to_tokens(&self, tokens: &mut Tokens) {
743 match *self {
744 BareFnArgName::Named(ref t) => t.to_tokens(tokens),
745 BareFnArgName::Wild(ref t) => t.to_tokens(tokens),
746 }
747 }
748 }
749
David Tolnayb8d8ef52016-10-29 14:30:08 -0700750 impl ToTokens for Abi {
751 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700752 self.extern_token.to_tokens(tokens);
David Tolnayd5125762017-12-29 02:42:17 -0500753 self.name.to_tokens(tokens);
David Tolnayb8d8ef52016-10-29 14:30:08 -0700754 }
755 }
David Tolnay87d0b442016-09-04 11:52:12 -0700756}