4 use proc_macro2
::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}
;
6 use std
::iter
::FromIterator
;
11 syn
::parse_str
::<Type
>("fn(mut self)").unwrap();
12 syn
::parse_str
::<Type
>("fn(mut self: ())").unwrap();
13 syn
::parse_str
::<Type
>("fn(mut self: ...)").unwrap_err();
14 syn
::parse_str
::<Type
>("fn(mut self: mut self)").unwrap_err();
15 syn
::parse_str
::<Type
>("fn(mut self::T)").unwrap_err();
19 fn test_macro_variable_type() {
20 // mimics the token stream corresponding to `$ty<T>`
21 let tokens
= TokenStream
::from_iter(vec
![
22 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { ty }
)),
23 TokenTree
::Punct(Punct
::new('
<'
, Spacing
::Alone
)),
24 TokenTree
::Ident(Ident
::new("T", Span
::call_site())),
25 TokenTree
::Punct(Punct
::new('
>'
, Spacing
::Alone
)),
28 snapshot
!(tokens
as Type
, @r
###"
34 arguments: PathArguments::AngleBracketed {
54 // mimics the token stream corresponding to `$ty::<T>`
55 let tokens
= TokenStream
::from_iter(vec
![
56 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { ty }
)),
57 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
58 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
59 TokenTree
::Punct(Punct
::new('
<'
, Spacing
::Alone
)),
60 TokenTree
::Ident(Ident
::new("T", Span
::call_site())),
61 TokenTree
::Punct(Punct
::new('
>'
, Spacing
::Alone
)),
64 snapshot
!(tokens
as Type
, @r
###"
70 arguments: PathArguments::AngleBracketed {
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 {
116 arguments: PathArguments::AngleBracketed {
145 fn test_group_colons() {
146 // mimics the token stream corresponding to `$ty::Item`
147 let tokens
= TokenStream
::from_iter(vec
![
148 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { Vec<u8> }
)),
149 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
150 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
151 TokenTree
::Ident(Ident
::new("Item", Span
::call_site())),
154 snapshot
!(tokens
as Type
, @r
###"
160 arguments: PathArguments::AngleBracketed {
184 let tokens
= TokenStream
::from_iter(vec
![
185 TokenTree
::Group(Group
::new(Delimiter
::None
, quote
! { [T] }
)),
186 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Joint
)),
187 TokenTree
::Punct(Punct
::new('
:'
, Spacing
::Alone
)),
188 TokenTree
::Ident(Ident
::new("Element", Span
::call_site())),
191 snapshot
!(tokens
as Type
, @r
###"