1 #![allow(clippy::uninlined_format_args)]
6 use proc_macro2
::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}
;
12 syn
::parse_str
::<Type
>("fn(mut self)").unwrap();
13 syn
::parse_str
::<Type
>("fn(mut self,)").unwrap();
14 syn
::parse_str
::<Type
>("fn(mut self: ())").unwrap();
15 syn
::parse_str
::<Type
>("fn(mut self: ...)").unwrap_err();
16 syn
::parse_str
::<Type
>("fn(mut self: mut self)").unwrap_err();
17 syn
::parse_str
::<Type
>("fn(mut self::T)").unwrap_err();
21 fn test_macro_variable_type() {
22 // mimics the token stream corresponding to `$ty<T>`
23 let tokens
= TokenStream
::from_iter(vec
![
24 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { ty }
)),
25 TokenTree
::Punct(Punct
::new('
<'
, Spacing
::Alone
)),
26 TokenTree
::Ident(Ident
::new("T", Span
::call_site())),
27 TokenTree
::Punct(Punct
::new('
>'
, Spacing
::Alone
)),
30 snapshot
!(tokens
as Type
, @r
###"
36 arguments: PathArguments::AngleBracketed {
38 GenericArgument::Type(Type::Path {
55 // mimics the token stream corresponding to `$ty::<T>`
56 let tokens
= TokenStream
::from_iter(vec
![
57 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { ty }
)),
58 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
59 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
60 TokenTree
::Punct(Punct
::new('
<'
, Spacing
::Alone
)),
61 TokenTree
::Ident(Ident
::new("T", Span
::call_site())),
62 TokenTree
::Punct(Punct
::new('
>'
, Spacing
::Alone
)),
65 snapshot
!(tokens
as Type
, @r
###"
71 arguments: PathArguments::AngleBracketed {
74 GenericArgument::Type(Type::Path {
93 fn test_group_angle_brackets() {
94 // mimics the token stream corresponding to `Option<$ty>`
95 let tokens
= TokenStream
::from_iter(vec
![
96 TokenTree
::Ident(Ident
::new("Option", Span
::call_site())),
97 TokenTree
::Punct(Punct
::new('
<'
, Spacing
::Alone
)),
98 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { Vec<u8> }
)),
99 TokenTree
::Punct(Punct
::new('
>'
, Spacing
::Alone
)),
102 snapshot
!(tokens
as Type
, @r
###"
108 arguments: PathArguments::AngleBracketed {
110 GenericArgument::Type(Type::Group {
116 arguments: PathArguments::AngleBracketed {
118 GenericArgument::Type(Type::Path {
144 fn test_group_colons() {
145 // mimics the token stream corresponding to `$ty::Item`
146 let tokens
= TokenStream
::from_iter(vec
![
147 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { Vec<u8> }
)),
148 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
149 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
150 TokenTree
::Ident(Ident
::new("Item", Span
::call_site())),
153 snapshot
!(tokens
as Type
, @r
###"
159 arguments: PathArguments::AngleBracketed {
161 GenericArgument::Type(Type::Path {
181 let tokens
= TokenStream
::from_iter(vec
![
182 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { [T] }
)),
183 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
184 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
185 TokenTree
::Ident(Ident
::new("Element", Span
::call_site())),
188 snapshot
!(tokens
as Type
, @r
###"
217 fn test_trait_object() {
218 let tokens
= quote
!(dyn for<'a
> Trait
<'a
> + '
static);
219 snapshot
!(tokens
as Type
, @r
###"
223 TypeParamBound::Trait(TraitBound {
224 lifetimes: Some(BoundLifetimes {
226 GenericParam::Lifetime(LifetimeParam {
237 arguments: PathArguments::AngleBracketed {
239 GenericArgument::Lifetime(Lifetime {
248 TypeParamBound::Lifetime {
255 let tokens
= quote
!(dyn 'a
+ Trait
);
256 snapshot
!(tokens
as Type
, @r
###"
260 TypeParamBound::Lifetime {
263 TypeParamBound::Trait(TraitBound {
276 // None of the following are valid Rust types.
277 syn
::parse_str
::<Type
>("for<'a> dyn Trait<'a>").unwrap_err();
278 syn
::parse_str
::<Type
>("dyn for<'a> 'a + Trait").unwrap_err();
282 fn test_trailing_plus() {
284 let tokens
= quote
!(impl Trait
+);
285 snapshot
!(tokens
as Type
, @r
###"
288 TypeParamBound::Trait(TraitBound {
302 let tokens
= quote
!(dyn Trait
+);
303 snapshot
!(tokens
as Type
, @r
###"
307 TypeParamBound::Trait(TraitBound {
321 let tokens
= quote
!(Trait
+);
322 snapshot
!(tokens
as Type
, @r
###"
325 TypeParamBound::Trait(TraitBound {