1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
mod features;
use syn::{FnArg, Receiver, TraitItemMethod};
#[test]
fn test_by_value() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn by_value(self: Self););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_by_mut_value() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn by_mut(mut self: Self););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_by_ref() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn by_ref(self: &Self););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_by_box() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn by_box(self: Box<Self>););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_by_pin() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn by_pin(self: Pin<Self>););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_explicit_type() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn explicit_type(self: Pin<MyType>););
match sig.receiver() {
Some(FnArg::Typed(_)) => (),
value => panic!("expected FnArg::Typed, got {:?}", value),
}
}
#[test]
fn test_value_shorthand() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn value_shorthand(self););
match sig.receiver() {
Some(FnArg::Receiver(Receiver {
reference: None,
mutability: None,
..
})) => (),
value => panic!("expected FnArg::Receiver without ref/mut, got {:?}", value),
}
}
#[test]
fn test_mut_value_shorthand() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn mut_value_shorthand(mut self););
match sig.receiver() {
Some(FnArg::Receiver(Receiver {
reference: None,
mutability: Some(_),
..
})) => (),
value => panic!("expected FnArg::Receiver with mut, got {:?}", value),
}
}
#[test]
fn test_ref_shorthand() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn ref_shorthand(&self););
match sig.receiver() {
Some(FnArg::Receiver(Receiver {
reference: Some(_),
mutability: None,
..
})) => (),
value => panic!("expected FnArg::Receiver with ref, got {:?}", value),
}
}
#[test]
fn test_ref_mut_shorthand() {
let TraitItemMethod { sig, .. } = syn::parse_quote!(fn ref_mut_shorthand(&mut self););
match sig.receiver() {
Some(FnArg::Receiver(Receiver {
reference: Some(_),
mutability: Some(_),
..
})) => (),
value => panic!("expected FnArg::Receiver with ref+mut, got {:?}", value),
}
}
|