blob: 4f4047eec890be4e42a725be1dce80cc27737536 [file] [log] [blame]
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001use delimited::Delimited;
David Tolnayb79ee962016-09-04 09:39:20 -07002use super::*;
David Tolnay2ae520a2017-12-29 11:19:50 -05003use proc_macro2::TokenStream;
4#[cfg(feature = "extra-traits")]
5use std::hash::{Hash, Hasher};
6#[cfg(feature = "extra-traits")]
7use mac::TokenStreamHelper;
David Tolnayb79ee962016-09-04 09:39:20 -07008
Alex Crichton62a0a592017-05-22 13:58:53 -07009ast_enum_of_structs! {
10 /// The different kinds of types recognized by the compiler
David Tolnayfd6bf5c2017-11-12 09:41:14 -080011 pub enum Type {
Alex Crichton62a0a592017-05-22 13:58:53 -070012 /// A variable-length array (`[T]`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080013 pub Slice(TypeSlice {
David Tolnay32954ef2017-12-26 22:43:16 -050014 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050015 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070016 }),
17 /// A fixed length array (`[T; n]`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080018 pub Array(TypeArray {
David Tolnay32954ef2017-12-26 22:43:16 -050019 pub bracket_token: token::Bracket,
David Tolnayeadbda32017-12-29 02:33:47 -050020 pub elem: Box<Type>,
David Tolnayf8db7ba2017-11-11 22:52:16 -080021 pub semi_token: Token![;],
David Tolnayeadbda32017-12-29 02:33:47 -050022 pub len: Expr,
Alex Crichton62a0a592017-05-22 13:58:53 -070023 }),
24 /// A raw pointer (`*const T` or `*mut T`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080025 pub Ptr(TypePtr {
David Tolnayf8db7ba2017-11-11 22:52:16 -080026 pub star_token: Token![*],
27 pub const_token: Option<Token![const]>,
David Tolnay136aaa32017-12-29 02:37:36 -050028 pub mutability: Option<Token![mut]>,
29 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070030 }),
31 /// A reference (`&'a T` or `&'a mut T`)
David Tolnay0a89b4d2017-11-13 00:55:45 -080032 pub Reference(TypeReference {
David Tolnayf8db7ba2017-11-11 22:52:16 -080033 pub and_token: Token![&],
Alex Crichton62a0a592017-05-22 13:58:53 -070034 pub lifetime: Option<Lifetime>,
David Tolnay136aaa32017-12-29 02:37:36 -050035 pub mutability: Option<Token![mut]>,
36 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070037 }),
38 /// A bare function (e.g. `fn(usize) -> bool`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080039 pub BareFn(TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -050040 pub unsafety: Option<Token![unsafe]>,
41 pub abi: Option<Abi>,
42 pub fn_token: Token![fn],
43 pub lifetimes: Option<BoundLifetimes>,
44 pub paren_token: token::Paren,
45 pub inputs: Delimited<BareFnArg, Token![,]>,
46 pub variadic: Option<Token![...]>,
47 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -070048 }),
49 /// The never type (`!`)
David Tolnayfd6bf5c2017-11-12 09:41:14 -080050 pub Never(TypeNever {
David Tolnayf8db7ba2017-11-11 22:52:16 -080051 pub bang_token: Token![!],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070052 }),
Alex Crichton62a0a592017-05-22 13:58:53 -070053 /// A tuple (`(A, B, C, D, ...)`)
David Tolnay05362582017-12-26 01:33:57 -050054 pub Tuple(TypeTuple {
David Tolnay32954ef2017-12-26 22:43:16 -050055 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050056 pub elems: Delimited<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070057 }),
58 /// A path (`module::module::...::Type`), optionally
59 /// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
60 ///
Nika Layzellc08227a2017-12-04 16:30:17 -050061 /// Type arguments are stored in the Path itself
David Tolnayfd6bf5c2017-11-12 09:41:14 -080062 pub Path(TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -070063 pub qself: Option<QSelf>,
64 pub path: Path,
65 }),
66 /// A trait object type `Bound1 + Bound2 + Bound3`
67 /// where `Bound` is a trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080068 pub TraitObject(TypeTraitObject {
David Tolnaye45b59f2017-12-25 18:44:49 -050069 pub dyn_token: Option<Token![dyn]>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -080070 pub bounds: Delimited<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070071 }),
72 /// An `impl Bound1 + Bound2 + Bound3` type
73 /// where `Bound` is a trait or a lifetime.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080074 pub ImplTrait(TypeImplTrait {
David Tolnayf8db7ba2017-11-11 22:52:16 -080075 pub impl_token: Token![impl],
David Tolnayfd6bf5c2017-11-12 09:41:14 -080076 pub bounds: Delimited<TypeParamBound, Token![+]>,
Alex Crichton62a0a592017-05-22 13:58:53 -070077 }),
78 /// No-op; kept solely so that we can pretty-print faithfully
David Tolnayfd6bf5c2017-11-12 09:41:14 -080079 pub Paren(TypeParen {
David Tolnay32954ef2017-12-26 22:43:16 -050080 pub paren_token: token::Paren,
David Tolnayeadbda32017-12-29 02:33:47 -050081 pub elem: Box<Type>,
Alex Crichton62a0a592017-05-22 13:58:53 -070082 }),
Michael Layzell93c36282017-06-04 20:43:14 -040083 /// No-op: kept solely so that we can pretty-print faithfully
David Tolnayfd6bf5c2017-11-12 09:41:14 -080084 pub Group(TypeGroup {
David Tolnay32954ef2017-12-26 22:43:16 -050085 pub group_token: token::Group,
David Tolnayeadbda32017-12-29 02:33:47 -050086 pub elem: Box<Type>,
Michael Layzell93c36282017-06-04 20:43:14 -040087 }),
David Tolnayfd6bf5c2017-11-12 09:41:14 -080088 /// TypeKind::Infer means the type should be inferred instead of it having been
Alex Crichton62a0a592017-05-22 13:58:53 -070089 /// specified. This can appear anywhere in a type.
David Tolnayfd6bf5c2017-11-12 09:41:14 -080090 pub Infer(TypeInfer {
David Tolnayf8db7ba2017-11-11 22:52:16 -080091 pub underscore_token: Token![_],
Alex Crichtonccbb45d2017-05-23 10:58:24 -070092 }),
Alex Crichton62a0a592017-05-22 13:58:53 -070093 /// A macro in the type position.
David Tolnay323279a2017-12-29 11:26:32 -050094 pub Macro(TypeMacro {
95 pub mac: Macro,
96 }),
David Tolnay2ae520a2017-12-29 11:19:50 -050097 pub Verbatim(TypeVerbatim #manual_extra_traits {
98 pub tts: TokenStream,
99 }),
100 }
101}
102
103#[cfg(feature = "extra-traits")]
104impl Eq for TypeVerbatim {}
105
106#[cfg(feature = "extra-traits")]
107impl PartialEq for TypeVerbatim {
108 fn eq(&self, other: &Self) -> bool {
109 TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
110 }
111}
112
113#[cfg(feature = "extra-traits")]
114impl Hash for TypeVerbatim {
115 fn hash<H>(&self, state: &mut H)
116 where
117 H: Hasher,
118 {
119 TokenStreamHelper(&self.tts).hash(state);
Alex Crichton62a0a592017-05-22 13:58:53 -0700120 }
121}
122
123ast_struct! {
Alex Crichton62a0a592017-05-22 13:58:53 -0700124 /// A "Path" is essentially Rust's notion of a name.
David Tolnayb79ee962016-09-04 09:39:20 -0700125 ///
Alex Crichton62a0a592017-05-22 13:58:53 -0700126 /// It's represented as a sequence of identifiers,
127 /// along with a bunch of supporting information.
128 ///
129 /// E.g. `std::cmp::PartialEq`
130 pub struct Path {
131 /// A `::foo` path, is relative to the crate root rather than current
132 /// module (like paths in an import).
David Tolnayf8db7ba2017-11-11 22:52:16 -0800133 pub leading_colon: Option<Token![::]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700134 /// The segments in the path: the things separated by `::`.
David Tolnayf8db7ba2017-11-11 22:52:16 -0800135 pub segments: Delimited<PathSegment, Token![::]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700136 }
David Tolnayb79ee962016-09-04 09:39:20 -0700137}
138
David Tolnay570695e2017-06-03 16:15:13 -0700139impl Path {
140 pub fn global(&self) -> bool {
141 self.leading_colon.is_some()
142 }
143}
144
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700145#[cfg(feature = "printing")]
Nika Layzell6b38b132017-10-24 23:09:39 -0400146#[cfg_attr(feature = "extra-traits", derive(Debug, Eq, PartialEq, Hash))]
147#[cfg_attr(feature = "clone-impls", derive(Clone))]
148pub struct PathTokens<'a>(pub &'a Option<QSelf>, pub &'a Path);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700149
David Tolnaydaaf7742016-10-03 11:11:43 -0700150impl<T> From<T> for Path
David Tolnay51382052017-12-27 13:46:21 -0500151where
152 T: Into<PathSegment>,
David Tolnaydaaf7742016-10-03 11:11:43 -0700153{
David Tolnay84aa0752016-10-02 23:01:13 -0700154 fn from(segment: T) -> Self {
155 Path {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700156 leading_colon: None,
157 segments: vec![(segment.into(), None)].into(),
David Tolnay84aa0752016-10-02 23:01:13 -0700158 }
159 }
160}
161
Alex Crichton62a0a592017-05-22 13:58:53 -0700162ast_struct! {
163 /// A segment of a path: an identifier, an optional lifetime, and a set of types.
164 ///
165 /// E.g. `std`, `String` or `Box<T>`
166 pub struct PathSegment {
167 /// The identifier portion of this path segment.
168 pub ident: Ident,
Nika Layzellc08227a2017-12-04 16:30:17 -0500169 /// Type/lifetime arguments attached to this path. They come in
Alex Crichton62a0a592017-05-22 13:58:53 -0700170 /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
171 /// this is more than just simple syntactic sugar; the use of
172 /// parens affects the region binding rules, so we preserve the
173 /// distinction.
Nika Layzellc08227a2017-12-04 16:30:17 -0500174 pub arguments: PathArguments,
Alex Crichton62a0a592017-05-22 13:58:53 -0700175 }
David Tolnayb79ee962016-09-04 09:39:20 -0700176}
177
David Tolnaydaaf7742016-10-03 11:11:43 -0700178impl<T> From<T> for PathSegment
David Tolnay51382052017-12-27 13:46:21 -0500179where
180 T: Into<Ident>,
David Tolnaydaaf7742016-10-03 11:11:43 -0700181{
David Tolnay84aa0752016-10-02 23:01:13 -0700182 fn from(ident: T) -> Self {
David Tolnayb79ee962016-09-04 09:39:20 -0700183 PathSegment {
David Tolnay84aa0752016-10-02 23:01:13 -0700184 ident: ident.into(),
Nika Layzellc08227a2017-12-04 16:30:17 -0500185 arguments: PathArguments::None,
David Tolnayb79ee962016-09-04 09:39:20 -0700186 }
187 }
188}
189
Alex Crichton62a0a592017-05-22 13:58:53 -0700190ast_enum! {
Nika Layzellc08227a2017-12-04 16:30:17 -0500191 /// Arguments of a path segment.
Alex Crichton62a0a592017-05-22 13:58:53 -0700192 ///
193 /// E.g. `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`
Nika Layzellc08227a2017-12-04 16:30:17 -0500194 pub enum PathArguments {
David Tolnay570695e2017-06-03 16:15:13 -0700195 None,
Alex Crichton62a0a592017-05-22 13:58:53 -0700196 /// The `<'a, A, B, C>` in `foo::bar::baz::<'a, A, B, C>`
Nika Layzellc08227a2017-12-04 16:30:17 -0500197 AngleBracketed(AngleBracketedGenericArguments),
Alex Crichton62a0a592017-05-22 13:58:53 -0700198 /// The `(A, B)` and `C` in `Foo(A, B) -> C`
Nika Layzellc08227a2017-12-04 16:30:17 -0500199 Parenthesized(ParenthesizedGenericArguments),
Alex Crichton62a0a592017-05-22 13:58:53 -0700200 }
David Tolnayb79ee962016-09-04 09:39:20 -0700201}
202
Nika Layzellc08227a2017-12-04 16:30:17 -0500203impl Default for PathArguments {
David Tolnay570695e2017-06-03 16:15:13 -0700204 fn default() -> Self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500205 PathArguments::None
David Tolnayb79ee962016-09-04 09:39:20 -0700206 }
David Tolnay570695e2017-06-03 16:15:13 -0700207}
David Tolnay5332d4b2016-10-30 14:25:22 -0700208
Nika Layzellc08227a2017-12-04 16:30:17 -0500209impl PathArguments {
David Tolnay5332d4b2016-10-30 14:25:22 -0700210 pub fn is_empty(&self) -> bool {
211 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -0500212 PathArguments::None => true,
213 PathArguments::AngleBracketed(ref bracketed) => bracketed.args.is_empty(),
214 PathArguments::Parenthesized(_) => false,
David Tolnay5332d4b2016-10-30 14:25:22 -0700215 }
216 }
David Tolnayb79ee962016-09-04 09:39:20 -0700217}
218
Nika Layzell357885a2017-12-04 15:47:07 -0500219ast_enum! {
220 /// A individual generic argument, like `'a`, `T`, or `Item=T`.
Nika Layzellc08227a2017-12-04 16:30:17 -0500221 pub enum GenericArgument {
Nika Layzell357885a2017-12-04 15:47:07 -0500222 /// The lifetime parameters for this path segment.
223 Lifetime(Lifetime),
224 /// The type parameters for this path segment, if present.
225 Type(Type),
226 /// Bindings (equality constraints) on associated types, if present.
227 ///
228 /// E.g., `Foo<A=Bar>`.
David Tolnay506e43a2017-12-29 11:34:36 -0500229 Binding(Binding),
Nika Layzellc680e612017-12-04 19:07:20 -0500230 /// Const expression. Must be inside of a block.
231 ///
232 /// NOTE: Identity expressions are represented as Type arguments, as
233 /// they are indistinguishable syntactically.
Nika Layzellce37f332017-12-05 12:01:22 -0500234 Const(Expr),
Nika Layzell357885a2017-12-04 15:47:07 -0500235 }
236}
237
Alex Crichton62a0a592017-05-22 13:58:53 -0700238ast_struct! {
239 /// A path like `Foo<'a, T>`
Nika Layzellc08227a2017-12-04 16:30:17 -0500240 pub struct AngleBracketedGenericArguments {
David Tolnay2d4e08a2017-12-28 23:54:07 -0500241 pub colon2_token: Option<Token![::]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800242 pub lt_token: Token![<],
Nika Layzellc08227a2017-12-04 16:30:17 -0500243 pub args: Delimited<GenericArgument, Token![,]>,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800244 pub gt_token: Token![>],
Alex Crichton62a0a592017-05-22 13:58:53 -0700245 }
246}
247
248ast_struct! {
249 /// Bind a type to an associated type: `A=Foo`.
David Tolnay506e43a2017-12-29 11:34:36 -0500250 pub struct Binding {
Alex Crichton62a0a592017-05-22 13:58:53 -0700251 pub ident: Ident,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800252 pub eq_token: Token![=],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800253 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700254 }
255}
256
Alex Crichton62a0a592017-05-22 13:58:53 -0700257ast_struct! {
258 /// A path like `Foo(A,B) -> C`
Nika Layzellc08227a2017-12-04 16:30:17 -0500259 pub struct ParenthesizedGenericArguments {
David Tolnay32954ef2017-12-26 22:43:16 -0500260 pub paren_token: token::Paren,
Alex Crichton62a0a592017-05-22 13:58:53 -0700261 /// `(A, B)`
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800262 pub inputs: Delimited<Type, Token![,]>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700263 /// `C`
David Tolnayf93b90d2017-11-11 19:21:26 -0800264 pub output: ReturnType,
Alex Crichton62a0a592017-05-22 13:58:53 -0700265 }
266}
267
268ast_struct! {
269 pub struct PolyTraitRef {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700270 /// The `for<'a>` in `for<'a> Foo<&'a T>`
271 pub bound_lifetimes: Option<BoundLifetimes>,
David Tolnay7d38c7e2017-12-25 22:31:50 -0500272 /// The `Foo<&'a T>` in `for<'a> Foo<&'a T>`
Alex Crichton62a0a592017-05-22 13:58:53 -0700273 pub trait_ref: Path,
274 }
275}
276
277ast_struct! {
278 /// The explicit Self type in a "qualified path". The actual
279 /// path, including the trait and the associated item, is stored
280 /// separately. `position` represents the index of the associated
281 /// item qualified with this Self type.
David Tolnayb79ee962016-09-04 09:39:20 -0700282 ///
David Tolnaybcf26022017-12-25 22:10:52 -0500283 /// ```text
Alex Crichton62a0a592017-05-22 13:58:53 -0700284 /// <Vec<T> as a::b::Trait>::AssociatedItem
David Tolnaybcf26022017-12-25 22:10:52 -0500285 /// ^~~~~~ ~~~~~~~~~~~~~~^
Alex Crichton62a0a592017-05-22 13:58:53 -0700286 /// ty position = 3
David Tolnayb79ee962016-09-04 09:39:20 -0700287 ///
Alex Crichton62a0a592017-05-22 13:58:53 -0700288 /// <Vec<T>>::AssociatedItem
David Tolnaybcf26022017-12-25 22:10:52 -0500289 /// ^~~~~~ ^
Alex Crichton62a0a592017-05-22 13:58:53 -0700290 /// ty position = 0
291 /// ```
292 pub struct QSelf {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800293 pub lt_token: Token![<],
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800294 pub ty: Box<Type>,
Michael Layzell3936ceb2017-07-08 00:28:36 -0400295 pub position: usize,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800296 pub as_token: Option<Token![as]>,
297 pub gt_token: Token![>],
Alex Crichton62a0a592017-05-22 13:58:53 -0700298 }
299}
300
301ast_struct! {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700302 pub struct Abi {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800303 pub extern_token: Token![extern],
David Tolnayd5125762017-12-29 02:42:17 -0500304 pub name: Option<Lit>,
Alex Crichton62a0a592017-05-22 13:58:53 -0700305 }
306}
307
308ast_struct! {
309 /// An argument in a function type.
310 ///
311 /// E.g. `bar: usize` as in `fn foo(bar: usize)`
312 pub struct BareFnArg {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800313 pub name: Option<(BareFnArgName, Token![:])>,
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800314 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700315 }
316}
317
Alex Crichton23a15f62017-08-28 12:34:23 -0700318ast_enum! {
319 /// Names of arguments in the `BareFnArg` structure
320 pub enum BareFnArgName {
321 /// Argument with the provided name
322 Named(Ident),
323 /// Argument matched with `_`
David Tolnayf8db7ba2017-11-11 22:52:16 -0800324 Wild(Token![_]),
Alex Crichton23a15f62017-08-28 12:34:23 -0700325 }
326}
Alex Crichton62a0a592017-05-22 13:58:53 -0700327
328ast_enum! {
David Tolnayf93b90d2017-11-11 19:21:26 -0800329 pub enum ReturnType {
Alex Crichton62a0a592017-05-22 13:58:53 -0700330 /// Return type is not specified.
331 ///
332 /// Functions default to `()` and
333 /// closures default to inference. Span points to where return
334 /// type would be inserted.
335 Default,
336 /// Everything else
David Tolnay4a3f59a2017-12-28 21:21:12 -0500337 Type(Token![->], Box<Type>),
Alex Crichton62a0a592017-05-22 13:58:53 -0700338 }
David Tolnayb79ee962016-09-04 09:39:20 -0700339}
340
David Tolnay86eca752016-09-04 11:26:41 -0700341#[cfg(feature = "parsing")]
David Tolnay9d8f1972016-09-04 11:58:48 -0700342pub mod parsing {
343 use super::*;
Michael Layzell92639a52017-06-01 00:07:44 -0400344 use synom::Synom;
David Tolnayda4049b2016-09-04 10:59:23 -0700345
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800346 impl Synom for Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400347 named!(parse -> Self, call!(ambig_ty, true));
David Tolnayb79ee962016-09-04 09:39:20 -0700348
Alex Crichton954046c2017-05-30 21:49:42 -0700349 fn description() -> Option<&'static str> {
350 Some("type")
351 }
352 }
David Tolnay0047c712016-12-21 21:59:25 -0500353
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800354 impl Type {
Michael Layzell9bf2b002017-06-04 18:49:53 -0400355 /// In some positions, types may not contain the `+` character, to
356 /// disambiguate them. For example in the expression `1 as T`, T may not
357 /// contain a `+` character.
358 ///
359 /// This parser does not allow a `+`, while the default parser does.
Michael Layzell6a5a1642017-06-04 19:35:15 -0400360 named!(pub without_plus -> Self, call!(ambig_ty, false));
Michael Layzell9bf2b002017-06-04 18:49:53 -0400361 }
362
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800363 named!(ambig_ty(allow_plus: bool) -> Type, alt!(
364 syn!(TypeGroup) => { Type::Group }
Michael Layzell93c36282017-06-04 20:43:14 -0400365 |
David Tolnay05362582017-12-26 01:33:57 -0500366 // must be before TypeTuple
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800367 syn!(TypeParen) => { Type::Paren }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400368 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500369 // must be before TypePath
David Tolnay323279a2017-12-29 11:26:32 -0500370 syn!(TypeMacro) => { Type::Macro }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400371 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500372 // must be before TypeTraitObject
373 call!(TypePath::parse, allow_plus) => { Type::Path }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400374 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800375 syn!(TypeSlice) => { Type::Slice }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400376 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800377 syn!(TypeArray) => { Type::Array }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400378 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800379 syn!(TypePtr) => { Type::Ptr }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400380 |
David Tolnay0a89b4d2017-11-13 00:55:45 -0800381 syn!(TypeReference) => { Type::Reference }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400382 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800383 syn!(TypeBareFn) => { Type::BareFn }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400384 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800385 syn!(TypeNever) => { Type::Never }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400386 |
David Tolnay05362582017-12-26 01:33:57 -0500387 syn!(TypeTuple) => { Type::Tuple }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400388 |
David Tolnay7d38c7e2017-12-25 22:31:50 -0500389 // Don't try parsing more than one trait bound if we aren't allowing it
390 call!(TypeTraitObject::parse, allow_plus) => { Type::TraitObject }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400391 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800392 syn!(TypeImplTrait) => { Type::ImplTrait }
Alex Crichton23a15f62017-08-28 12:34:23 -0700393 |
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800394 syn!(TypeInfer) => { Type::Infer }
Michael Layzell9bf2b002017-06-04 18:49:53 -0400395 ));
396
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800397 impl Synom for TypeSlice {
Michael Layzell92639a52017-06-01 00:07:44 -0400398 named!(parse -> Self, map!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800399 brackets!(syn!(Type)),
400 |(ty, b)| TypeSlice {
David Tolnayeadbda32017-12-29 02:33:47 -0500401 elem: Box::new(ty),
Michael Layzell92639a52017-06-01 00:07:44 -0400402 bracket_token: b,
Alex Crichton954046c2017-05-30 21:49:42 -0700403 }
Michael Layzell92639a52017-06-01 00:07:44 -0400404 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700405 }
David Tolnayb79ee962016-09-04 09:39:20 -0700406
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800407 impl Synom for TypeArray {
Michael Layzell92639a52017-06-01 00:07:44 -0400408 named!(parse -> Self, map!(
409 brackets!(do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800410 elem: syn!(Type) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800411 semi: punct!(;) >>
Michael Layzelld7ee9102017-06-07 10:02:19 -0400412 len: syn!(Expr) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700413 (elem, semi, len)
Michael Layzell92639a52017-06-01 00:07:44 -0400414 )),
415 |((elem, semi, len), brackets)| {
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800416 TypeArray {
David Tolnayeadbda32017-12-29 02:33:47 -0500417 elem: Box::new(elem),
418 len: len,
Michael Layzell92639a52017-06-01 00:07:44 -0400419 bracket_token: brackets,
420 semi_token: semi,
Alex Crichton954046c2017-05-30 21:49:42 -0700421 }
422 }
Michael Layzell92639a52017-06-01 00:07:44 -0400423 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700424 }
David Tolnayfa94b6f2016-10-05 23:26:11 -0700425
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800426 impl Synom for TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400427 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800428 star: punct!(*) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400429 mutability: alt!(
David Tolnay24237fb2017-12-29 02:15:26 -0500430 keyword!(const) => { |c| (None, Some(c)) }
Michael Layzell92639a52017-06-01 00:07:44 -0400431 |
David Tolnay24237fb2017-12-29 02:15:26 -0500432 keyword!(mut) => { |m| (Some(m), None) }
Michael Layzell92639a52017-06-01 00:07:44 -0400433 ) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800434 target: call!(Type::without_plus) >>
435 (TypePtr {
Michael Layzell92639a52017-06-01 00:07:44 -0400436 const_token: mutability.1,
437 star_token: star,
David Tolnay136aaa32017-12-29 02:37:36 -0500438 mutability: mutability.0,
439 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400440 })
441 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700442 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700443
David Tolnay0a89b4d2017-11-13 00:55:45 -0800444 impl Synom for TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400445 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800446 amp: punct!(&) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400447 life: option!(syn!(Lifetime)) >>
David Tolnay24237fb2017-12-29 02:15:26 -0500448 mutability: option!(keyword!(mut)) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400449 // & binds tighter than +, so we don't allow + here.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800450 target: call!(Type::without_plus) >>
David Tolnay0a89b4d2017-11-13 00:55:45 -0800451 (TypeReference {
Michael Layzell92639a52017-06-01 00:07:44 -0400452 lifetime: life,
David Tolnay136aaa32017-12-29 02:37:36 -0500453 mutability: mutability,
454 elem: Box::new(target),
Michael Layzell92639a52017-06-01 00:07:44 -0400455 and_token: amp,
456 })
457 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700458 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700459
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800460 impl Synom for TypeBareFn {
Michael Layzell92639a52017-06-01 00:07:44 -0400461 named!(parse -> Self, do_parse!(
462 lifetimes: option!(syn!(BoundLifetimes)) >>
David Tolnay9b258702017-12-29 02:24:41 -0500463 unsafety: option!(keyword!(unsafe)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400464 abi: option!(syn!(Abi)) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800465 fn_: keyword!(fn) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400466 parens: parens!(do_parse!(
467 inputs: call!(Delimited::parse_terminated) >>
468 variadic: option!(cond_reduce!(inputs.is_empty() || inputs.trailing_delim(),
David Tolnayf8db7ba2017-11-11 22:52:16 -0800469 punct!(...))) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400470 (inputs, variadic)
471 )) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800472 output: syn!(ReturnType) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800473 (TypeBareFn {
David Tolnaybe7a9592017-12-29 02:39:53 -0500474 unsafety: unsafety,
475 abi: abi,
476 lifetimes: lifetimes,
477 output: output,
478 variadic: (parens.0).1,
479 fn_token: fn_,
480 paren_token: parens.1,
481 inputs: (parens.0).0,
Michael Layzell92639a52017-06-01 00:07:44 -0400482 })
483 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700484 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700485
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800486 impl Synom for TypeNever {
Michael Layzell92639a52017-06-01 00:07:44 -0400487 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800488 punct!(!),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800489 |b| TypeNever { bang_token: b }
Michael Layzell92639a52017-06-01 00:07:44 -0400490 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700491 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700492
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800493 impl Synom for TypeInfer {
Alex Crichton23a15f62017-08-28 12:34:23 -0700494 named!(parse -> Self, map!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800495 punct!(_),
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800496 |u| TypeInfer { underscore_token: u }
Alex Crichton23a15f62017-08-28 12:34:23 -0700497 ));
498 }
499
David Tolnay05362582017-12-26 01:33:57 -0500500 impl Synom for TypeTuple {
Michael Layzell92639a52017-06-01 00:07:44 -0400501 named!(parse -> Self, do_parse!(
502 data: parens!(call!(Delimited::parse_terminated)) >>
David Tolnay05362582017-12-26 01:33:57 -0500503 (TypeTuple {
David Tolnayeadbda32017-12-29 02:33:47 -0500504 elems: data.0,
Michael Layzell92639a52017-06-01 00:07:44 -0400505 paren_token: data.1,
Michael Layzell92639a52017-06-01 00:07:44 -0400506 })
507 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700508 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700509
David Tolnay323279a2017-12-29 11:26:32 -0500510 impl Synom for TypeMacro {
511 named!(parse -> Self, map!(syn!(Macro), |mac| TypeMacro { mac: mac }));
512 }
513
David Tolnay7d38c7e2017-12-25 22:31:50 -0500514 impl TypePath {
515 named!(parse(allow_plus: bool) -> Self, do_parse!(
516 qpath: qpath >>
517 parenthesized: cond!(
518 qpath.1.segments.last().unwrap().item().arguments.is_empty(),
519 option!(syn!(ParenthesizedGenericArguments))
520 ) >>
521 cond!(allow_plus, not!(peek!(punct!(+)))) >>
522 ({
523 let (qself, mut path) = qpath;
524 if let Some(Some(parenthesized)) = parenthesized {
525 let parenthesized = PathArguments::Parenthesized(parenthesized);
526 path.segments.last_mut().unwrap().item_mut().arguments = parenthesized;
527 }
528 TypePath { qself: qself, path: path }
529 })
530 ));
531 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700532
David Tolnay9636c052016-10-02 17:11:17 -0700533 named!(pub qpath -> (Option<QSelf>, Path), alt!(
Alex Crichton954046c2017-05-30 21:49:42 -0700534 map!(syn!(Path), |p| (None, p))
David Tolnay9636c052016-10-02 17:11:17 -0700535 |
536 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800537 lt: punct!(<) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800538 this: syn!(Type) >>
David Tolnay7d38c7e2017-12-25 22:31:50 -0500539 path: option!(tuple!(keyword!(as), syn!(Path))) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800540 gt: punct!(>) >>
541 colon2: punct!(::) >>
Alex Crichton954046c2017-05-30 21:49:42 -0700542 rest: call!(Delimited::parse_separated_nonempty) >>
David Tolnay9636c052016-10-02 17:11:17 -0700543 ({
Michael Layzell3936ceb2017-07-08 00:28:36 -0400544 let (pos, as_, path) = match path {
Alex Crichton954046c2017-05-30 21:49:42 -0700545 Some((as_, mut path)) => {
David Tolnay9636c052016-10-02 17:11:17 -0700546 let pos = path.segments.len();
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700547 if !path.segments.is_empty() && !path.segments.trailing_delim() {
Alex Crichton954046c2017-05-30 21:49:42 -0700548 path.segments.push_trailing(colon2);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700549 }
Alex Crichton954046c2017-05-30 21:49:42 -0700550 for item in rest {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700551 path.segments.push(item);
552 }
Michael Layzell3936ceb2017-07-08 00:28:36 -0400553 (pos, Some(as_), path)
David Tolnay9636c052016-10-02 17:11:17 -0700554 }
555 None => {
Michael Layzell3936ceb2017-07-08 00:28:36 -0400556 (0, None, Path {
David Tolnay570695e2017-06-03 16:15:13 -0700557 leading_colon: Some(colon2),
David Tolnay9636c052016-10-02 17:11:17 -0700558 segments: rest,
David Tolnay570695e2017-06-03 16:15:13 -0700559 })
David Tolnay9636c052016-10-02 17:11:17 -0700560 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700561 };
562 (Some(QSelf {
David Tolnay570695e2017-06-03 16:15:13 -0700563 lt_token: lt,
564 ty: Box::new(this),
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700565 position: pos,
Michael Layzell3936ceb2017-07-08 00:28:36 -0400566 as_token: as_,
Alex Crichton954046c2017-05-30 21:49:42 -0700567 gt_token: gt,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700568 }), path)
David Tolnay9636c052016-10-02 17:11:17 -0700569 })
570 )
David Tolnay6cd2a232016-10-24 22:41:08 -0700571 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800572 map!(keyword!(self), |s| (None, s.into()))
David Tolnay9d8f1972016-09-04 11:58:48 -0700573 ));
David Tolnayb79ee962016-09-04 09:39:20 -0700574
Nika Layzellc08227a2017-12-04 16:30:17 -0500575 impl Synom for ParenthesizedGenericArguments {
Michael Layzell92639a52017-06-01 00:07:44 -0400576 named!(parse -> Self, do_parse!(
577 data: parens!(call!(Delimited::parse_terminated)) >>
David Tolnayf93b90d2017-11-11 19:21:26 -0800578 output: syn!(ReturnType) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500579 (ParenthesizedGenericArguments {
Michael Layzell92639a52017-06-01 00:07:44 -0400580 paren_token: data.1,
581 inputs: data.0,
582 output: output,
583 })
584 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700585 }
586
David Tolnayf93b90d2017-11-11 19:21:26 -0800587 impl Synom for ReturnType {
Michael Layzell92639a52017-06-01 00:07:44 -0400588 named!(parse -> Self, alt!(
589 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800590 arrow: punct!(->) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800591 ty: syn!(Type) >>
David Tolnay4a3f59a2017-12-28 21:21:12 -0500592 (ReturnType::Type(arrow, Box::new(ty)))
Michael Layzell92639a52017-06-01 00:07:44 -0400593 )
594 |
David Tolnayf93b90d2017-11-11 19:21:26 -0800595 epsilon!() => { |_| ReturnType::Default }
Michael Layzell92639a52017-06-01 00:07:44 -0400596 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700597 }
598
David Tolnay7d38c7e2017-12-25 22:31:50 -0500599 impl TypeTraitObject {
600 // Only allow multiple trait references if allow_plus is true.
601 named!(parse(allow_plus: bool) -> Self, do_parse!(
602 dyn_token: option!(keyword!(dyn)) >>
603 bounds: alt!(
604 cond_reduce!(allow_plus, call!(Delimited::parse_terminated_nonempty))
605 |
606 syn!(TypeParamBound) => { |x| vec![x].into() }
607 ) >>
608 (TypeTraitObject {
609 dyn_token: dyn_token,
610 bounds: bounds,
611 })
612 ));
613 }
David Tolnay6414da72016-10-08 00:55:17 -0700614
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800615 impl Synom for TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400616 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800617 impl_: keyword!(impl) >>
Michael Layzell9bf2b002017-06-04 18:49:53 -0400618 // NOTE: rust-lang/rust#34511 includes discussion about whether or
619 // not + should be allowed in ImplTrait directly without ().
Nika Layzellb49a9e52017-12-05 13:31:52 -0500620 elem: call!(Delimited::parse_terminated_nonempty) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800621 (TypeImplTrait {
Michael Layzell92639a52017-06-01 00:07:44 -0400622 impl_token: impl_,
623 bounds: elem,
624 })
625 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700626 }
David Tolnayb79ee962016-09-04 09:39:20 -0700627
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800628 impl Synom for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400629 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800630 data: grouped!(syn!(Type)) >>
631 (TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400632 group_token: data.1,
David Tolnayeadbda32017-12-29 02:33:47 -0500633 elem: Box::new(data.0),
Michael Layzell93c36282017-06-04 20:43:14 -0400634 })
635 ));
636 }
637
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800638 impl Synom for TypeParen {
Michael Layzell92639a52017-06-01 00:07:44 -0400639 named!(parse -> Self, do_parse!(
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800640 data: parens!(syn!(Type)) >>
641 (TypeParen {
Michael Layzell92639a52017-06-01 00:07:44 -0400642 paren_token: data.1,
David Tolnayeadbda32017-12-29 02:33:47 -0500643 elem: Box::new(data.0),
Michael Layzell92639a52017-06-01 00:07:44 -0400644 })
645 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700646 }
David Tolnayb79ee962016-09-04 09:39:20 -0700647
Alex Crichton954046c2017-05-30 21:49:42 -0700648 impl Synom for Path {
Michael Layzell92639a52017-06-01 00:07:44 -0400649 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800650 colon: option!(punct!(::)) >>
David Tolnaye45b59f2017-12-25 18:44:49 -0500651 segments: call!(Delimited::<PathSegment, Token![::]>::parse_separated_nonempty) >>
652 cond_reduce!(segments.first().map_or(true, |seg| seg.item().ident != "dyn"), epsilon!()) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400653 (Path {
David Tolnay570695e2017-06-03 16:15:13 -0700654 leading_colon: colon,
Michael Layzell92639a52017-06-01 00:07:44 -0400655 segments: segments,
Michael Layzell92639a52017-06-01 00:07:44 -0400656 })
657 ));
Alex Crichton36e91bf2017-07-06 14:59:56 -0700658
659 fn description() -> Option<&'static str> {
660 Some("path")
661 }
Alex Crichton954046c2017-05-30 21:49:42 -0700662 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700663
Nika Layzellc680e612017-12-04 19:07:20 -0500664 #[cfg(not(feature = "full"))]
Nika Layzellc08227a2017-12-04 16:30:17 -0500665 impl Synom for GenericArgument {
Nika Layzell357885a2017-12-04 15:47:07 -0500666 named!(parse -> Self, alt!(
Nika Layzellc08227a2017-12-04 16:30:17 -0500667 call!(ty_no_eq_after) => { GenericArgument::Type }
Nika Layzell357885a2017-12-04 15:47:07 -0500668 |
Nika Layzellc08227a2017-12-04 16:30:17 -0500669 syn!(Lifetime) => { GenericArgument::Lifetime }
Nika Layzell357885a2017-12-04 15:47:07 -0500670 |
David Tolnay506e43a2017-12-29 11:34:36 -0500671 syn!(Binding) => { GenericArgument::Binding }
Nika Layzell357885a2017-12-04 15:47:07 -0500672 ));
673 }
674
Nika Layzellc680e612017-12-04 19:07:20 -0500675 #[cfg(feature = "full")]
676 impl Synom for GenericArgument {
677 named!(parse -> Self, alt!(
678 call!(ty_no_eq_after) => { GenericArgument::Type }
679 |
680 syn!(Lifetime) => { GenericArgument::Lifetime }
681 |
David Tolnay506e43a2017-12-29 11:34:36 -0500682 syn!(Binding) => { GenericArgument::Binding }
Nika Layzellc680e612017-12-04 19:07:20 -0500683 |
David Tolnay8c91b882017-12-28 23:04:32 -0500684 syn!(ExprLit) => { |l| GenericArgument::Const(Expr::Lit(l).into()) }
Nika Layzellce37f332017-12-05 12:01:22 -0500685 |
David Tolnay8c91b882017-12-28 23:04:32 -0500686 syn!(ExprBlock) => { |b| GenericArgument::Const(Expr::Block(b).into()) }
Nika Layzellc680e612017-12-04 19:07:20 -0500687 ));
688 }
689
Nika Layzellc08227a2017-12-04 16:30:17 -0500690 impl Synom for AngleBracketedGenericArguments {
Nika Layzell357885a2017-12-04 15:47:07 -0500691 named!(parse -> Self, do_parse!(
David Tolnay2d4e08a2017-12-28 23:54:07 -0500692 colon2: option!(punct!(::)) >>
Nika Layzell357885a2017-12-04 15:47:07 -0500693 lt: punct!(<) >>
694 args: call!(Delimited::parse_terminated) >>
695 gt: punct!(>) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500696 (AngleBracketedGenericArguments {
David Tolnay2d4e08a2017-12-28 23:54:07 -0500697 colon2_token: colon2,
Nika Layzell357885a2017-12-04 15:47:07 -0500698 lt_token: lt,
699 args: args,
700 gt_token: gt,
701 })
702 ));
703 }
704
Alex Crichton954046c2017-05-30 21:49:42 -0700705 impl Synom for PathSegment {
Michael Layzell92639a52017-06-01 00:07:44 -0400706 named!(parse -> Self, alt!(
707 do_parse!(
David Tolnay570695e2017-06-03 16:15:13 -0700708 ident: syn!(Ident) >>
Nika Layzellc08227a2017-12-04 16:30:17 -0500709 arguments: syn!(AngleBracketedGenericArguments) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400710 (PathSegment {
David Tolnay570695e2017-06-03 16:15:13 -0700711 ident: ident,
Nika Layzellc08227a2017-12-04 16:30:17 -0500712 arguments: PathArguments::AngleBracketed(arguments),
Michael Layzell92639a52017-06-01 00:07:44 -0400713 })
714 )
715 |
716 mod_style_path_segment
717 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700718 }
David Tolnay570695e2017-06-03 16:15:13 -0700719
David Tolnayd60cfec2017-12-29 00:21:38 -0500720 named!(pub ty_no_eq_after -> Type, terminated!(syn!(Type), not!(punct!(=))));
David Tolnay9d8f1972016-09-04 11:58:48 -0700721
Alex Crichton954046c2017-05-30 21:49:42 -0700722 impl Path {
Michael Layzell92639a52017-06-01 00:07:44 -0400723 named!(pub parse_mod_style -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800724 colon: option!(punct!(::)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400725 segments: call!(Delimited::parse_separated_nonempty_with,
726 mod_style_path_segment) >>
727 (Path {
David Tolnay570695e2017-06-03 16:15:13 -0700728 leading_colon: colon,
Michael Layzell92639a52017-06-01 00:07:44 -0400729 segments: segments,
Michael Layzell92639a52017-06-01 00:07:44 -0400730 })
731 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700732 }
Arnavionf2dada12017-04-20 23:55:20 -0700733
734 named!(mod_style_path_segment -> PathSegment, alt!(
David Tolnay5f332a92017-12-26 00:42:45 -0500735 syn!(Ident) => { Into::into }
Arnavionf2dada12017-04-20 23:55:20 -0700736 |
David Tolnay5f332a92017-12-26 00:42:45 -0500737 keyword!(super) => { Into::into }
738 |
739 keyword!(self) => { Into::into }
740 |
741 keyword!(Self) => { Into::into }
742 |
743 keyword!(crate) => { Into::into }
Arnavionf2dada12017-04-20 23:55:20 -0700744 ));
745
David Tolnay506e43a2017-12-29 11:34:36 -0500746 impl Synom for Binding {
Michael Layzell92639a52017-06-01 00:07:44 -0400747 named!(parse -> Self, do_parse!(
748 id: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800749 eq: punct!(=) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800750 ty: syn!(Type) >>
David Tolnay506e43a2017-12-29 11:34:36 -0500751 (Binding {
Michael Layzell92639a52017-06-01 00:07:44 -0400752 ident: id,
753 eq_token: eq,
754 ty: ty,
755 })
756 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700757 }
758
759 impl Synom for PolyTraitRef {
Michael Layzell92639a52017-06-01 00:07:44 -0400760 named!(parse -> Self, do_parse!(
761 bound_lifetimes: option!(syn!(BoundLifetimes)) >>
762 trait_ref: syn!(Path) >>
763 parenthesized: option!(cond_reduce!(
Nika Layzellc08227a2017-12-04 16:30:17 -0500764 trait_ref.segments.get(trait_ref.segments.len() - 1).item().arguments.is_empty(),
765 syn!(ParenthesizedGenericArguments)
Michael Layzell92639a52017-06-01 00:07:44 -0400766 )) >>
767 ({
768 let mut trait_ref = trait_ref;
769 if let Some(parenthesized) = parenthesized {
Nika Layzellc08227a2017-12-04 16:30:17 -0500770 let parenthesized = PathArguments::Parenthesized(parenthesized);
Michael Layzell92639a52017-06-01 00:07:44 -0400771 let len = trait_ref.segments.len();
Nika Layzellc08227a2017-12-04 16:30:17 -0500772 trait_ref.segments.get_mut(len - 1).item_mut().arguments = parenthesized;
Michael Layzell92639a52017-06-01 00:07:44 -0400773 }
774 PolyTraitRef {
775 bound_lifetimes: bound_lifetimes,
776 trait_ref: trait_ref,
777 }
778 })
779 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700780 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700781
Alex Crichton954046c2017-05-30 21:49:42 -0700782 impl Synom for BareFnArg {
Michael Layzell92639a52017-06-01 00:07:44 -0400783 named!(parse -> Self, do_parse!(
784 name: option!(do_parse!(
Alex Crichton23a15f62017-08-28 12:34:23 -0700785 name: syn!(BareFnArgName) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800786 not!(punct!(::)) >>
787 colon: punct!(:) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400788 (name, colon)
789 )) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800790 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400791 (BareFnArg {
792 name: name,
793 ty: ty,
794 })
795 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700796 }
David Tolnayb8d8ef52016-10-29 14:30:08 -0700797
Alex Crichton23a15f62017-08-28 12:34:23 -0700798 impl Synom for BareFnArgName {
799 named!(parse -> Self, alt!(
800 map!(syn!(Ident), BareFnArgName::Named)
801 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800802 map!(punct!(_), BareFnArgName::Wild)
Alex Crichton23a15f62017-08-28 12:34:23 -0700803 ));
804 }
805
Alex Crichton954046c2017-05-30 21:49:42 -0700806 impl Synom for Abi {
Michael Layzell92639a52017-06-01 00:07:44 -0400807 named!(parse -> Self, do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800808 extern_: keyword!(extern) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400809 // TODO: this parses all literals, not just strings
810 name: option!(syn!(Lit)) >>
811 (Abi {
812 extern_token: extern_,
David Tolnayd5125762017-12-29 02:42:17 -0500813 name: name,
Michael Layzell92639a52017-06-01 00:07:44 -0400814 })
815 ));
Alex Crichton954046c2017-05-30 21:49:42 -0700816 }
David Tolnay9d8f1972016-09-04 11:58:48 -0700817}
David Tolnay87d0b442016-09-04 11:52:12 -0700818
819#[cfg(feature = "printing")]
820mod printing {
821 use super::*;
David Tolnay51382052017-12-27 13:46:21 -0500822 use quote::{ToTokens, Tokens};
David Tolnay87d0b442016-09-04 11:52:12 -0700823
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800824 impl ToTokens for TypeSlice {
David Tolnay87d0b442016-09-04 11:52:12 -0700825 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700826 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500827 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700828 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700829 }
830 }
831
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800832 impl ToTokens for TypeArray {
Alex Crichton62a0a592017-05-22 13:58:53 -0700833 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700834 self.bracket_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500835 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700836 self.semi_token.to_tokens(tokens);
David Tolnayeadbda32017-12-29 02:33:47 -0500837 self.len.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700838 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700839 }
840 }
841
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800842 impl ToTokens for TypePtr {
Alex Crichton62a0a592017-05-22 13:58:53 -0700843 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700844 self.star_token.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500845 match self.mutability {
David Tolnay24237fb2017-12-29 02:15:26 -0500846 Some(ref tok) => tok.to_tokens(tokens),
847 None => {
Alex Crichton259ee532017-07-14 06:51:02 -0700848 TokensOrDefault(&self.const_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400849 }
850 }
David Tolnay136aaa32017-12-29 02:37:36 -0500851 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700852 }
853 }
854
David Tolnay0a89b4d2017-11-13 00:55:45 -0800855 impl ToTokens for TypeReference {
Alex Crichton62a0a592017-05-22 13:58:53 -0700856 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700857 self.and_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700858 self.lifetime.to_tokens(tokens);
David Tolnay136aaa32017-12-29 02:37:36 -0500859 self.mutability.to_tokens(tokens);
860 self.elem.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700861 }
862 }
863
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800864 impl ToTokens for TypeBareFn {
Alex Crichton62a0a592017-05-22 13:58:53 -0700865 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaybe7a9592017-12-29 02:39:53 -0500866 self.lifetimes.to_tokens(tokens);
867 self.unsafety.to_tokens(tokens);
868 self.abi.to_tokens(tokens);
869 self.fn_token.to_tokens(tokens);
870 self.paren_token.surround(tokens, |tokens| {
871 self.inputs.to_tokens(tokens);
872 if let Some(ref variadic) = self.variadic {
873 if !self.inputs.empty_or_trailing() {
874 let span = variadic.0[0];
875 <Token![,]>::new(span).to_tokens(tokens);
876 }
877 variadic.to_tokens(tokens);
878 }
879 });
880 self.output.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700881 }
882 }
883
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800884 impl ToTokens for TypeNever {
Alex Crichton62a0a592017-05-22 13:58:53 -0700885 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700886 self.bang_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700887 }
888 }
889
David Tolnay05362582017-12-26 01:33:57 -0500890 impl ToTokens for TypeTuple {
Alex Crichton62a0a592017-05-22 13:58:53 -0700891 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700892 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500893 self.elems.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700894 })
Alex Crichton62a0a592017-05-22 13:58:53 -0700895 }
896 }
897
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800898 impl ToTokens for TypePath {
Alex Crichton62a0a592017-05-22 13:58:53 -0700899 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700900 PathTokens(&self.qself, &self.path).to_tokens(tokens);
901 }
902 }
903
904 impl<'a> ToTokens for PathTokens<'a> {
905 fn to_tokens(&self, tokens: &mut Tokens) {
906 let qself = match *self.0 {
Alex Crichton62a0a592017-05-22 13:58:53 -0700907 Some(ref qself) => qself,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700908 None => return self.1.to_tokens(tokens),
Alex Crichton62a0a592017-05-22 13:58:53 -0700909 };
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700910 qself.lt_token.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700911 qself.ty.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400912
913 // XXX: Gross.
914 let pos = if qself.position > 0 && qself.position >= self.1.segments.len() {
915 self.1.segments.len() - 1
916 } else {
917 qself.position
918 };
David Tolnay570695e2017-06-03 16:15:13 -0700919 let mut segments = self.1.segments.iter();
Michael Layzell3936ceb2017-07-08 00:28:36 -0400920 if pos > 0 {
Alex Crichton259ee532017-07-14 06:51:02 -0700921 TokensOrDefault(&qself.as_token).to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700922 self.1.leading_colon.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700923 for (i, segment) in (&mut segments).take(pos).enumerate() {
924 if i + 1 == pos {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700925 segment.item().to_tokens(tokens);
926 qself.gt_token.to_tokens(tokens);
927 segment.delimiter().to_tokens(tokens);
928 } else {
929 segment.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700930 }
Alex Crichton62a0a592017-05-22 13:58:53 -0700931 }
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700932 } else {
933 qself.gt_token.to_tokens(tokens);
David Tolnay570695e2017-06-03 16:15:13 -0700934 self.1.leading_colon.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700935 }
David Tolnay570695e2017-06-03 16:15:13 -0700936 for segment in segments {
Alex Crichton62a0a592017-05-22 13:58:53 -0700937 segment.to_tokens(tokens);
938 }
939 }
940 }
941
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800942 impl ToTokens for TypeTraitObject {
Alex Crichton62a0a592017-05-22 13:58:53 -0700943 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnaye45b59f2017-12-25 18:44:49 -0500944 self.dyn_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700945 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700946 }
947 }
948
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800949 impl ToTokens for TypeImplTrait {
Alex Crichton62a0a592017-05-22 13:58:53 -0700950 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700951 self.impl_token.to_tokens(tokens);
952 self.bounds.to_tokens(tokens);
Alex Crichton62a0a592017-05-22 13:58:53 -0700953 }
954 }
955
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800956 impl ToTokens for TypeGroup {
Michael Layzell93c36282017-06-04 20:43:14 -0400957 fn to_tokens(&self, tokens: &mut Tokens) {
958 self.group_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500959 self.elem.to_tokens(tokens);
Michael Layzell93c36282017-06-04 20:43:14 -0400960 });
961 }
962 }
963
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800964 impl ToTokens for TypeParen {
Alex Crichton62a0a592017-05-22 13:58:53 -0700965 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700966 self.paren_token.surround(tokens, |tokens| {
David Tolnayeadbda32017-12-29 02:33:47 -0500967 self.elem.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700968 });
Alex Crichton62a0a592017-05-22 13:58:53 -0700969 }
970 }
971
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800972 impl ToTokens for TypeInfer {
Alex Crichton62a0a592017-05-22 13:58:53 -0700973 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700974 self.underscore_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700975 }
976 }
977
David Tolnay323279a2017-12-29 11:26:32 -0500978 impl ToTokens for TypeMacro {
979 fn to_tokens(&self, tokens: &mut Tokens) {
980 self.mac.to_tokens(tokens);
981 }
982 }
983
David Tolnay2ae520a2017-12-29 11:19:50 -0500984 impl ToTokens for TypeVerbatim {
985 fn to_tokens(&self, tokens: &mut Tokens) {
986 self.tts.to_tokens(tokens);
987 }
988 }
989
David Tolnay87d0b442016-09-04 11:52:12 -0700990 impl ToTokens for Path {
991 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700992 self.leading_colon.to_tokens(tokens);
993 self.segments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -0700994 }
995 }
996
997 impl ToTokens for PathSegment {
998 fn to_tokens(&self, tokens: &mut Tokens) {
999 self.ident.to_tokens(tokens);
Nika Layzellc08227a2017-12-04 16:30:17 -05001000 self.arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001001 }
1002 }
1003
Nika Layzellc08227a2017-12-04 16:30:17 -05001004 impl ToTokens for PathArguments {
David Tolnay87d0b442016-09-04 11:52:12 -07001005 fn to_tokens(&self, tokens: &mut Tokens) {
1006 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -05001007 PathArguments::None => {}
1008 PathArguments::AngleBracketed(ref arguments) => {
1009 arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001010 }
Nika Layzellc08227a2017-12-04 16:30:17 -05001011 PathArguments::Parenthesized(ref arguments) => {
1012 arguments.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001013 }
1014 }
1015 }
1016 }
1017
Nika Layzellc08227a2017-12-04 16:30:17 -05001018 impl ToTokens for GenericArgument {
David Tolnaybb4ca9f2017-12-26 12:28:58 -05001019 #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
Nika Layzell357885a2017-12-04 15:47:07 -05001020 fn to_tokens(&self, tokens: &mut Tokens) {
1021 match *self {
Nika Layzellc08227a2017-12-04 16:30:17 -05001022 GenericArgument::Lifetime(ref lt) => lt.to_tokens(tokens),
1023 GenericArgument::Type(ref ty) => ty.to_tokens(tokens),
David Tolnay506e43a2017-12-29 11:34:36 -05001024 GenericArgument::Binding(ref tb) => tb.to_tokens(tokens),
David Tolnay8c91b882017-12-28 23:04:32 -05001025 GenericArgument::Const(ref e) => match *e {
1026 Expr::Lit(_) => e.to_tokens(tokens),
Nika Layzellce37f332017-12-05 12:01:22 -05001027
1028 // NOTE: We should probably support parsing blocks with only
1029 // expressions in them without the full feature for const
1030 // generics.
1031 #[cfg(feature = "full")]
David Tolnay8c91b882017-12-28 23:04:32 -05001032 Expr::Block(_) => e.to_tokens(tokens),
Nika Layzellce37f332017-12-05 12:01:22 -05001033
1034 // ERROR CORRECTION: Add braces to make sure that the
1035 // generated code is valid.
David Tolnay32954ef2017-12-26 22:43:16 -05001036 _ => token::Brace::default().surround(tokens, |tokens| {
Nika Layzellce37f332017-12-05 12:01:22 -05001037 e.to_tokens(tokens);
1038 }),
David Tolnay51382052017-12-27 13:46:21 -05001039 },
Nika Layzell357885a2017-12-04 15:47:07 -05001040 }
1041 }
1042 }
1043
Nika Layzellc08227a2017-12-04 16:30:17 -05001044 impl ToTokens for AngleBracketedGenericArguments {
David Tolnay87d0b442016-09-04 11:52:12 -07001045 fn to_tokens(&self, tokens: &mut Tokens) {
David Tolnay2d4e08a2017-12-28 23:54:07 -05001046 self.colon2_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001047 self.lt_token.to_tokens(tokens);
Nika Layzell357885a2017-12-04 15:47:07 -05001048 self.args.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001049 self.gt_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001050 }
1051 }
1052
David Tolnay506e43a2017-12-29 11:34:36 -05001053 impl ToTokens for Binding {
David Tolnay87d0b442016-09-04 11:52:12 -07001054 fn to_tokens(&self, tokens: &mut Tokens) {
1055 self.ident.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001056 self.eq_token.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001057 self.ty.to_tokens(tokens);
1058 }
1059 }
1060
Nika Layzellc08227a2017-12-04 16:30:17 -05001061 impl ToTokens for ParenthesizedGenericArguments {
David Tolnay87d0b442016-09-04 11:52:12 -07001062 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001063 self.paren_token.surround(tokens, |tokens| {
1064 self.inputs.to_tokens(tokens);
1065 });
1066 self.output.to_tokens(tokens);
1067 }
1068 }
1069
David Tolnayf93b90d2017-11-11 19:21:26 -08001070 impl ToTokens for ReturnType {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001071 fn to_tokens(&self, tokens: &mut Tokens) {
1072 match *self {
David Tolnayf93b90d2017-11-11 19:21:26 -08001073 ReturnType::Default => {}
David Tolnay4a3f59a2017-12-28 21:21:12 -05001074 ReturnType::Type(ref arrow, ref ty) => {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001075 arrow.to_tokens(tokens);
1076 ty.to_tokens(tokens);
1077 }
David Tolnay87d0b442016-09-04 11:52:12 -07001078 }
1079 }
1080 }
1081
1082 impl ToTokens for PolyTraitRef {
1083 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001084 self.bound_lifetimes.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001085 self.trait_ref.to_tokens(tokens);
1086 }
1087 }
1088
David Tolnay62f374c2016-10-02 13:37:00 -07001089 impl ToTokens for BareFnArg {
David Tolnay42602292016-10-01 22:25:45 -07001090 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001091 if let Some((ref name, ref colon)) = self.name {
David Tolnay62f374c2016-10-02 13:37:00 -07001092 name.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001093 colon.to_tokens(tokens);
David Tolnay42602292016-10-01 22:25:45 -07001094 }
1095 self.ty.to_tokens(tokens);
David Tolnay87d0b442016-09-04 11:52:12 -07001096 }
1097 }
David Tolnayb8d8ef52016-10-29 14:30:08 -07001098
Alex Crichton23a15f62017-08-28 12:34:23 -07001099 impl ToTokens for BareFnArgName {
1100 fn to_tokens(&self, tokens: &mut Tokens) {
1101 match *self {
1102 BareFnArgName::Named(ref t) => t.to_tokens(tokens),
1103 BareFnArgName::Wild(ref t) => t.to_tokens(tokens),
1104 }
1105 }
1106 }
1107
David Tolnayb8d8ef52016-10-29 14:30:08 -07001108 impl ToTokens for Abi {
1109 fn to_tokens(&self, tokens: &mut Tokens) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -07001110 self.extern_token.to_tokens(tokens);
David Tolnayd5125762017-12-29 02:42:17 -05001111 self.name.to_tokens(tokens);
David Tolnayb8d8ef52016-10-29 14:30:08 -07001112 }
1113 }
David Tolnay87d0b442016-09-04 11:52:12 -07001114}