blob: 39bae3843c9f3b2bcfda18292d4f179183361192 [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 Tolnay614a0142018-01-07 10:25:43 -080019 ///
20 /// # Syntax tree enum
21 ///
22 /// This type is a [syntax tree enum].
23 ///
24 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnayfd6bf5c2017-11-12 09:41:14 -080025 pub enum Type {
David Tolnay7949ae22018-01-07 00:14:51 -080026 /// A dynamically sized slice type: `[T]`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080027 pub Slice(TypeSlice {
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>,
Alex Crichton62a0a592017-05-22 13:58:53 -070030 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080031
David Tolnay7949ae22018-01-07 00:14:51 -080032 /// A fixed size array type: `[T; n]`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080033 pub Array(TypeArray {
David Tolnay32954ef2017-12-26 22:43:16 -050034 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050035 pub elem: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080036 pub semi_token: Token![;],
David Tolnayeadbda32017-12-29 02:33:47 -050037 pub len: Expr,
Alex Crichton62a0a592017-05-22 13:58:53 -070038 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080039
David Tolnay7949ae22018-01-07 00:14:51 -080040 /// A raw pointer type: `*const T` or `*mut T`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080041 pub Ptr(TypePtr {
David Tolnayf8db7ba2017-11-11 22:52:16 -080042 pub star_token: Token![*],
43 pub const_token: Option<Token![const]>,
David Tolnay136aaa32017-12-29 02:37:36 -050044 pub mutability: Option<Token![mut]>,
45 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070046 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080047
David Tolnay7949ae22018-01-07 00:14:51 -080048 /// A reference type: `&'a T` or `&'a mut T`.
David Tolnay0a89b4d2017-11-13 00:55:45 -080049 pub Reference(TypeReference {
David Tolnayf8db7ba2017-11-11 22:52:16 -080050 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -070051 pub lifetime: Option<Lifetime>,
David Tolnay136aaa32017-12-29 02:37:36 -050052 pub mutability: Option<Token![mut]>,
53 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070054 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080055
David Tolnay7949ae22018-01-07 00:14:51 -080056 /// A bare function type: `fn(usize) -> bool`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080057 pub BareFn(TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -050058 pub unsafety: Option<Token![unsafe]>,
59 pub abi: Option<Abi>,
60 pub fn_token: Token![fn],
61 pub lifetimes: Option<BoundLifetimes>,
62 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050063 pub inputs: Punctuated<BareFnArg, Token![,]>,
David Tolnaybe7a9592017-12-29 02:39:53 -050064 pub variadic: Option<Token![...]>,
65 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -070066 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080067
David Tolnay7949ae22018-01-07 00:14:51 -080068 /// The never type: `!`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080069 pub Never(TypeNever {
David Tolnayf8db7ba2017-11-11 22:52:16 -080070 pub bang_token: Token![!],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070071 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080072
David Tolnay7949ae22018-01-07 00:14:51 -080073 /// A tuple type: `(A, B, C, String)`.
David Tolnay05362582017-12-26 01:33:57 -050074 pub Tuple(TypeTuple {
David Tolnay32954ef2017-12-26 22:43:16 -050075 pub paren_token: token::Paren,
David Tolnayf2cfd722017-12-31 18:02:51 -050076 pub elems: Punctuated<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070077 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080078
79 /// A path like `std::slice::Iter`, optionally qualified with a
David Tolnay7949ae22018-01-07 00:14:51 -080080 /// self-type as in `<Vec<T> as SomeTrait>::Associated`.
Alex Crichton62a0a592017-05-22 13:58:53 -070081 ///
David Tolnay7949ae22018-01-07 00:14:51 -080082 /// Type arguments are stored in the Path itself.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080083 pub Path(TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -070084 pub qself: Option<QSelf>,
85 pub path: Path,
86 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080087
David Tolnay7949ae22018-01-07 00:14:51 -080088 /// A trait object type `Bound1 + Bound2 + Bound3` where `Bound` is a
89 /// trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080090 pub TraitObject(TypeTraitObject {
David Tolnaye45b59f2017-12-25 18:44:49 -050091 pub dyn_token: Option<Token![dyn]>,
David Tolnayf2cfd722017-12-31 18:02:51 -050092 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070093 }),
David Tolnaya454c8f2018-01-07 01:01:10 -080094
David Tolnay7949ae22018-01-07 00:14:51 -080095 /// An `impl Bound1 + Bound2 + Bound3` type where `Bound` is a trait or
96 /// a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080097 pub ImplTrait(TypeImplTrait {
David Tolnayf8db7ba2017-11-11 22:52:16 -080098 pub impl_token: Token![impl],
David Tolnayf2cfd722017-12-31 18:02:51 -050099 pub bounds: Punctuated<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700100 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800101
102 /// A parenthesized type equivalent to the inner type.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800103 pub Paren(TypeParen {
David Tolnay32954ef2017-12-26 22:43:16 -0500104 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -0500105 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700106 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800107
108 /// A type contained within invisible delimiters.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800109 pub Group(TypeGroup {
David Tolnay32954ef2017-12-26 22:43:16 -0500110 pub group_token: token::Group,
David Tolnayeadbda32017-12-29 02:33:47 -0500111 pub elem: Box<Type>,
Michael Layzell93c36282017-06-04 20:43:14 -0400112 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800113
David Tolnay7949ae22018-01-07 00:14:51 -0800114 /// Indication that a type should be inferred by the compiler: `_`.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800115 pub Infer(TypeInfer {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800116 pub underscore_token: Token![_],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700117 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800118
Alex Crichton62a0a592017-05-22 13:58:53 -0700119 /// A macro in the type position.
David Tolnay323279a2017-12-29 11:26:32 -0500120 pub Macro(TypeMacro {
121 pub mac: Macro,
122 }),
David Tolnaya454c8f2018-01-07 01:01:10 -0800123
David Tolnay7949ae22018-01-07 00:14:51 -0800124 /// Tokens in type position not interpreted by Syn.
David Tolnay2ae520a2017-12-29 11:19:50 -0500125 pub Verbatim(TypeVerbatim #manual_extra_traits {
126 pub tts: TokenStream,
127 }),
128 }
129}
130
131#[cfg(feature = "extra-traits")]
132impl Eq for TypeVerbatim {}
133
134#[cfg(feature = "extra-traits")]
135impl PartialEq for TypeVerbatim {
136 fn eq(&self, other: &Self) -> bool {
137 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
138 }
139}
140
141#[cfg(feature = "extra-traits")]
142impl Hash for TypeVerbatim {
143 fn hash<H>(&self, state: &mut H)
144 where
145 H: Hasher,
146 {
147 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700148 }
149}
150
151ast_struct! {
David Tolnayf01e37b2018-01-06 23:38:26 -0800152 /// The binary interface of a function: `extern "C"`.
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700153 pub struct Abi {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800154 pub extern_token: Token![extern],
David Tolnayf01e37b2018-01-06 23:38:26 -0800155 pub name: Option<LitStr>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700156 }
157}
158
159ast_struct! {
David Tolnay7949ae22018-01-07 00:14:51 -0800160 /// An argument in a function type: the `usize` in `fn(usize) -> bool`.
Alex Crichton62a0a592017-05-22 13:58:53 -0700161 pub struct BareFnArg {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800162 pub name: Option<(BareFnArgName, Token![:])>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800163 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700164 }
165}
166
Alex Crichton23a15f62017-08-28 12:34:23 -0700167ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800168 /// Name of an argument in a function type: the `n` in `fn(n: usize)`.
Alex Crichton23a15f62017-08-28 12:34:23 -0700169 pub enum BareFnArgName {
David Tolnay7949ae22018-01-07 00:14:51 -0800170 /// Argument given a name.
Alex Crichton23a15f62017-08-28 12:34:23 -0700171 Named(Ident),
David Tolnay7949ae22018-01-07 00:14:51 -0800172 /// Argument not given a name, matched with `_`.
David Tolnayf8db7ba2017-11-11 22:52:16 -0800173 Wild(Token![_]),
Alex Crichton23a15f62017-08-28 12:34:23 -0700174 }
175}
Alex Crichton62a0a592017-05-22 13:58:53 -0700176
177ast_enum! {
David Tolnay7949ae22018-01-07 00:14:51 -0800178 /// Return type of a function signature.
David Tolnayf93b90d2017-11-11 19:21:26 -0800179 pub enum ReturnType {
Alex Crichton62a0a592017-05-22 13:58:53 -0700180 /// Return type is not specified.
181 ///
David Tolnay7949ae22018-01-07 00:14:51 -0800182 /// Functions default to `()` and closures default to type inference.
Alex Crichton62a0a592017-05-22 13:58:53 -0700183 Default,
David Tolnay7949ae22018-01-07 00:14:51 -0800184 /// A particular type is returned.
David Tolnay4a3f59a2017-12-28 21:21:12 -0500185 Type(Token![->], Box<Type>),
Alex Crichton62a0a592017-05-22 13:58:53 -0700186 }
David Tolnayb79ee962016-09-04 09:39:20 -0700187}
188
David Tolnay86eca752016-09-04 11:26:41 -0700189#[cfg(feature = "parsing")]
David Tolnay9d8f1972016-09-04 11:58:48 -0700190pub mod parsing {
191 use super::*;
Michael Layzell92639a52017-06-01 00:07:44 -0400192 use synom::Synom;
David Tolnay056de302018-01-05 14:29:05 -0800193 use path::parsing::qpath;
David Tolnayda4049b2016-09-04 10:59:23 -0700194
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800195 impl Synom for Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400196 named!(parse -> Self, call!(ambig_ty, true));
David Tolnayb79ee962016-09-04 09:39:20 -0700197
Alex Crichton954046c2017-05-30 21:49:42 -0700198 fn description() -> Option<&'static str> {
199 Some("type")
200 }
201 }
David Tolnay0047c712016-12-21 21:59:25 -0500202
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800203 impl Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400204 /// In some positions, types may not contain the `+` character, to
205 /// disambiguate them. For example in the expression `1 as T`, T may not
206 /// contain a `+` character.
207 ///
208 /// This parser does not allow a `+`, while the default parser does.
Michael Layzell6a5a1642017-06-04 19:35:15 -0400209 named!(pub without_plus -> Self, call!(ambig_ty, false));
Michael Layzell9bf2b002017-06-04 18:49:53 -0400210 }
211
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800212 named!(ambig_ty(allow_plus: bool) -> Type, alt!(
213 syn!(TypeGroup) => { Type::Group }
Michael Layzell93c36282017-06-04 20:43:14 -0400214 |
David Tolnay05362582017-12-26 01:33:57 -0500215 // must be before TypeTuple
David Tolnay0a169d42017-12-29 17:57:29 -0500216 call!(TypeParen::parse, allow_plus) => { Type::Paren }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400217 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500218 // must be before TypePath
David Tolnay323279a2017-12-29 11:26:32 -0500219 syn!(TypeMacro) => { Type::Macro }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400220 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500221 // must be before TypeTraitObject
222 call!(TypePath::parse, allow_plus) => { Type::Path }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400223 |
David Tolnay0a169d42017-12-29 17:57:29 -0500224 // Don't try parsing more than one trait bound if we aren't allowing it.
225 // must be before TypeTuple
226 call!(TypeTraitObject::parse, allow_plus) => { Type::TraitObject }
227 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800228 syn!(TypeSlice) => { Type::Slice }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400229 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800230 syn!(TypeArray) => { Type::Array }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400231 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800232 syn!(TypePtr) => { Type::Ptr }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400233 |
David Tolnay0a89b4d2017-11-13 00:55:45 -0800234 syn!(TypeReference) => { Type::Reference }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400235 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800236 syn!(TypeBareFn) => { Type::BareFn }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400237 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800238 syn!(TypeNever) => { Type::Never }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400239 |
David Tolnay05362582017-12-26 01:33:57 -0500240 syn!(TypeTuple) => { Type::Tuple }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400241 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800242 syn!(TypeImplTrait) => { Type::ImplTrait }
Alex Crichton23a15f62017-08-28 12:34:23 -0700243 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800244 syn!(TypeInfer) => { Type::Infer }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400245 ));
246
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800247 impl Synom for TypeSlice {
Michael Layzell92639a52017-06-01 00:07:44 -0400248 named!(parse -> Self, map!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800249 brackets!(syn!(Type)),
David Tolnay8875fca2017-12-31 13:52:37 -0500250 |(b, ty)| TypeSlice {
David Tolnayeadbda32017-12-29 02:33:47 -0500251 elem: Box::new(ty),
Michael Layzell92639a52017-06-01 00:07:44 -0400252 bracket_token: b,
Alex Crichton954046c2017-05-30 21:49:42 -0700253 }
Michael Layzell92639a52017-06-01 00:07:44 -0400254 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800255
256 fn description() -> Option<&'static str> {
257 Some("slice type")
258 }
Alex Crichton954046c2017-05-30 21:49:42 -0700259 }
David Tolnayb79ee962016-09-04 09:39:20 -0700260
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800261 impl Synom for TypeArray {
Michael Layzell92639a52017-06-01 00:07:44 -0400262 named!(parse -> Self, map!(
263 brackets!(do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800264 elem: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800265 semi: punct!(;) >>
Michael Layzelld7ee9102017-06-07 10:02:19 -0400266 len: syn!(Expr) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700267 (elem, semi, len)
Michael Layzell92639a52017-06-01 00:07:44 -0400268 )),
David Tolnay8875fca2017-12-31 13:52:37 -0500269 |(brackets, (elem, semi, len))| {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800270 TypeArray {
David Tolnayeadbda32017-12-29 02:33:47 -0500271 elem: Box::new(elem),
272 len: len,
Michael Layzell92639a52017-06-01 00:07:44 -0400273 bracket_token: brackets,
274 semi_token: semi,
Alex Crichton954046c2017-05-30 21:49:42 -0700275 }
276 }
Michael Layzell92639a52017-06-01 00:07:44 -0400277 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800278
279 fn description() -> Option<&'static str> {
280 Some("array type")
281 }
Alex Crichton954046c2017-05-30 21:49:42 -0700282 }
David Tolnayfa94b6f2016-10-05 23:26:11 -0700283
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800284 impl Synom for TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400285 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800286 star: punct!(*) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400287 mutability: alt!(
David Tolnay24237fb2017-12-29 02:15:26 -0500288 keyword!(const) => { |c| (None, Some(c)) }
Michael Layzell92639a52017-06-01 00:07:44 -0400289 |
David Tolnay24237fb2017-12-29 02:15:26 -0500290 keyword!(mut) => { |m| (Some(m), None) }
Michael Layzell92639a52017-06-01 00:07:44 -0400291 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800292 target: call!(Type::without_plus) >>
293 (TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400294 const_token: mutability.1,
295 star_token: star,
David Tolnay136aaa32017-12-29 02:37:36 -0500296 mutability: mutability.0,
297 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400298 })
299 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800300
301 fn description() -> Option<&'static str> {
302 Some("raw pointer type")
303 }
Alex Crichton954046c2017-05-30 21:49:42 -0700304 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700305
David Tolnay0a89b4d2017-11-13 00:55:45 -0800306 impl Synom for TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400307 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800308 amp: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400309 life: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500310 mutability: option!(keyword!(mut)) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400311 // & binds tighter than +, so we don't allow + here.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800312 target: call!(Type::without_plus) >>
David Tolnay0a89b4d2017-11-13 00:55:45 -0800313 (TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400314 lifetime: life,
David Tolnay136aaa32017-12-29 02:37:36 -0500315 mutability: mutability,
316 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400317 and_token: amp,
318 })
319 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800320
321 fn description() -> Option<&'static str> {
322 Some("reference type")
323 }
Alex Crichton954046c2017-05-30 21:49:42 -0700324 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700325
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800326 impl Synom for TypeBareFn {
Michael Layzell92639a52017-06-01 00:07:44 -0400327 named!(parse -> Self, do_parse!(
328 lifetimes: option!(syn!(BoundLifetimes)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500329 unsafety: option!(keyword!(unsafe)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400330 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800331 fn_: keyword!(fn) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400332 parens: parens!(do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500333 inputs: call!(Punctuated::parse_terminated) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500334 variadic: option!(cond_reduce!(inputs.empty_or_trailing(), punct!(...))) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400335 (inputs, variadic)
336 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800337 output: syn!(ReturnType) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800338 (TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -0500339 unsafety: unsafety,
340 abi: abi,
341 lifetimes: lifetimes,
342 output: output,
David Tolnay8875fca2017-12-31 13:52:37 -0500343 variadic: (parens.1).1,
David Tolnaybe7a9592017-12-29 02:39:53 -0500344 fn_token: fn_,
David Tolnay8875fca2017-12-31 13:52:37 -0500345 paren_token: parens.0,
346 inputs: (parens.1).0,
Michael Layzell92639a52017-06-01 00:07:44 -0400347 })
348 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800349
350 fn description() -> Option<&'static str> {
351 Some("`fn` type")
352 }
Alex Crichton954046c2017-05-30 21:49:42 -0700353 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700354
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800355 impl Synom for TypeNever {
Michael Layzell92639a52017-06-01 00:07:44 -0400356 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800357 punct!(!),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800358 |b| TypeNever { bang_token: b }
Michael Layzell92639a52017-06-01 00:07:44 -0400359 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800360
361 fn description() -> Option<&'static str> {
362 Some("never type: `!`")
363 }
Alex Crichton954046c2017-05-30 21:49:42 -0700364 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700365
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800366 impl Synom for TypeInfer {
Alex Crichton23a15f62017-08-28 12:34:23 -0700367 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800368 punct!(_),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800369 |u| TypeInfer { underscore_token: u }
Alex Crichton23a15f62017-08-28 12:34:23 -0700370 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800371
372 fn description() -> Option<&'static str> {
373 Some("inferred type: `_`")
374 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700375 }
376
David Tolnay05362582017-12-26 01:33:57 -0500377 impl Synom for TypeTuple {
Michael Layzell92639a52017-06-01 00:07:44 -0400378 named!(parse -> Self, do_parse!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500379 data: parens!(Punctuated::parse_terminated) >>
David Tolnay05362582017-12-26 01:33:57 -0500380 (TypeTuple {
David Tolnay8875fca2017-12-31 13:52:37 -0500381 paren_token: data.0,
382 elems: data.1,
Michael Layzell92639a52017-06-01 00:07:44 -0400383 })
384 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800385
386 fn description() -> Option<&'static str> {
387 Some("tuple type")
388 }
Alex Crichton954046c2017-05-30 21:49:42 -0700389 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700390
David Tolnay323279a2017-12-29 11:26:32 -0500391 impl Synom for TypeMacro {
392 named!(parse -> Self, map!(syn!(Macro), |mac| TypeMacro { mac: mac }));
David Tolnay79777332018-01-07 10:04:42 -0800393
394 fn description() -> Option<&'static str> {
395 Some("macro invocation")
396 }
David Tolnay323279a2017-12-29 11:26:32 -0500397 }
398
David Tolnay0a169d42017-12-29 17:57:29 -0500399 impl Synom for TypePath {
400 named!(parse -> Self, call!(Self::parse, false));
David Tolnay79777332018-01-07 10:04:42 -0800401
402 fn description() -> Option<&'static str> {
403 Some("type path")
404 }
David Tolnay0a169d42017-12-29 17:57:29 -0500405 }
406
David Tolnay7d38c7e2017-12-25 22:31:50 -0500407 impl TypePath {
408 named!(parse(allow_plus: bool) -> Self, do_parse!(
409 qpath: qpath >>
David Tolnay660fd1f2017-12-31 01:52:57 -0500410 parenthesized: option!(cond_reduce!(
David Tolnay56080682018-01-06 14:01:52 -0800411 qpath.1.segments.last().unwrap().value().arguments.is_empty(),
David Tolnay660fd1f2017-12-31 01:52:57 -0500412 syn!(ParenthesizedGenericArguments)
413 )) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500414 cond!(allow_plus, not!(punct!(+))) >>
David Tolnay7d38c7e2017-12-25 22:31:50 -0500415 ({
416 let (qself, mut path) = qpath;
David Tolnay660fd1f2017-12-31 01:52:57 -0500417 if let Some(parenthesized) = parenthesized {
David Tolnay7d38c7e2017-12-25 22:31:50 -0500418 let parenthesized = PathArguments::Parenthesized(parenthesized);
David Tolnay56080682018-01-06 14:01:52 -0800419 path.segments.last_mut().unwrap().value_mut().arguments = parenthesized;
David Tolnay7d38c7e2017-12-25 22:31:50 -0500420 }
421 TypePath { qself: qself, path: path }
422 })
423 ));
424 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700425
David Tolnayf93b90d2017-11-11 19:21:26 -0800426 impl Synom for ReturnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400427 named!(parse -> Self, alt!(
428 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800429 arrow: punct!(->) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800430 ty: syn!(Type) >>
David Tolnay4a3f59a2017-12-28 21:21:12 -0500431 (ReturnType::Type(arrow, Box::new(ty)))
Michael Layzell92639a52017-06-01 00:07:44 -0400432 )
433 |
David Tolnayf93b90d2017-11-11 19:21:26 -0800434 epsilon!() => { |_| ReturnType::Default }
Michael Layzell92639a52017-06-01 00:07:44 -0400435 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800436
437 fn description() -> Option<&'static str> {
438 Some("return type")
439 }
Alex Crichton954046c2017-05-30 21:49:42 -0700440 }
441
David Tolnay0a169d42017-12-29 17:57:29 -0500442 impl Synom for TypeTraitObject {
443 named!(parse -> Self, call!(Self::parse, true));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800444
445 fn description() -> Option<&'static str> {
446 Some("trait object type")
447 }
David Tolnay0a169d42017-12-29 17:57:29 -0500448 }
449
David Tolnay7d38c7e2017-12-25 22:31:50 -0500450 impl TypeTraitObject {
David Tolnay0a169d42017-12-29 17:57:29 -0500451 named!(pub without_plus -> Self, call!(Self::parse, false));
452
David Tolnay7d38c7e2017-12-25 22:31:50 -0500453 // Only allow multiple trait references if allow_plus is true.
454 named!(parse(allow_plus: bool) -> Self, do_parse!(
455 dyn_token: option!(keyword!(dyn)) >>
456 bounds: alt!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500457 cond_reduce!(allow_plus, Punctuated::parse_terminated_nonempty)
David Tolnay7d38c7e2017-12-25 22:31:50 -0500458 |
David Tolnay660fd1f2017-12-31 01:52:57 -0500459 syn!(TypeParamBound) => {|x| {
David Tolnayf2cfd722017-12-31 18:02:51 -0500460 let mut bounds = Punctuated::new();
David Tolnay56080682018-01-06 14:01:52 -0800461 bounds.push_value(x);
David Tolnayf2cfd722017-12-31 18:02:51 -0500462 bounds
David Tolnay660fd1f2017-12-31 01:52:57 -0500463 }}
David Tolnay7d38c7e2017-12-25 22:31:50 -0500464 ) >>
465 (TypeTraitObject {
466 dyn_token: dyn_token,
467 bounds: bounds,
468 })
469 ));
470 }
David Tolnay6414da72016-10-08 00:55:17 -0700471
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800472 impl Synom for TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400473 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800474 impl_: keyword!(impl) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400475 // NOTE: rust-lang/rust#34511 includes discussion about whether or
476 // not + should be allowed in ImplTrait directly without ().
David Tolnayf2cfd722017-12-31 18:02:51 -0500477 elem: call!(Punctuated::parse_terminated_nonempty) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800478 (TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400479 impl_token: impl_,
480 bounds: elem,
481 })
482 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800483
484 fn description() -> Option<&'static str> {
485 Some("`impl Trait` type")
486 }
Alex Crichton954046c2017-05-30 21:49:42 -0700487 }
David Tolnayb79ee962016-09-04 09:39:20 -0700488
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800489 impl Synom for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400490 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800491 data: grouped!(syn!(Type)) >>
492 (TypeGroup {
David Tolnay8875fca2017-12-31 13:52:37 -0500493 group_token: data.0,
494 elem: Box::new(data.1),
Michael Layzell93c36282017-06-04 20:43:14 -0400495 })
496 ));
David Tolnay79777332018-01-07 10:04:42 -0800497
498 fn description() -> Option<&'static str> {
499 Some("type surrounded by invisible delimiters")
500 }
Michael Layzell93c36282017-06-04 20:43:14 -0400501 }
502
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800503 impl Synom for TypeParen {
David Tolnay0a169d42017-12-29 17:57:29 -0500504 named!(parse -> Self, call!(Self::parse, false));
David Tolnay79777332018-01-07 10:04:42 -0800505
506 fn description() -> Option<&'static str> {
507 Some("parenthesized type")
508 }
David Tolnay0a169d42017-12-29 17:57:29 -0500509 }
510
511 impl TypeParen {
512 named!(parse(allow_plus: bool) -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800513 data: parens!(syn!(Type)) >>
David Tolnaydc03aec2017-12-30 01:54:18 -0500514 cond!(allow_plus, not!(punct!(+))) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800515 (TypeParen {
David Tolnay8875fca2017-12-31 13:52:37 -0500516 paren_token: data.0,
517 elem: Box::new(data.1),
Michael Layzell92639a52017-06-01 00:07:44 -0400518 })
519 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700520 }
David Tolnayb79ee962016-09-04 09:39:20 -0700521
Alex Crichton954046c2017-05-30 21:49:42 -0700522 impl Synom for BareFnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400523 named!(parse -> Self, do_parse!(
524 name: option!(do_parse!(
Alex Crichton23a15f62017-08-28 12:34:23 -0700525 name: syn!(BareFnArgName) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800526 not!(punct!(::)) >>
527 colon: punct!(:) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400528 (name, colon)
529 )) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800530 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400531 (BareFnArg {
532 name: name,
533 ty: ty,
534 })
535 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800536
537 fn description() -> Option<&'static str> {
538 Some("function type argument")
539 }
Alex Crichton954046c2017-05-30 21:49:42 -0700540 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700541
Alex Crichton23a15f62017-08-28 12:34:23 -0700542 impl Synom for BareFnArgName {
543 named!(parse -> Self, alt!(
544 map!(syn!(Ident), BareFnArgName::Named)
545 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800546 map!(punct!(_), BareFnArgName::Wild)
Alex Crichton23a15f62017-08-28 12:34:23 -0700547 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800548
549 fn description() -> Option<&'static str> {
550 Some("function argument name")
551 }
Alex Crichton23a15f62017-08-28 12:34:23 -0700552 }
553
Alex Crichton954046c2017-05-30 21:49:42 -0700554 impl Synom for Abi {
Michael Layzell92639a52017-06-01 00:07:44 -0400555 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800556 extern_: keyword!(extern) >>
David Tolnayf01e37b2018-01-06 23:38:26 -0800557 name: option!(syn!(LitStr)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400558 (Abi {
559 extern_token: extern_,
David Tolnayd5125762017-12-29 02:42:17 -0500560 name: name,
Michael Layzell92639a52017-06-01 00:07:44 -0400561 })
562 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800563
564 fn description() -> Option<&'static str> {
David Tolnay79777332018-01-07 10:04:42 -0800565 Some("`extern` ABI qualifier")
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800566 }
Alex Crichton954046c2017-05-30 21:49:42 -0700567 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700568}
David Tolnay87d0b442016-09-04 11:52:12 -0700569
570#[cfg(feature = "printing")]
571mod printing {
572 use super::*;
David Tolnay51382052017-12-27 13:46:21 -0500573 use quote::{ToTokens, Tokens};
David Tolnay87d0b442016-09-04 11:52:12 -0700574
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800575 impl ToTokens for TypeSlice {
David Tolnay87d0b442016-09-04 11:52:12 -0700576 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700577 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500578 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700579 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700580 }
581 }
582
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800583 impl ToTokens for TypeArray {
Alex Crichton62a0a592017-05-22 13:58:53 -0700584 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700585 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500586 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700587 self.semi_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500588 self.len.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700589 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700590 }
591 }
592
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800593 impl ToTokens for TypePtr {
Alex Crichton62a0a592017-05-22 13:58:53 -0700594 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700595 self.star_token.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500596 match self.mutability {
David Tolnay24237fb2017-12-29 02:15:26 -0500597 Some(ref tok) => tok.to_tokens(tokens),
598 None => {
Alex Crichton259ee532017-07-14 06:51:02 -0700599 TokensOrDefault(&self.const_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400600 }
601 }
David Tolnay136aaa32017-12-29 02:37:36 -0500602 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700603 }
604 }
605
David Tolnay0a89b4d2017-11-13 00:55:45 -0800606 impl ToTokens for TypeReference {
Alex Crichton62a0a592017-05-22 13:58:53 -0700607 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700608 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700609 self.lifetime.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500610 self.mutability.to_tokens(tokens);
611 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700612 }
613 }
614
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800615 impl ToTokens for TypeBareFn {
Alex Crichton62a0a592017-05-22 13:58:53 -0700616 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaybe7a9592017-12-29 02:39:53 -0500617 self.lifetimes.to_tokens(tokens);
618 self.unsafety.to_tokens(tokens);
619 self.abi.to_tokens(tokens);
620 self.fn_token.to_tokens(tokens);
621 self.paren_token.surround(tokens, |tokens| {
622 self.inputs.to_tokens(tokens);
623 if let Some(ref variadic) = self.variadic {
624 if !self.inputs.empty_or_trailing() {
625 let span = variadic.0[0];
626 <Token![,]>::new(span).to_tokens(tokens);
627 }
628 variadic.to_tokens(tokens);
629 }
630 });
631 self.output.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700632 }
633 }
634
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800635 impl ToTokens for TypeNever {
Alex Crichton62a0a592017-05-22 13:58:53 -0700636 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700637 self.bang_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700638 }
639 }
640
David Tolnay05362582017-12-26 01:33:57 -0500641 impl ToTokens for TypeTuple {
Alex Crichton62a0a592017-05-22 13:58:53 -0700642 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700643 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500644 self.elems.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700645 })
Alex Crichton62a0a592017-05-22 13:58:53 -0700646 }
647 }
648
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800649 impl ToTokens for TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -0700650 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700651 PathTokens(&self.qself, &self.path).to_tokens(tokens);
652 }
653 }
654
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800655 impl ToTokens for TypeTraitObject {
Alex Crichton62a0a592017-05-22 13:58:53 -0700656 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaye45b59f2017-12-25 18:44:49 -0500657 self.dyn_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700658 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700659 }
660 }
661
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800662 impl ToTokens for TypeImplTrait {
Alex Crichton62a0a592017-05-22 13:58:53 -0700663 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700664 self.impl_token.to_tokens(tokens);
665 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700666 }
667 }
668
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800669 impl ToTokens for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400670 fn to_tokens(&self, tokens: &mut Tokens) {
671 self.group_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500672 self.elem.to_tokens(tokens);
Michael Layzell93c36282017-06-04 20:43:14 -0400673 });
674 }
675 }
676
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800677 impl ToTokens for TypeParen {
Alex Crichton62a0a592017-05-22 13:58:53 -0700678 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700679 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500680 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700681 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700682 }
683 }
684
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800685 impl ToTokens for TypeInfer {
Alex Crichton62a0a592017-05-22 13:58:53 -0700686 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700687 self.underscore_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700688 }
689 }
690
David Tolnay323279a2017-12-29 11:26:32 -0500691 impl ToTokens for TypeMacro {
692 fn to_tokens(&self, tokens: &mut Tokens) {
693 self.mac.to_tokens(tokens);
694 }
695 }
696
David Tolnay2ae520a2017-12-29 11:19:50 -0500697 impl ToTokens for TypeVerbatim {
698 fn to_tokens(&self, tokens: &mut Tokens) {
699 self.tts.to_tokens(tokens);
700 }
701 }
702
David Tolnayf93b90d2017-11-11 19:21:26 -0800703 impl ToTokens for ReturnType {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700704 fn to_tokens(&self, tokens: &mut Tokens) {
705 match *self {
David Tolnayf93b90d2017-11-11 19:21:26 -0800706 ReturnType::Default => {}
David Tolnay4a3f59a2017-12-28 21:21:12 -0500707 ReturnType::Type(ref arrow, ref ty) => {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700708 arrow.to_tokens(tokens);
709 ty.to_tokens(tokens);
710 }
David Tolnay87d0b442016-09-04 11:52:12 -0700711 }
712 }
713 }
714
David Tolnay62f374c2016-10-02 13:37:00 -0700715 impl ToTokens for BareFnArg {
David Tolnay42602292016-10-01 22:25:45 -0700716 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700717 if let Some((ref name, ref colon)) = self.name {
David Tolnay62f374c2016-10-02 13:37:00 -0700718 name.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700719 colon.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -0700720 }
721 self.ty.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700722 }
723 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700724
Alex Crichton23a15f62017-08-28 12:34:23 -0700725 impl ToTokens for BareFnArgName {
726 fn to_tokens(&self, tokens: &mut Tokens) {
727 match *self {
728 BareFnArgName::Named(ref t) => t.to_tokens(tokens),
729 BareFnArgName::Wild(ref t) => t.to_tokens(tokens),
730 }
731 }
732 }
733
David Tolnayb8d8ef52016-10-29 14:30:08 -0700734 impl ToTokens for Abi {
735 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700736 self.extern_token.to_tokens(tokens);
David Tolnayd5125762017-12-29 02:42:17 -0500737 self.name.to_tokens(tokens);
David Tolnayb8d8ef52016-10-29 14:30:08 -0700738 }
739 }
David Tolnay87d0b442016-09-04 11:52:12 -0700740}