blob: 6eadfa12f31ed580835dbd4d7d2d24c3295341c3 [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 Tolnay7949ae22018-01-07 00:14:51 -080025 /// A fixed size array type: `[T; n]`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080026 pub Array(TypeArray {
David Tolnay32954ef2017-12-26 22:43:16 -050027 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050028 pub elem: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080029 pub semi_token: Token![;],
David Tolnayeadbda32017-12-29 02:33:47 -050030 pub len: Expr,
Alex Crichton62a0a592017-05-22 13:58:53 -070031 }),
David Tolnay7949ae22018-01-07 00:14:51 -080032 /// A raw pointer type: `*const T` or `*mut T`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080033 pub Ptr(TypePtr {
David Tolnayf8db7ba2017-11-11 22:52:16 -080034 pub star_token: Token![*],
35 pub const_token: Option<Token![const]>,
David Tolnay136aaa32017-12-29 02:37:36 -050036 pub mutability: Option<Token![mut]>,
37 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070038 }),
David Tolnay7949ae22018-01-07 00:14:51 -080039 /// A reference type: `&'a T` or `&'a mut T`.
David Tolnay0a89b4d2017-11-13 00:55:45 -080040 pub Reference(TypeReference {
David Tolnayf8db7ba2017-11-11 22:52:16 -080041 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -070042 pub lifetime: Option<Lifetime>,
David Tolnay136aaa32017-12-29 02:37:36 -050043 pub mutability: Option<Token![mut]>,
44 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070045 }),
David Tolnay7949ae22018-01-07 00:14:51 -080046 /// A bare function type: `fn(usize) -> bool`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080047 pub BareFn(TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -050048 pub unsafety: Option<Token![unsafe]>,
49 pub abi: Option<Abi>,
50 pub fn_token: Token![fn],
51 pub lifetimes: Option<BoundLifetimes>,
52 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050053 pub inputs: Punctuated<BareFnArg, Token![,]>,
David Tolnaybe7a9592017-12-29 02:39:53 -050054 pub variadic: Option<Token![...]>,
55 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -070056 }),
David Tolnay7949ae22018-01-07 00:14:51 -080057 /// The never type: `!`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080058 pub Never(TypeNever {
David Tolnayf8db7ba2017-11-11 22:52:16 -080059 pub bang_token: Token![!],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070060 }),
David Tolnay7949ae22018-01-07 00:14:51 -080061 /// A tuple type: `(A, B, C, String)`.
David Tolnay05362582017-12-26 01:33:57 -050062 pub Tuple(TypeTuple {
David Tolnay32954ef2017-12-26 22:43:16 -050063 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050064 pub elems: Punctuated<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070065 }),
David Tolnay7949ae22018-01-07 00:14:51 -080066 /// A path like `std::slice::Iter`, optionally "qualified" with a
67 /// self-type as in `<Vec<T> as SomeTrait>::Associated`.
Alex Crichton62a0a592017-05-22 13:58:53 -070068 ///
David Tolnay7949ae22018-01-07 00:14:51 -080069 /// Type arguments are stored in the Path itself.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080070 pub Path(TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -070071 pub qself: Option<QSelf>,
72 pub path: Path,
73 }),
David Tolnay7949ae22018-01-07 00:14:51 -080074 /// A trait object type `Bound1 + Bound2 + Bound3` where `Bound` is a
75 /// trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080076 pub TraitObject(TypeTraitObject {
David Tolnaye45b59f2017-12-25 18:44:49 -050077 pub dyn_token: Option<Token![dyn]>,
David Tolnayf2cfd722017-12-31 18:02:51 -050078 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070079 }),
David Tolnay7949ae22018-01-07 00:14:51 -080080 /// An `impl Bound1 + Bound2 + Bound3` type where `Bound` is a trait or
81 /// a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080082 pub ImplTrait(TypeImplTrait {
David Tolnayf8db7ba2017-11-11 22:52:16 -080083 pub impl_token: Token![impl],
David Tolnayf2cfd722017-12-31 18:02:51 -050084 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070085 }),
David Tolnay7949ae22018-01-07 00:14:51 -080086 /// A parenthesized type equal to the inner type; important for
87 /// round-tripping types faithfully.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080088 pub Paren(TypeParen {
David Tolnay32954ef2017-12-26 22:43:16 -050089 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050090 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070091 }),
David Tolnay7949ae22018-01-07 00:14:51 -080092 /// A type contained within invisible delimiters; important for
93 /// round-tripping types faithfully.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080094 pub Group(TypeGroup {
David Tolnay32954ef2017-12-26 22:43:16 -050095 pub group_token: token::Group,
David Tolnayeadbda32017-12-29 02:33:47 -050096 pub elem: Box<Type>,
Michael Layzell93c36282017-06-04 20:43:14 -040097 }),
David Tolnay7949ae22018-01-07 00:14:51 -080098 /// Indication that a type should be inferred by the compiler: `_`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080099 pub Infer(TypeInfer {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800100 pub underscore_token: Token![_],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700101 }),
Alex Crichton62a0a592017-05-22 13:58:53 -0700102 /// A macro in the type position.
David Tolnay323279a2017-12-29 11:26:32 -0500103 pub Macro(TypeMacro {
104 pub mac: Macro,
105 }),
David Tolnay7949ae22018-01-07 00:14:51 -0800106 /// Tokens in type position not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500107 pub Verbatim(TypeVerbatim #manual_extra_traits {
108 pub tts: TokenStream,
109 }),
110 }
111}
112
113#[cfg(feature = "extra-traits")]
114impl Eq for TypeVerbatim {}
115
116#[cfg(feature = "extra-traits")]
117impl PartialEq for TypeVerbatim {
118 fn eq(&self, other: &Self) -> bool {
119 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
120 }
121}
122
123#[cfg(feature = "extra-traits")]
124impl Hash for TypeVerbatim {
125 fn hash<H>(&self, state: &mut H)
126 where
127 H: Hasher,
128 {
129 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700130 }
131}
132
133ast_struct! {
David Tolnayf01e37b2018-01-06 23:38:26 -0800134 /// The binary interface of a function: `extern "C"`.
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700135 pub struct Abi {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800136 pub extern_token: Token![extern],
David Tolnayf01e37b2018-01-06 23:38:26 -0800137 pub name: Option<LitStr>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700138 }
139}
140
141ast_struct! {
David Tolnay7949ae22018-01-07 00:14:51 -0800142 /// An argument in a function type: the `usize` in `fn(usize) -> bool`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700143 pub struct BareFnArg {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800144 pub name: Option<(BareFnArgName, Token![:])>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800145 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700146 }
147}
148
Alex Crichton23a15f62017-08-28 12:34:23 -0700149ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800150 /// Name of an argument in a function type: the `n` in `fn(n: usize)`.
Alex Crichton23a15f62017-08-28 12:34:23 -0700151 pub enum BareFnArgName {
David Tolnay7949ae22018-01-07 00:14:51 -0800152 /// Argument given a name.
Alex Crichton23a15f62017-08-28 12:34:23 -0700153 Named(Ident),
David Tolnay7949ae22018-01-07 00:14:51 -0800154 /// Argument not given a name, matched with `_`.
David Tolnayf8db7ba2017-11-11 22:52:16 -0800155 Wild(Token![_]),
Alex Crichton23a15f62017-08-28 12:34:23 -0700156 }
157}
Alex Crichton62a0a592017-05-22 13:58:53 -0700158
159ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800160 /// Return type of a function signature.
David Tolnayf93b90d2017-11-11 19:21:26 -0800161 pub enum ReturnType {
Alex Crichton62a0a592017-05-22 13:58:53 -0700162 /// Return type is not specified.
163 ///
David Tolnay7949ae22018-01-07 00:14:51 -0800164 /// Functions default to `()` and closures default to type inference.
Alex Crichton62a0a592017-05-22 13:58:53 -0700165 Default,
David Tolnay7949ae22018-01-07 00:14:51 -0800166 /// A particular type is returned.
David Tolnay4a3f59a2017-12-28 21:21:12 -0500167 Type(Token![->], Box<Type>),
Alex Crichton62a0a592017-05-22 13:58:53 -0700168 }
David Tolnayb79ee962016-09-04 09:39:20 -0700169}
170
David Tolnay86eca752016-09-04 11:26:41 -0700171#[cfg(feature = "parsing")]
David Tolnay9d8f1972016-09-04 11:58:48 -0700172pub mod parsing {
173 use super::*;
Michael Layzell92639a52017-06-01 00:07:44 -0400174 use synom::Synom;
David Tolnay056de302018-01-05 14:29:05 -0800175 use path::parsing::qpath;
David Tolnayda4049b2016-09-04 10:59:23 -0700176
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800177 impl Synom for Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400178 named!(parse -> Self, call!(ambig_ty, true));
David Tolnayb79ee962016-09-04 09:39:20 -0700179
Alex Crichton954046c2017-05-30 21:49:42 -0700180 fn description() -> Option<&'static str> {
181 Some("type")
182 }
183 }
David Tolnay0047c712016-12-21 21:59:25 -0500184
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800185 impl Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400186 /// In some positions, types may not contain the `+` character, to
187 /// disambiguate them. For example in the expression `1 as T`, T may not
188 /// contain a `+` character.
189 ///
190 /// This parser does not allow a `+`, while the default parser does.
Michael Layzell6a5a1642017-06-04 19:35:15 -0400191 named!(pub without_plus -> Self, call!(ambig_ty, false));
Michael Layzell9bf2b002017-06-04 18:49:53 -0400192 }
193
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800194 named!(ambig_ty(allow_plus: bool) -> Type, alt!(
195 syn!(TypeGroup) => { Type::Group }
Michael Layzell93c36282017-06-04 20:43:14 -0400196 |
David Tolnay05362582017-12-26 01:33:57 -0500197 // must be before TypeTuple
David Tolnay0a169d42017-12-29 17:57:29 -0500198 call!(TypeParen::parse, allow_plus) => { Type::Paren }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400199 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500200 // must be before TypePath
David Tolnay323279a2017-12-29 11:26:32 -0500201 syn!(TypeMacro) => { Type::Macro }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400202 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500203 // must be before TypeTraitObject
204 call!(TypePath::parse, allow_plus) => { Type::Path }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400205 |
David Tolnay0a169d42017-12-29 17:57:29 -0500206 // Don't try parsing more than one trait bound if we aren't allowing it.
207 // must be before TypeTuple
208 call!(TypeTraitObject::parse, allow_plus) => { Type::TraitObject }
209 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800210 syn!(TypeSlice) => { Type::Slice }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400211 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800212 syn!(TypeArray) => { Type::Array }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400213 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800214 syn!(TypePtr) => { Type::Ptr }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400215 |
David Tolnay0a89b4d2017-11-13 00:55:45 -0800216 syn!(TypeReference) => { Type::Reference }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400217 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800218 syn!(TypeBareFn) => { Type::BareFn }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400219 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800220 syn!(TypeNever) => { Type::Never }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400221 |
David Tolnay05362582017-12-26 01:33:57 -0500222 syn!(TypeTuple) => { Type::Tuple }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400223 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800224 syn!(TypeImplTrait) => { Type::ImplTrait }
Alex Crichton23a15f62017-08-28 12:34:23 -0700225 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800226 syn!(TypeInfer) => { Type::Infer }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400227 ));
228
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800229 impl Synom for TypeSlice {
Michael Layzell92639a52017-06-01 00:07:44 -0400230 named!(parse -> Self, map!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800231 brackets!(syn!(Type)),
David Tolnay8875fca2017-12-31 13:52:37 -0500232 |(b, ty)| TypeSlice {
David Tolnayeadbda32017-12-29 02:33:47 -0500233 elem: Box::new(ty),
Michael Layzell92639a52017-06-01 00:07:44 -0400234 bracket_token: b,
Alex Crichton954046c2017-05-30 21:49:42 -0700235 }
Michael Layzell92639a52017-06-01 00:07:44 -0400236 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800237
238 fn description() -> Option<&'static str> {
239 Some("slice type")
240 }
Alex Crichton954046c2017-05-30 21:49:42 -0700241 }
David Tolnayb79ee962016-09-04 09:39:20 -0700242
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800243 impl Synom for TypeArray {
Michael Layzell92639a52017-06-01 00:07:44 -0400244 named!(parse -> Self, map!(
245 brackets!(do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800246 elem: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800247 semi: punct!(;) >>
Michael Layzelld7ee9102017-06-07 10:02:19 -0400248 len: syn!(Expr) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700249 (elem, semi, len)
Michael Layzell92639a52017-06-01 00:07:44 -0400250 )),
David Tolnay8875fca2017-12-31 13:52:37 -0500251 |(brackets, (elem, semi, len))| {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800252 TypeArray {
David Tolnayeadbda32017-12-29 02:33:47 -0500253 elem: Box::new(elem),
254 len: len,
Michael Layzell92639a52017-06-01 00:07:44 -0400255 bracket_token: brackets,
256 semi_token: semi,
Alex Crichton954046c2017-05-30 21:49:42 -0700257 }
258 }
Michael Layzell92639a52017-06-01 00:07:44 -0400259 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800260
261 fn description() -> Option<&'static str> {
262 Some("array type")
263 }
Alex Crichton954046c2017-05-30 21:49:42 -0700264 }
David Tolnayfa94b6f2016-10-05 23:26:11 -0700265
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800266 impl Synom for TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400267 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800268 star: punct!(*) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400269 mutability: alt!(
David Tolnay24237fb2017-12-29 02:15:26 -0500270 keyword!(const) => { |c| (None, Some(c)) }
Michael Layzell92639a52017-06-01 00:07:44 -0400271 |
David Tolnay24237fb2017-12-29 02:15:26 -0500272 keyword!(mut) => { |m| (Some(m), None) }
Michael Layzell92639a52017-06-01 00:07:44 -0400273 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800274 target: call!(Type::without_plus) >>
275 (TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400276 const_token: mutability.1,
277 star_token: star,
David Tolnay136aaa32017-12-29 02:37:36 -0500278 mutability: mutability.0,
279 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400280 })
281 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800282
283 fn description() -> Option<&'static str> {
284 Some("raw pointer type")
285 }
Alex Crichton954046c2017-05-30 21:49:42 -0700286 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700287
David Tolnay0a89b4d2017-11-13 00:55:45 -0800288 impl Synom for TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400289 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800290 amp: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400291 life: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500292 mutability: option!(keyword!(mut)) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400293 // & binds tighter than +, so we don't allow + here.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800294 target: call!(Type::without_plus) >>
David Tolnay0a89b4d2017-11-13 00:55:45 -0800295 (TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400296 lifetime: life,
David Tolnay136aaa32017-12-29 02:37:36 -0500297 mutability: mutability,
298 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400299 and_token: amp,
300 })
301 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800302
303 fn description() -> Option<&'static str> {
304 Some("reference type")
305 }
Alex Crichton954046c2017-05-30 21:49:42 -0700306 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700307
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800308 impl Synom for TypeBareFn {
Michael Layzell92639a52017-06-01 00:07:44 -0400309 named!(parse -> Self, do_parse!(
310 lifetimes: option!(syn!(BoundLifetimes)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500311 unsafety: option!(keyword!(unsafe)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400312 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800313 fn_: keyword!(fn) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400314 parens: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500315 inputs: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500316 variadic: option!(cond_reduce!(inputs.empty_or_trailing(), punct!(...))) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400317 (inputs, variadic)
318 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800319 output: syn!(ReturnType) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800320 (TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -0500321 unsafety: unsafety,
322 abi: abi,
323 lifetimes: lifetimes,
324 output: output,
David Tolnay8875fca2017-12-31 13:52:37 -0500325 variadic: (parens.1).1,
David Tolnaybe7a9592017-12-29 02:39:53 -0500326 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500327 paren_token: parens.0,
328 inputs: (parens.1).0,
Michael Layzell92639a52017-06-01 00:07:44 -0400329 })
330 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800331
332 fn description() -> Option<&'static str> {
333 Some("`fn` type")
334 }
Alex Crichton954046c2017-05-30 21:49:42 -0700335 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700336
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800337 impl Synom for TypeNever {
Michael Layzell92639a52017-06-01 00:07:44 -0400338 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800339 punct!(!),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800340 |b| TypeNever { bang_token: b }
Michael Layzell92639a52017-06-01 00:07:44 -0400341 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800342
343 fn description() -> Option<&'static str> {
344 Some("never type: `!`")
345 }
Alex Crichton954046c2017-05-30 21:49:42 -0700346 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700347
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800348 impl Synom for TypeInfer {
Alex Crichton23a15f62017-08-28 12:34:23 -0700349 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800350 punct!(_),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800351 |u| TypeInfer { underscore_token: u }
Alex Crichton23a15f62017-08-28 12:34:23 -0700352 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800353
354 fn description() -> Option<&'static str> {
355 Some("inferred type: `_`")
356 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700357 }
358
David Tolnay05362582017-12-26 01:33:57 -0500359 impl Synom for TypeTuple {
Michael Layzell92639a52017-06-01 00:07:44 -0400360 named!(parse -> Self, do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500361 data: parens!(Punctuated::parse_terminated) >>
David Tolnay05362582017-12-26 01:33:57 -0500362 (TypeTuple {
David Tolnay8875fca2017-12-31 13:52:37 -0500363 paren_token: data.0,
364 elems: data.1,
Michael Layzell92639a52017-06-01 00:07:44 -0400365 })
366 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800367
368 fn description() -> Option<&'static str> {
369 Some("tuple type")
370 }
Alex Crichton954046c2017-05-30 21:49:42 -0700371 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700372
David Tolnay323279a2017-12-29 11:26:32 -0500373 impl Synom for TypeMacro {
374 named!(parse -> Self, map!(syn!(Macro), |mac| TypeMacro { mac: mac }));
375 }
376
David Tolnay0a169d42017-12-29 17:57:29 -0500377 impl Synom for TypePath {
378 named!(parse -> Self, call!(Self::parse, false));
379 }
380
David Tolnay7d38c7e2017-12-25 22:31:50 -0500381 impl TypePath {
382 named!(parse(allow_plus: bool) -> Self, do_parse!(
383 qpath: qpath >>
David Tolnay660fd1f2017-12-31 01:52:57 -0500384 parenthesized: option!(cond_reduce!(
David Tolnay56080682018-01-06 14:01:52 -0800385 qpath.1.segments.last().unwrap().value().arguments.is_empty(),
David Tolnay660fd1f2017-12-31 01:52:57 -0500386 syn!(ParenthesizedGenericArguments)
387 )) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500388 cond!(allow_plus, not!(punct!(+))) >>
David Tolnay7d38c7e2017-12-25 22:31:50 -0500389 ({
390 let (qself, mut path) = qpath;
David Tolnay660fd1f2017-12-31 01:52:57 -0500391 if let Some(parenthesized) = parenthesized {
David Tolnay7d38c7e2017-12-25 22:31:50 -0500392 let parenthesized = PathArguments::Parenthesized(parenthesized);
David Tolnay56080682018-01-06 14:01:52 -0800393 path.segments.last_mut().unwrap().value_mut().arguments = parenthesized;
David Tolnay7d38c7e2017-12-25 22:31:50 -0500394 }
395 TypePath { qself: qself, path: path }
396 })
397 ));
398 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700399
David Tolnayf93b90d2017-11-11 19:21:26 -0800400 impl Synom for ReturnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400401 named!(parse -> Self, alt!(
402 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800403 arrow: punct!(->) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800404 ty: syn!(Type) >>
David Tolnay4a3f59a2017-12-28 21:21:12 -0500405 (ReturnType::Type(arrow, Box::new(ty)))
Michael Layzell92639a52017-06-01 00:07:44 -0400406 )
407 |
David Tolnayf93b90d2017-11-11 19:21:26 -0800408 epsilon!() => { |_| ReturnType::Default }
Michael Layzell92639a52017-06-01 00:07:44 -0400409 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800410
411 fn description() -> Option<&'static str> {
412 Some("return type")
413 }
Alex Crichton954046c2017-05-30 21:49:42 -0700414 }
415
David Tolnay0a169d42017-12-29 17:57:29 -0500416 impl Synom for TypeTraitObject {
417 named!(parse -> Self, call!(Self::parse, true));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800418
419 fn description() -> Option<&'static str> {
420 Some("trait object type")
421 }
David Tolnay0a169d42017-12-29 17:57:29 -0500422 }
423
David Tolnay7d38c7e2017-12-25 22:31:50 -0500424 impl TypeTraitObject {
David Tolnay0a169d42017-12-29 17:57:29 -0500425 named!(pub without_plus -> Self, call!(Self::parse, false));
426
David Tolnay7d38c7e2017-12-25 22:31:50 -0500427 // Only allow multiple trait references if allow_plus is true.
428 named!(parse(allow_plus: bool) -> Self, do_parse!(
429 dyn_token: option!(keyword!(dyn)) >>
430 bounds: alt!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500431 cond_reduce!(allow_plus, Punctuated::parse_terminated_nonempty)
David Tolnay7d38c7e2017-12-25 22:31:50 -0500432 |
David Tolnay660fd1f2017-12-31 01:52:57 -0500433 syn!(TypeParamBound) => {|x| {
David Tolnayf2cfd722017-12-31 18:02:51 -0500434 let mut bounds = Punctuated::new();
David Tolnay56080682018-01-06 14:01:52 -0800435 bounds.push_value(x);
David Tolnayf2cfd722017-12-31 18:02:51 -0500436 bounds
David Tolnay660fd1f2017-12-31 01:52:57 -0500437 }}
David Tolnay7d38c7e2017-12-25 22:31:50 -0500438 ) >>
439 (TypeTraitObject {
440 dyn_token: dyn_token,
441 bounds: bounds,
442 })
443 ));
444 }
David Tolnay6414da72016-10-08 00:55:17 -0700445
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800446 impl Synom for TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400447 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800448 impl_: keyword!(impl) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400449 // NOTE: rust-lang/rust#34511 includes discussion about whether or
450 // not + should be allowed in ImplTrait directly without ().
David Tolnayf2cfd722017-12-31 18:02:51 -0500451 elem: call!(Punctuated::parse_terminated_nonempty) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800452 (TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400453 impl_token: impl_,
454 bounds: elem,
455 })
456 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800457
458 fn description() -> Option<&'static str> {
459 Some("`impl Trait` type")
460 }
Alex Crichton954046c2017-05-30 21:49:42 -0700461 }
David Tolnayb79ee962016-09-04 09:39:20 -0700462
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800463 impl Synom for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400464 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800465 data: grouped!(syn!(Type)) >>
466 (TypeGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500467 group_token: data.0,
468 elem: Box::new(data.1),
Michael Layzell93c36282017-06-04 20:43:14 -0400469 })
470 ));
471 }
472
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800473 impl Synom for TypeParen {
David Tolnay0a169d42017-12-29 17:57:29 -0500474 named!(parse -> Self, call!(Self::parse, false));
475 }
476
477 impl TypeParen {
478 named!(parse(allow_plus: bool) -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800479 data: parens!(syn!(Type)) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500480 cond!(allow_plus, not!(punct!(+))) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800481 (TypeParen {
David Tolnay8875fca2017-12-31 13:52:37 -0500482 paren_token: data.0,
483 elem: Box::new(data.1),
Michael Layzell92639a52017-06-01 00:07:44 -0400484 })
485 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700486 }
David Tolnayb79ee962016-09-04 09:39:20 -0700487
Alex Crichton954046c2017-05-30 21:49:42 -0700488 impl Synom for BareFnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400489 named!(parse -> Self, do_parse!(
490 name: option!(do_parse!(
Alex Crichton23a15f62017-08-28 12:34:23 -0700491 name: syn!(BareFnArgName) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800492 not!(punct!(::)) >>
493 colon: punct!(:) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400494 (name, colon)
495 )) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800496 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400497 (BareFnArg {
498 name: name,
499 ty: ty,
500 })
501 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800502
503 fn description() -> Option<&'static str> {
504 Some("function type argument")
505 }
Alex Crichton954046c2017-05-30 21:49:42 -0700506 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700507
Alex Crichton23a15f62017-08-28 12:34:23 -0700508 impl Synom for BareFnArgName {
509 named!(parse -> Self, alt!(
510 map!(syn!(Ident), BareFnArgName::Named)
511 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800512 map!(punct!(_), BareFnArgName::Wild)
Alex Crichton23a15f62017-08-28 12:34:23 -0700513 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800514
515 fn description() -> Option<&'static str> {
516 Some("function argument name")
517 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700518 }
519
Alex Crichton954046c2017-05-30 21:49:42 -0700520 impl Synom for Abi {
Michael Layzell92639a52017-06-01 00:07:44 -0400521 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800522 extern_: keyword!(extern) >>
David Tolnayf01e37b2018-01-06 23:38:26 -0800523 name: option!(syn!(LitStr)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400524 (Abi {
525 extern_token: extern_,
David Tolnayd5125762017-12-29 02:42:17 -0500526 name: name,
Michael Layzell92639a52017-06-01 00:07:44 -0400527 })
528 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800529
530 fn description() -> Option<&'static str> {
531 Some("ABI qualifier")
532 }
Alex Crichton954046c2017-05-30 21:49:42 -0700533 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700534}
David Tolnay87d0b442016-09-04 11:52:12 -0700535
536#[cfg(feature = "printing")]
537mod printing {
538 use super::*;
David Tolnay51382052017-12-27 13:46:21 -0500539 use quote::{ToTokens, Tokens};
David Tolnay87d0b442016-09-04 11:52:12 -0700540
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800541 impl ToTokens for TypeSlice {
David Tolnay87d0b442016-09-04 11:52:12 -0700542 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700543 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500544 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700545 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700546 }
547 }
548
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800549 impl ToTokens for TypeArray {
Alex Crichton62a0a592017-05-22 13:58:53 -0700550 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700551 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500552 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700553 self.semi_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500554 self.len.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700555 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700556 }
557 }
558
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800559 impl ToTokens for TypePtr {
Alex Crichton62a0a592017-05-22 13:58:53 -0700560 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700561 self.star_token.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500562 match self.mutability {
David Tolnay24237fb2017-12-29 02:15:26 -0500563 Some(ref tok) => tok.to_tokens(tokens),
564 None => {
Alex Crichton259ee532017-07-14 06:51:02 -0700565 TokensOrDefault(&self.const_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400566 }
567 }
David Tolnay136aaa32017-12-29 02:37:36 -0500568 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700569 }
570 }
571
David Tolnay0a89b4d2017-11-13 00:55:45 -0800572 impl ToTokens for TypeReference {
Alex Crichton62a0a592017-05-22 13:58:53 -0700573 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700574 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700575 self.lifetime.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500576 self.mutability.to_tokens(tokens);
577 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700578 }
579 }
580
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800581 impl ToTokens for TypeBareFn {
Alex Crichton62a0a592017-05-22 13:58:53 -0700582 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaybe7a9592017-12-29 02:39:53 -0500583 self.lifetimes.to_tokens(tokens);
584 self.unsafety.to_tokens(tokens);
585 self.abi.to_tokens(tokens);
586 self.fn_token.to_tokens(tokens);
587 self.paren_token.surround(tokens, |tokens| {
588 self.inputs.to_tokens(tokens);
589 if let Some(ref variadic) = self.variadic {
590 if !self.inputs.empty_or_trailing() {
591 let span = variadic.0[0];
592 <Token![,]>::new(span).to_tokens(tokens);
593 }
594 variadic.to_tokens(tokens);
595 }
596 });
597 self.output.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700598 }
599 }
600
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800601 impl ToTokens for TypeNever {
Alex Crichton62a0a592017-05-22 13:58:53 -0700602 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700603 self.bang_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700604 }
605 }
606
David Tolnay05362582017-12-26 01:33:57 -0500607 impl ToTokens for TypeTuple {
Alex Crichton62a0a592017-05-22 13:58:53 -0700608 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700609 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500610 self.elems.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700611 })
Alex Crichton62a0a592017-05-22 13:58:53 -0700612 }
613 }
614
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800615 impl ToTokens for TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -0700616 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700617 PathTokens(&self.qself, &self.path).to_tokens(tokens);
618 }
619 }
620
621 impl<'a> ToTokens for PathTokens<'a> {
622 fn to_tokens(&self, tokens: &mut Tokens) {
623 let qself = match *self.0 {
Alex Crichton62a0a592017-05-22 13:58:53 -0700624 Some(ref qself) => qself,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700625 None => return self.1.to_tokens(tokens),
Alex Crichton62a0a592017-05-22 13:58:53 -0700626 };
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700627 qself.lt_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700628 qself.ty.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400629
630 // XXX: Gross.
631 let pos = if qself.position > 0 && qself.position >= self.1.segments.len() {
632 self.1.segments.len() - 1
633 } else {
634 qself.position
635 };
David Tolnay56080682018-01-06 14:01:52 -0800636 let mut segments = self.1.segments.pairs();
Michael Layzell3936ceb2017-07-08 00:28:36 -0400637 if pos > 0 {
Alex Crichton259ee532017-07-14 06:51:02 -0700638 TokensOrDefault(&qself.as_token).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700639 self.1.leading_colon.to_tokens(tokens);
David Tolnay6eff4da2018-01-01 20:27:45 -0800640 for (i, segment) in segments.by_ref().take(pos).enumerate() {
David Tolnay570695e2017-06-03 16:15:13 -0700641 if i + 1 == pos {
David Tolnay56080682018-01-06 14:01:52 -0800642 segment.value().to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700643 qself.gt_token.to_tokens(tokens);
David Tolnayf2cfd722017-12-31 18:02:51 -0500644 segment.punct().to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700645 } else {
646 segment.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700647 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700648 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700649 } else {
650 qself.gt_token.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700651 self.1.leading_colon.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700652 }
David Tolnay570695e2017-06-03 16:15:13 -0700653 for segment in segments {
Alex Crichton62a0a592017-05-22 13:58:53 -0700654 segment.to_tokens(tokens);
655 }
656 }
657 }
658
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800659 impl ToTokens for TypeTraitObject {
Alex Crichton62a0a592017-05-22 13:58:53 -0700660 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaye45b59f2017-12-25 18:44:49 -0500661 self.dyn_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700662 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700663 }
664 }
665
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800666 impl ToTokens for TypeImplTrait {
Alex Crichton62a0a592017-05-22 13:58:53 -0700667 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700668 self.impl_token.to_tokens(tokens);
669 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700670 }
671 }
672
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800673 impl ToTokens for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400674 fn to_tokens(&self, tokens: &mut Tokens) {
675 self.group_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500676 self.elem.to_tokens(tokens);
Michael Layzell93c36282017-06-04 20:43:14 -0400677 });
678 }
679 }
680
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800681 impl ToTokens for TypeParen {
Alex Crichton62a0a592017-05-22 13:58:53 -0700682 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700683 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500684 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700685 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700686 }
687 }
688
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800689 impl ToTokens for TypeInfer {
Alex Crichton62a0a592017-05-22 13:58:53 -0700690 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700691 self.underscore_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700692 }
693 }
694
David Tolnay323279a2017-12-29 11:26:32 -0500695 impl ToTokens for TypeMacro {
696 fn to_tokens(&self, tokens: &mut Tokens) {
697 self.mac.to_tokens(tokens);
698 }
699 }
700
David Tolnay2ae520a2017-12-29 11:19:50 -0500701 impl ToTokens for TypeVerbatim {
702 fn to_tokens(&self, tokens: &mut Tokens) {
703 self.tts.to_tokens(tokens);
704 }
705 }
706
David Tolnayf93b90d2017-11-11 19:21:26 -0800707 impl ToTokens for ReturnType {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700708 fn to_tokens(&self, tokens: &mut Tokens) {
709 match *self {
David Tolnayf93b90d2017-11-11 19:21:26 -0800710 ReturnType::Default => {}
David Tolnay4a3f59a2017-12-28 21:21:12 -0500711 ReturnType::Type(ref arrow, ref ty) => {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700712 arrow.to_tokens(tokens);
713 ty.to_tokens(tokens);
714 }
David Tolnay87d0b442016-09-04 11:52:12 -0700715 }
716 }
717 }
718
David Tolnay62f374c2016-10-02 13:37:00 -0700719 impl ToTokens for BareFnArg {
David Tolnay42602292016-10-01 22:25:45 -0700720 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700721 if let Some((ref name, ref colon)) = self.name {
David Tolnay62f374c2016-10-02 13:37:00 -0700722 name.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700723 colon.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -0700724 }
725 self.ty.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700726 }
727 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700728
Alex Crichton23a15f62017-08-28 12:34:23 -0700729 impl ToTokens for BareFnArgName {
730 fn to_tokens(&self, tokens: &mut Tokens) {
731 match *self {
732 BareFnArgName::Named(ref t) => t.to_tokens(tokens),
733 BareFnArgName::Wild(ref t) => t.to_tokens(tokens),
734 }
735 }
736 }
737
David Tolnayb8d8ef52016-10-29 14:30:08 -0700738 impl ToTokens for Abi {
739 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700740 self.extern_token.to_tokens(tokens);
David Tolnayd5125762017-12-29 02:42:17 -0500741 self.name.to_tokens(tokens);
David Tolnayb8d8ef52016-10-29 14:30:08 -0700742 }
743 }
David Tolnay87d0b442016-09-04 11:52:12 -0700744}