2 use proc_macro2
::TokenStream
;
3 use punctuated
::Punctuated
;
4 #[cfg(feature = "extra-traits")]
5 use std
::hash
::{Hash, Hasher}
;
6 #[cfg(feature = "extra-traits")]
7 use tt
::TokenStreamHelper
;
10 /// The possible types that a Rust value could have.
12 /// *This type is available if Syn is built with the `"derive"` or `"full"`
15 /// # Syntax tree enum
17 /// This type is a [syntax tree enum].
19 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
21 /// A dynamically sized slice type: `[T]`.
23 /// *This type is available if Syn is built with the `"derive"` or
24 /// `"full"` feature.*
26 pub bracket_token
: token
::Bracket
,
30 /// A fixed size array type: `[T; n]`.
32 /// *This type is available if Syn is built with the `"derive"` or
33 /// `"full"` feature.*
35 pub bracket_token
: token
::Bracket
,
37 pub semi_token
: Token
![;],
41 /// A raw pointer type: `*const T` or `*mut T`.
43 /// *This type is available if Syn is built with the `"derive"` or
44 /// `"full"` feature.*
46 pub star_token
: Token
![*],
47 pub const_token
: Option
<Token
![const]>,
48 pub mutability
: Option
<Token
![mut]>,
52 /// A reference type: `&'a T` or `&'a mut T`.
54 /// *This type is available if Syn is built with the `"derive"` or
55 /// `"full"` feature.*
56 pub Reference(TypeReference
{
57 pub and_token
: Token
![&],
58 pub lifetime
: Option
<Lifetime
>,
59 pub mutability
: Option
<Token
![mut]>,
63 /// A bare function type: `fn(usize) -> bool`.
65 /// *This type is available if Syn is built with the `"derive"` or
66 /// `"full"` feature.*
67 pub BareFn(TypeBareFn
{
68 pub lifetimes
: Option
<BoundLifetimes
>,
69 pub unsafety
: Option
<Token
![unsafe]>,
71 pub fn_token
: Token
![fn],
72 pub paren_token
: token
::Paren
,
73 pub inputs
: Punctuated
<BareFnArg
, Token
![,]>,
74 pub variadic
: Option
<Token
![...]>,
75 pub output
: ReturnType
,
78 /// The never type: `!`.
80 /// *This type is available if Syn is built with the `"derive"` or
81 /// `"full"` feature.*
83 pub bang_token
: Token
![!],
86 /// A tuple type: `(A, B, C, String)`.
88 /// *This type is available if Syn is built with the `"derive"` or
89 /// `"full"` feature.*
91 pub paren_token
: token
::Paren
,
92 pub elems
: Punctuated
<Type
, Token
![,]>,
95 /// A path like `std::slice::Iter`, optionally qualified with a
96 /// self-type as in `<Vec<T> as SomeTrait>::Associated`.
98 /// Type arguments are stored in the Path itself.
100 /// *This type is available if Syn is built with the `"derive"` or
101 /// `"full"` feature.*
103 pub qself
: Option
<QSelf
>,
107 /// A trait object type `Bound1 + Bound2 + Bound3` where `Bound` is a
108 /// trait or a lifetime.
110 /// *This type is available if Syn is built with the `"derive"` or
111 /// `"full"` feature.*
112 pub TraitObject(TypeTraitObject
{
113 pub dyn_token
: Option
<Token
![dyn]>,
114 pub bounds
: Punctuated
<TypeParamBound
, Token
![+]>,
117 /// An `impl Bound1 + Bound2 + Bound3` type where `Bound` is a trait or
120 /// *This type is available if Syn is built with the `"derive"` or
121 /// `"full"` feature.*
122 pub ImplTrait(TypeImplTrait
{
123 pub impl_token
: Token
![impl],
124 pub bounds
: Punctuated
<TypeParamBound
, Token
![+]>,
127 /// A parenthesized type equivalent to the inner type.
129 /// *This type is available if Syn is built with the `"derive"` or
130 /// `"full"` feature.*
131 pub Paren(TypeParen
{
132 pub paren_token
: token
::Paren
,
136 /// A type contained within invisible delimiters.
138 /// *This type is available if Syn is built with the `"derive"` or
139 /// `"full"` feature.*
140 pub Group(TypeGroup
{
141 pub group_token
: token
::Group
,
145 /// Indication that a type should be inferred by the compiler: `_`.
147 /// *This type is available if Syn is built with the `"derive"` or
148 /// `"full"` feature.*
149 pub Infer(TypeInfer
{
150 pub underscore_token
: Token
![_
],
153 /// A macro in the type position.
155 /// *This type is available if Syn is built with the `"derive"` or
156 /// `"full"` feature.*
157 pub Macro(TypeMacro
{
161 /// Tokens in type position not interpreted by Syn.
163 /// *This type is available if Syn is built with the `"derive"` or
164 /// `"full"` feature.*
165 pub Verbatim(TypeVerbatim
#manual_extra_traits {
166 pub tts
: TokenStream
,
171 #[cfg(feature = "extra-traits")]
172 impl Eq
for TypeVerbatim {}
174 #[cfg(feature = "extra-traits")]
175 impl PartialEq
for TypeVerbatim
{
176 fn eq(&self, other
: &Self) -> bool
{
177 TokenStreamHelper(&self.tts
) == TokenStreamHelper(&other
.tts
)
181 #[cfg(feature = "extra-traits")]
182 impl Hash
for TypeVerbatim
{
183 fn hash
<H
>(&self, state
: &mut H
)
187 TokenStreamHelper(&self.tts
).hash(state
);
192 /// The binary interface of a function: `extern "C"`.
194 /// *This type is available if Syn is built with the `"derive"` or `"full"`
197 pub extern_token
: Token
![extern],
198 pub name
: Option
<LitStr
>,
203 /// An argument in a function type: the `usize` in `fn(usize) -> bool`.
205 /// *This type is available if Syn is built with the `"derive"` or `"full"`
207 pub struct BareFnArg
{
208 pub name
: Option
<(BareFnArgName
, Token
![:])>,
214 /// Name of an argument in a function type: the `n` in `fn(n: usize)`.
216 /// *This type is available if Syn is built with the `"derive"` or `"full"`
218 pub enum BareFnArgName
{
219 /// Argument given a name.
221 /// Argument not given a name, matched with `_`.
227 /// Return type of a function signature.
229 /// *This type is available if Syn is built with the `"derive"` or `"full"`
231 pub enum ReturnType
{
232 /// Return type is not specified.
234 /// Functions default to `()` and closures default to type inference.
236 /// A particular type is returned.
237 Type(Token
![->], Box
<Type
>),
241 #[cfg(feature = "parsing")]
245 use parse
::{Parse, ParseStream, Result}
;
248 impl Parse
for Type
{
249 fn parse(input
: ParseStream
) -> Result
<Self> {
250 ambig_ty(input
, true)
255 /// In some positions, types may not contain the `+` character, to
256 /// disambiguate them. For example in the expression `1 as T`, T may not
257 /// contain a `+` character.
259 /// This parser does not allow a `+`, while the default parser does.
260 pub fn without_plus(input
: ParseStream
) -> Result
<Self> {
261 ambig_ty(input
, false)
265 fn ambig_ty(input
: ParseStream
, allow_plus
: bool
) -> Result
<Type
> {
266 if input
.peek(token
::Group
) {
267 return input
.parse().map(Type
::Group
);
270 let mut lifetimes
= None
::<BoundLifetimes
>;
271 let mut lookahead
= input
.lookahead1();
272 if lookahead
.peek(Token
![for]) {
273 lifetimes
= input
.parse()?
;
274 lookahead
= input
.lookahead1();
275 if !lookahead
.peek(Ident
)
276 && !lookahead
.peek(Token
![fn])
277 && !lookahead
.peek(Token
![unsafe])
278 && !lookahead
.peek(Token
![extern])
279 && !lookahead
.peek(Token
![super])
280 && !lookahead
.peek(Token
![self])
281 && !lookahead
.peek(Token
![Self])
282 && !lookahead
.peek(Token
![crate])
284 return Err(lookahead
.error());
288 if lookahead
.peek(token
::Paren
) {
290 let paren_token
= parenthesized
!(content
in input
);
291 if content
.is_empty() {
292 return Ok(Type
::Tuple(TypeTuple
{
293 paren_token
: paren_token
,
294 elems
: Punctuated
::new(),
297 if content
.peek(Lifetime
) {
298 return Ok(Type
::Paren(TypeParen
{
299 paren_token
: paren_token
,
300 elem
: Box
::new(Type
::TraitObject(content
.parse()?
)),
303 if content
.peek(Token
![?
]) {
304 return Ok(Type
::TraitObject(TypeTraitObject
{
307 let mut bounds
= Punctuated
::new();
308 bounds
.push_value(TypeParamBound
::Trait(TraitBound
{
309 paren_token
: Some(paren_token
),
312 while let Some(plus
) = input
.parse()?
{
313 bounds
.push_punct(plus
);
314 bounds
.push_value(input
.parse()?
);
320 let first
: Type
= content
.parse()?
;
321 if content
.peek(Token
![,]) {
322 return Ok(Type
::Tuple(TypeTuple
{
323 paren_token
: paren_token
,
325 let mut elems
= Punctuated
::new();
326 elems
.push_value(first
);
327 elems
.push_punct(content
.parse()?
);
328 let rest
: Punctuated
<Type
, Token
![,]> =
329 content
.parse_terminated(Parse
::parse
)?
;
335 if allow_plus
&& input
.peek(Token
![+]) {
337 let first
= match first
{
338 Type
::Path(TypePath { qself: None, path }
) => {
339 TypeParamBound
::Trait(TraitBound
{
340 paren_token
: Some(paren_token
),
341 modifier
: TraitBoundModifier
::None
,
346 Type
::TraitObject(TypeTraitObject
{
350 if bounds
.len() > 1 || bounds
.trailing_punct() {
354 Type
::TraitObject(TypeTraitObject { bounds, .. }
) => {
355 match bounds
.into_iter().next().unwrap() {
356 TypeParamBound
::Trait(trait_bound
) => {
357 TypeParamBound
::Trait(TraitBound
{
358 paren_token
: Some(paren_token
),
370 return Ok(Type
::TraitObject(TypeTraitObject
{
373 let mut bounds
= Punctuated
::new();
374 bounds
.push_value(first
);
375 while let Some(plus
) = input
.parse()?
{
376 bounds
.push_punct(plus
);
377 bounds
.push_value(input
.parse()?
);
384 Ok(Type
::Paren(TypeParen
{
385 paren_token
: paren_token
,
386 elem
: Box
::new(first
),
388 } else if lookahead
.peek(Token
![fn])
389 || lookahead
.peek(Token
![unsafe])
390 || lookahead
.peek(Token
![extern]) && !input
.peek2(Token
![::])
392 let mut bare_fn
: TypeBareFn
= input
.parse()?
;
393 bare_fn
.lifetimes
= lifetimes
;
394 Ok(Type
::BareFn(bare_fn
))
395 } else if lookahead
.peek(Ident
)
396 || input
.peek(Token
![super])
397 || input
.peek(Token
![self])
398 || input
.peek(Token
![Self])
399 || input
.peek(Token
![crate])
400 || input
.peek(Token
![extern])
401 || lookahead
.peek(Token
![::])
402 || lookahead
.peek(Token
![<])
404 if input
.peek(Token
![dyn]) {
405 let mut trait_object
: TypeTraitObject
= input
.parse()?
;
406 if lifetimes
.is_some() {
407 match *trait_object
.bounds
.iter_mut().next().unwrap() {
408 TypeParamBound
::Trait(ref mut trait_bound
) => {
409 trait_bound
.lifetimes
= lifetimes
;
411 TypeParamBound
::Lifetime(_
) => unreachable
!(),
414 return Ok(Type
::TraitObject(trait_object
));
417 let ty
: TypePath
= input
.parse()?
;
418 if ty
.qself
.is_some() {
419 return Ok(Type
::Path(ty
));
422 if input
.peek(Token
![!]) && !input
.peek(Token
![!=]) {
423 let mut contains_arguments
= false;
424 for segment
in &ty
.path
.segments
{
425 match segment
.arguments
{
426 PathArguments
::None
=> {}
427 PathArguments
::AngleBracketed(_
) | PathArguments
::Parenthesized(_
) => {
428 contains_arguments
= true;
433 if !contains_arguments
{
434 let bang_token
: Token
![!] = input
.parse()?
;
435 let (delimiter
, tts
) = mac
::parse_delimiter(input
)?
;
436 return Ok(Type
::Macro(TypeMacro
{
439 bang_token
: bang_token
,
440 delimiter
: delimiter
,
447 if lifetimes
.is_some() || allow_plus
&& input
.peek(Token
![+]) {
448 let mut bounds
= Punctuated
::new();
449 bounds
.push_value(TypeParamBound
::Trait(TraitBound
{
451 modifier
: TraitBoundModifier
::None
,
452 lifetimes
: lifetimes
,
456 while input
.peek(Token
![+]) {
457 bounds
.push_punct(input
.parse()?
);
458 if input
.peek(Token
![>]) {
461 bounds
.push_value(input
.parse()?
);
464 return Ok(Type
::TraitObject(TypeTraitObject
{
471 } else if lookahead
.peek(token
::Bracket
) {
473 let bracket_token
= bracketed
!(content
in input
);
474 let elem
: Type
= content
.parse()?
;
475 if content
.peek(Token
![;]) {
476 Ok(Type
::Array(TypeArray
{
477 bracket_token
: bracket_token
,
478 elem
: Box
::new(elem
),
479 semi_token
: content
.parse()?
,
480 len
: content
.parse()?
,
483 Ok(Type
::Slice(TypeSlice
{
484 bracket_token
: bracket_token
,
485 elem
: Box
::new(elem
),
488 } else if lookahead
.peek(Token
![*]) {
489 input
.parse().map(Type
::Ptr
)
490 } else if lookahead
.peek(Token
![&]) {
491 input
.parse().map(Type
::Reference
)
492 } else if lookahead
.peek(Token
![!]) && !input
.peek(Token
![=]) {
493 input
.parse().map(Type
::Never
)
494 } else if lookahead
.peek(Token
![impl ]) {
495 input
.parse().map(Type
::ImplTrait
)
496 } else if lookahead
.peek(Token
![_
]) {
497 input
.parse().map(Type
::Infer
)
498 } else if lookahead
.peek(Lifetime
) {
499 input
.parse().map(Type
::TraitObject
)
501 Err(lookahead
.error())
505 impl Parse
for TypeSlice
{
506 fn parse(input
: ParseStream
) -> Result
<Self> {
509 bracket_token
: bracketed
!(content
in input
),
510 elem
: content
.parse()?
,
515 impl Parse
for TypeArray
{
516 fn parse(input
: ParseStream
) -> Result
<Self> {
519 bracket_token
: bracketed
!(content
in input
),
520 elem
: content
.parse()?
,
521 semi_token
: content
.parse()?
,
522 len
: content
.parse()?
,
527 impl Parse
for TypePtr
{
528 fn parse(input
: ParseStream
) -> Result
<Self> {
529 let star_token
: Token
![*] = input
.parse()?
;
531 let lookahead
= input
.lookahead1();
532 let (const_token
, mutability
) = if lookahead
.peek(Token
![const]) {
533 (Some(input
.parse()?
), None
)
534 } else if lookahead
.peek(Token
![mut]) {
535 (None
, Some(input
.parse()?
))
537 return Err(lookahead
.error());
541 star_token
: star_token
,
542 const_token
: const_token
,
543 mutability
: mutability
,
544 elem
: Box
::new(input
.call(Type
::without_plus
)?
),
549 impl Parse
for TypeReference
{
550 fn parse(input
: ParseStream
) -> Result
<Self> {
552 and_token
: input
.parse()?
,
553 lifetime
: input
.parse()?
,
554 mutability
: input
.parse()?
,
555 // & binds tighter than +, so we don't allow + here.
556 elem
: Box
::new(input
.call(Type
::without_plus
)?
),
561 impl Parse
for TypeBareFn
{
562 fn parse(input
: ParseStream
) -> Result
<Self> {
566 lifetimes
: input
.parse()?
,
567 unsafety
: input
.parse()?
,
569 fn_token
: input
.parse()?
,
570 paren_token
: parenthesized
!(args
in input
),
572 let mut inputs
= Punctuated
::new();
573 while !args
.is_empty() && !args
.peek(Token
![...]) {
574 inputs
.push_value(args
.parse()?
);
578 inputs
.push_punct(args
.parse()?
);
580 allow_variadic
= inputs
.empty_or_trailing();
584 if allow_variadic
&& args
.peek(Token
![...]) {
590 output
: input
.call(ReturnType
::without_plus
)?
,
595 impl Parse
for TypeNever
{
596 fn parse(input
: ParseStream
) -> Result
<Self> {
598 bang_token
: input
.parse()?
,
603 impl Parse
for TypeInfer
{
604 fn parse(input
: ParseStream
) -> Result
<Self> {
606 underscore_token
: input
.parse()?
,
611 impl Parse
for TypeTuple
{
612 fn parse(input
: ParseStream
) -> Result
<Self> {
615 paren_token
: parenthesized
!(content
in input
),
616 elems
: content
.parse_terminated(Type
::parse
)?
,
621 impl Parse
for TypeMacro
{
622 fn parse(input
: ParseStream
) -> Result
<Self> {
629 impl Parse
for TypePath
{
630 fn parse(input
: ParseStream
) -> Result
<Self> {
631 let (qself
, mut path
) = path
::parsing
::qpath(input
, false)?
;
633 if path
.segments
.last().unwrap().value().arguments
.is_empty()
634 && input
.peek(token
::Paren
)
636 let args
: ParenthesizedGenericArguments
= input
.parse()?
;
637 let parenthesized
= PathArguments
::Parenthesized(args
);
638 path
.segments
.last_mut().unwrap().value_mut().arguments
= parenthesized
;
649 pub fn without_plus(input
: ParseStream
) -> Result
<Self> {
650 Self::parse(input
, false)
653 pub fn parse(input
: ParseStream
, allow_plus
: bool
) -> Result
<Self> {
654 if input
.peek(Token
![->]) {
655 let arrow
= input
.parse()?
;
656 let ty
= ambig_ty(input
, allow_plus
)?
;
657 Ok(ReturnType
::Type(arrow
, Box
::new(ty
)))
659 Ok(ReturnType
::Default
)
664 impl Parse
for ReturnType
{
665 fn parse(input
: ParseStream
) -> Result
<Self> {
666 Self::parse(input
, true)
670 impl Parse
for TypeTraitObject
{
671 fn parse(input
: ParseStream
) -> Result
<Self> {
672 Self::parse(input
, true)
676 fn at_least_one_type(bounds
: &Punctuated
<TypeParamBound
, Token
![+]>) -> bool
{
677 for bound
in bounds
{
678 if let TypeParamBound
::Trait(_
) = *bound
{
685 impl TypeTraitObject
{
686 pub fn without_plus(input
: ParseStream
) -> Result
<Self> {
687 Self::parse(input
, false)
690 // Only allow multiple trait references if allow_plus is true.
691 pub fn parse(input
: ParseStream
, allow_plus
: bool
) -> Result
<Self> {
693 dyn_token
: input
.parse()?
,
695 let mut bounds
= Punctuated
::new();
698 bounds
.push_value(input
.parse()?
);
699 if !input
.peek(Token
![+]) {
702 bounds
.push_punct(input
.parse()?
);
703 if input
.peek(Token
![>]) {
708 bounds
.push_value(input
.parse()?
);
710 // Just lifetimes like `'a + 'b` is not a TraitObject.
711 if !at_least_one_type(&bounds
) {
712 return Err(input
.error("expected at least one type"));
720 impl Parse
for TypeImplTrait
{
721 fn parse(input
: ParseStream
) -> Result
<Self> {
723 impl_token
: input
.parse()?
,
724 // NOTE: rust-lang/rust#34511 includes discussion about whether
725 // or not + should be allowed in ImplTrait directly without ().
727 let mut bounds
= Punctuated
::new();
729 bounds
.push_value(input
.parse()?
);
730 if !input
.peek(Token
![+]) {
733 bounds
.push_punct(input
.parse()?
);
741 impl Parse
for TypeGroup
{
742 fn parse(input
: ParseStream
) -> Result
<Self> {
743 let group
= private
::parse_group(input
)?
;
745 group_token
: group
.token
,
746 elem
: group
.content
.parse()?
,
751 impl Parse
for TypeParen
{
752 fn parse(input
: ParseStream
) -> Result
<Self> {
753 Self::parse(input
, false)
758 fn parse(input
: ParseStream
, allow_plus
: bool
) -> Result
<Self> {
761 paren_token
: parenthesized
!(content
in input
),
762 elem
: Box
::new(ambig_ty(&content
, allow_plus
)?
),
767 impl Parse
for BareFnArg
{
768 fn parse(input
: ParseStream
) -> Result
<Self> {
771 if (input
.peek(Ident
) || input
.peek(Token
![_
]))
772 && !input
.peek2(Token
![::])
773 && input
.peek2(Token
![:])
775 let name
: BareFnArgName
= input
.parse()?
;
776 let colon
: Token
![:] = input
.parse()?
;
787 impl Parse
for BareFnArgName
{
788 fn parse(input
: ParseStream
) -> Result
<Self> {
789 let lookahead
= input
.lookahead1();
790 if lookahead
.peek(Ident
) {
791 input
.parse().map(BareFnArgName
::Named
)
792 } else if lookahead
.peek(Token
![_
]) {
793 input
.parse().map(BareFnArgName
::Wild
)
795 Err(lookahead
.error())
801 fn parse(input
: ParseStream
) -> Result
<Self> {
803 extern_token
: input
.parse()?
,
804 name
: input
.parse()?
,
809 impl Parse
for Option
<Abi
> {
810 fn parse(input
: ParseStream
) -> Result
<Self> {
811 if input
.peek(Token
![extern]) {
812 input
.parse().map(Some
)
820 #[cfg(feature = "printing")]
824 use proc_macro2
::TokenStream
;
827 use print
::TokensOrDefault
;
829 impl ToTokens
for TypeSlice
{
830 fn to_tokens(&self, tokens
: &mut TokenStream
) {
831 self.bracket_token
.surround(tokens
, |tokens
| {
832 self.elem
.to_tokens(tokens
);
837 impl ToTokens
for TypeArray
{
838 fn to_tokens(&self, tokens
: &mut TokenStream
) {
839 self.bracket_token
.surround(tokens
, |tokens
| {
840 self.elem
.to_tokens(tokens
);
841 self.semi_token
.to_tokens(tokens
);
842 self.len
.to_tokens(tokens
);
847 impl ToTokens
for TypePtr
{
848 fn to_tokens(&self, tokens
: &mut TokenStream
) {
849 self.star_token
.to_tokens(tokens
);
850 match self.mutability
{
851 Some(ref tok
) => tok
.to_tokens(tokens
),
853 TokensOrDefault(&self.const_token
).to_tokens(tokens
);
856 self.elem
.to_tokens(tokens
);
860 impl ToTokens
for TypeReference
{
861 fn to_tokens(&self, tokens
: &mut TokenStream
) {
862 self.and_token
.to_tokens(tokens
);
863 self.lifetime
.to_tokens(tokens
);
864 self.mutability
.to_tokens(tokens
);
865 self.elem
.to_tokens(tokens
);
869 impl ToTokens
for TypeBareFn
{
870 fn to_tokens(&self, tokens
: &mut TokenStream
) {
871 self.lifetimes
.to_tokens(tokens
);
872 self.unsafety
.to_tokens(tokens
);
873 self.abi
.to_tokens(tokens
);
874 self.fn_token
.to_tokens(tokens
);
875 self.paren_token
.surround(tokens
, |tokens
| {
876 self.inputs
.to_tokens(tokens
);
877 if let Some(ref variadic
) = self.variadic
{
878 if !self.inputs
.empty_or_trailing() {
879 let span
= variadic
.spans
[0];
880 Token
![,](span
).to_tokens(tokens
);
882 variadic
.to_tokens(tokens
);
885 self.output
.to_tokens(tokens
);
889 impl ToTokens
for TypeNever
{
890 fn to_tokens(&self, tokens
: &mut TokenStream
) {
891 self.bang_token
.to_tokens(tokens
);
895 impl ToTokens
for TypeTuple
{
896 fn to_tokens(&self, tokens
: &mut TokenStream
) {
897 self.paren_token
.surround(tokens
, |tokens
| {
898 self.elems
.to_tokens(tokens
);
903 impl ToTokens
for TypePath
{
904 fn to_tokens(&self, tokens
: &mut TokenStream
) {
905 private
::print_path(tokens
, &self.qself
, &self.path
);
909 impl ToTokens
for TypeTraitObject
{
910 fn to_tokens(&self, tokens
: &mut TokenStream
) {
911 self.dyn_token
.to_tokens(tokens
);
912 self.bounds
.to_tokens(tokens
);
916 impl ToTokens
for TypeImplTrait
{
917 fn to_tokens(&self, tokens
: &mut TokenStream
) {
918 self.impl_token
.to_tokens(tokens
);
919 self.bounds
.to_tokens(tokens
);
923 impl ToTokens
for TypeGroup
{
924 fn to_tokens(&self, tokens
: &mut TokenStream
) {
925 self.group_token
.surround(tokens
, |tokens
| {
926 self.elem
.to_tokens(tokens
);
931 impl ToTokens
for TypeParen
{
932 fn to_tokens(&self, tokens
: &mut TokenStream
) {
933 self.paren_token
.surround(tokens
, |tokens
| {
934 self.elem
.to_tokens(tokens
);
939 impl ToTokens
for TypeInfer
{
940 fn to_tokens(&self, tokens
: &mut TokenStream
) {
941 self.underscore_token
.to_tokens(tokens
);
945 impl ToTokens
for TypeMacro
{
946 fn to_tokens(&self, tokens
: &mut TokenStream
) {
947 self.mac
.to_tokens(tokens
);
951 impl ToTokens
for TypeVerbatim
{
952 fn to_tokens(&self, tokens
: &mut TokenStream
) {
953 self.tts
.to_tokens(tokens
);
957 impl ToTokens
for ReturnType
{
958 fn to_tokens(&self, tokens
: &mut TokenStream
) {
960 ReturnType
::Default
=> {}
961 ReturnType
::Type(ref arrow
, ref ty
) => {
962 arrow
.to_tokens(tokens
);
963 ty
.to_tokens(tokens
);
969 impl ToTokens
for BareFnArg
{
970 fn to_tokens(&self, tokens
: &mut TokenStream
) {
971 if let Some((ref name
, ref colon
)) = self.name
{
972 name
.to_tokens(tokens
);
973 colon
.to_tokens(tokens
);
975 self.ty
.to_tokens(tokens
);
979 impl ToTokens
for BareFnArgName
{
980 fn to_tokens(&self, tokens
: &mut TokenStream
) {
982 BareFnArgName
::Named(ref t
) => t
.to_tokens(tokens
),
983 BareFnArgName
::Wild(ref t
) => t
.to_tokens(tokens
),
988 impl ToTokens
for Abi
{
989 fn to_tokens(&self, tokens
: &mut TokenStream
) {
990 self.extern_token
.to_tokens(tokens
);
991 self.name
.to_tokens(tokens
);