• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(
2     clippy::elidable_lifetime_names,
3     clippy::needless_lifetimes,
4     clippy::uninlined_format_args
5 )]
6 
7 #[macro_use]
8 mod macros;
9 
10 use syn::{parse_quote, TraitItemFn};
11 
12 #[test]
test_by_value()13 fn test_by_value() {
14     let TraitItemFn { sig, .. } = parse_quote! {
15         fn by_value(self: Self);
16     };
17     snapshot!(&sig.inputs[0], @r#"
18     FnArg::Receiver(Receiver {
19         colon_token: Some,
20         ty: Type::Path {
21             path: Path {
22                 segments: [
23                     PathSegment {
24                         ident: "Self",
25                     },
26                 ],
27             },
28         },
29     })
30     "#);
31 }
32 
33 #[test]
test_by_mut_value()34 fn test_by_mut_value() {
35     let TraitItemFn { sig, .. } = parse_quote! {
36         fn by_mut(mut self: Self);
37     };
38     snapshot!(&sig.inputs[0], @r#"
39     FnArg::Receiver(Receiver {
40         mutability: Some,
41         colon_token: Some,
42         ty: Type::Path {
43             path: Path {
44                 segments: [
45                     PathSegment {
46                         ident: "Self",
47                     },
48                 ],
49             },
50         },
51     })
52     "#);
53 }
54 
55 #[test]
test_by_ref()56 fn test_by_ref() {
57     let TraitItemFn { sig, .. } = parse_quote! {
58         fn by_ref(self: &Self);
59     };
60     snapshot!(&sig.inputs[0], @r#"
61     FnArg::Receiver(Receiver {
62         colon_token: Some,
63         ty: Type::Reference {
64             elem: Type::Path {
65                 path: Path {
66                     segments: [
67                         PathSegment {
68                             ident: "Self",
69                         },
70                     ],
71                 },
72             },
73         },
74     })
75     "#);
76 }
77 
78 #[test]
test_by_box()79 fn test_by_box() {
80     let TraitItemFn { sig, .. } = parse_quote! {
81         fn by_box(self: Box<Self>);
82     };
83     snapshot!(&sig.inputs[0], @r#"
84     FnArg::Receiver(Receiver {
85         colon_token: Some,
86         ty: Type::Path {
87             path: Path {
88                 segments: [
89                     PathSegment {
90                         ident: "Box",
91                         arguments: PathArguments::AngleBracketed {
92                             args: [
93                                 GenericArgument::Type(Type::Path {
94                                     path: Path {
95                                         segments: [
96                                             PathSegment {
97                                                 ident: "Self",
98                                             },
99                                         ],
100                                     },
101                                 }),
102                             ],
103                         },
104                     },
105                 ],
106             },
107         },
108     })
109     "#);
110 }
111 
112 #[test]
test_by_pin()113 fn test_by_pin() {
114     let TraitItemFn { sig, .. } = parse_quote! {
115         fn by_pin(self: Pin<Self>);
116     };
117     snapshot!(&sig.inputs[0], @r#"
118     FnArg::Receiver(Receiver {
119         colon_token: Some,
120         ty: Type::Path {
121             path: Path {
122                 segments: [
123                     PathSegment {
124                         ident: "Pin",
125                         arguments: PathArguments::AngleBracketed {
126                             args: [
127                                 GenericArgument::Type(Type::Path {
128                                     path: Path {
129                                         segments: [
130                                             PathSegment {
131                                                 ident: "Self",
132                                             },
133                                         ],
134                                     },
135                                 }),
136                             ],
137                         },
138                     },
139                 ],
140             },
141         },
142     })
143     "#);
144 }
145 
146 #[test]
test_explicit_type()147 fn test_explicit_type() {
148     let TraitItemFn { sig, .. } = parse_quote! {
149         fn explicit_type(self: Pin<MyType>);
150     };
151     snapshot!(&sig.inputs[0], @r#"
152     FnArg::Receiver(Receiver {
153         colon_token: Some,
154         ty: Type::Path {
155             path: Path {
156                 segments: [
157                     PathSegment {
158                         ident: "Pin",
159                         arguments: PathArguments::AngleBracketed {
160                             args: [
161                                 GenericArgument::Type(Type::Path {
162                                     path: Path {
163                                         segments: [
164                                             PathSegment {
165                                                 ident: "MyType",
166                                             },
167                                         ],
168                                     },
169                                 }),
170                             ],
171                         },
172                     },
173                 ],
174             },
175         },
176     })
177     "#);
178 }
179 
180 #[test]
test_value_shorthand()181 fn test_value_shorthand() {
182     let TraitItemFn { sig, .. } = parse_quote! {
183         fn value_shorthand(self);
184     };
185     snapshot!(&sig.inputs[0], @r#"
186     FnArg::Receiver(Receiver {
187         ty: Type::Path {
188             path: Path {
189                 segments: [
190                     PathSegment {
191                         ident: "Self",
192                     },
193                 ],
194             },
195         },
196     })
197     "#);
198 }
199 
200 #[test]
test_mut_value_shorthand()201 fn test_mut_value_shorthand() {
202     let TraitItemFn { sig, .. } = parse_quote! {
203         fn mut_value_shorthand(mut self);
204     };
205     snapshot!(&sig.inputs[0], @r#"
206     FnArg::Receiver(Receiver {
207         mutability: Some,
208         ty: Type::Path {
209             path: Path {
210                 segments: [
211                     PathSegment {
212                         ident: "Self",
213                     },
214                 ],
215             },
216         },
217     })
218     "#);
219 }
220 
221 #[test]
test_ref_shorthand()222 fn test_ref_shorthand() {
223     let TraitItemFn { sig, .. } = parse_quote! {
224         fn ref_shorthand(&self);
225     };
226     snapshot!(&sig.inputs[0], @r#"
227     FnArg::Receiver(Receiver {
228         reference: Some(None),
229         ty: Type::Reference {
230             elem: Type::Path {
231                 path: Path {
232                     segments: [
233                         PathSegment {
234                             ident: "Self",
235                         },
236                     ],
237                 },
238             },
239         },
240     })
241     "#);
242 }
243 
244 #[test]
test_ref_shorthand_with_lifetime()245 fn test_ref_shorthand_with_lifetime() {
246     let TraitItemFn { sig, .. } = parse_quote! {
247         fn ref_shorthand(&'a self);
248     };
249     snapshot!(&sig.inputs[0], @r#"
250     FnArg::Receiver(Receiver {
251         reference: Some(Some(Lifetime {
252             ident: "a",
253         })),
254         ty: Type::Reference {
255             lifetime: Some(Lifetime {
256                 ident: "a",
257             }),
258             elem: Type::Path {
259                 path: Path {
260                     segments: [
261                         PathSegment {
262                             ident: "Self",
263                         },
264                     ],
265                 },
266             },
267         },
268     })
269     "#);
270 }
271 
272 #[test]
test_ref_mut_shorthand()273 fn test_ref_mut_shorthand() {
274     let TraitItemFn { sig, .. } = parse_quote! {
275         fn ref_mut_shorthand(&mut self);
276     };
277     snapshot!(&sig.inputs[0], @r#"
278     FnArg::Receiver(Receiver {
279         reference: Some(None),
280         mutability: Some,
281         ty: Type::Reference {
282             mutability: Some,
283             elem: Type::Path {
284                 path: Path {
285                     segments: [
286                         PathSegment {
287                             ident: "Self",
288                         },
289                     ],
290                 },
291             },
292         },
293     })
294     "#);
295 }
296 
297 #[test]
test_ref_mut_shorthand_with_lifetime()298 fn test_ref_mut_shorthand_with_lifetime() {
299     let TraitItemFn { sig, .. } = parse_quote! {
300         fn ref_mut_shorthand(&'a mut self);
301     };
302     snapshot!(&sig.inputs[0], @r#"
303     FnArg::Receiver(Receiver {
304         reference: Some(Some(Lifetime {
305             ident: "a",
306         })),
307         mutability: Some,
308         ty: Type::Reference {
309             lifetime: Some(Lifetime {
310                 ident: "a",
311             }),
312             mutability: Some,
313             elem: Type::Path {
314                 path: Path {
315                     segments: [
316                         PathSegment {
317                             ident: "Self",
318                         },
319                     ],
320                 },
321             },
322         },
323     })
324     "#);
325 }
326