blob: 321fb1a3de19a81247280498cbdf16d6dc153f9e [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001use crate::syntax::atom::Atom::{self, *};
David Tolnayd763f4c2020-04-22 16:09:19 -07002use crate::syntax::{
Joel Galensonc03402a2020-04-23 17:31:09 -07003 error, ident, Api, Enum, ExternFn, ExternType, Lang, Receiver, Ref, Slice, Struct, Ty1, Type,
4 Types,
David Tolnayd763f4c2020-04-22 16:09:19 -07005};
David Tolnay09462ac2020-03-20 14:58:41 -07006use proc_macro2::{Delimiter, Group, Ident, TokenStream};
David Tolnaya420f012020-03-25 17:55:56 -07007use quote::{quote, ToTokens};
Joel Galensonc03402a2020-04-23 17:31:09 -07008use std::collections::HashSet;
David Tolnaya420f012020-03-25 17:55:56 -07009use std::fmt::Display;
David Tolnay7db73692019-10-20 14:51:12 -040010use syn::{Error, Result};
11
David Tolnay26a2a1d2020-03-25 17:26:43 -070012struct Check<'a> {
13 apis: &'a [Api],
14 types: &'a Types<'a>,
15 errors: &'a mut Vec<Error>,
16}
17
David Tolnay7db73692019-10-20 14:51:12 -040018pub(crate) fn typecheck(apis: &[Api], types: &Types) -> Result<()> {
David Tolnay26a2a1d2020-03-25 17:26:43 -070019 let mut errors = Vec::new();
20 let mut cx = Check {
21 apis,
22 types,
23 errors: &mut errors,
24 };
25 do_typecheck(&mut cx);
26 combine_errors(errors)
27}
David Tolnay7db73692019-10-20 14:51:12 -040028
David Tolnay26a2a1d2020-03-25 17:26:43 -070029fn do_typecheck(cx: &mut Check) {
30 for ty in cx.types {
David Tolnay7db73692019-10-20 14:51:12 -040031 match ty {
David Tolnay26a2a1d2020-03-25 17:26:43 -070032 Type::Ident(ident) => check_type_ident(cx, ident),
33 Type::RustBox(ptr) => check_type_box(cx, ptr),
David Tolnayc6d891e2020-04-25 12:06:34 -070034 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070035 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
David Tolnayfff4c8a2020-04-25 11:45:20 -070036 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
David Tolnay26a2a1d2020-03-25 17:26:43 -070037 Type::Ref(ty) => check_type_ref(cx, ty),
David Tolnayeebe9b72020-04-14 16:32:18 -070038 Type::Slice(ty) => check_type_slice(cx, ty),
David Tolnay7db73692019-10-20 14:51:12 -040039 _ => {}
40 }
41 }
42
David Tolnay26a2a1d2020-03-25 17:26:43 -070043 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040044 match api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070045 Api::Struct(strct) => check_api_struct(cx, strct),
Joel Galensonc03402a2020-04-23 17:31:09 -070046 Api::Enum(enm) => check_api_enum(cx, enm),
David Tolnay0b368ae2020-04-22 17:55:02 -070047 Api::CxxType(ty) | Api::RustType(ty) => check_api_type(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070048 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
David Tolnay7db73692019-10-20 14:51:12 -040049 _ => {}
50 }
51 }
52
David Tolnay26a2a1d2020-03-25 17:26:43 -070053 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040054 if let Api::CxxFunction(efn) = api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070055 check_mut_return_restriction(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -040056 }
57 if let Api::CxxFunction(efn) | Api::RustFunction(efn) = api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070058 check_multiple_arg_lifetimes(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -040059 }
60 }
61
David Tolnay26a2a1d2020-03-25 17:26:43 -070062 ident::check_all(cx.apis, cx.errors);
David Tolnay7db73692019-10-20 14:51:12 -040063}
64
David Tolnaya420f012020-03-25 17:55:56 -070065impl Check<'_> {
66 fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
67 self.errors.push(Error::new_spanned(sp, msg));
68 }
69}
70
David Tolnay26a2a1d2020-03-25 17:26:43 -070071fn check_type_ident(cx: &mut Check, ident: &Ident) {
David Tolnayd4e68302020-03-25 12:04:17 -070072 if Atom::from(ident).is_none()
David Tolnay26a2a1d2020-03-25 17:26:43 -070073 && !cx.types.structs.contains_key(ident)
Joel Galensonc03402a2020-04-23 17:31:09 -070074 && !cx.types.enums.contains_key(ident)
David Tolnay26a2a1d2020-03-25 17:26:43 -070075 && !cx.types.cxx.contains(ident)
76 && !cx.types.rust.contains(ident)
David Tolnayd4e68302020-03-25 12:04:17 -070077 {
David Tolnaya420f012020-03-25 17:55:56 -070078 cx.error(ident, "unsupported type");
David Tolnayd4e68302020-03-25 12:04:17 -070079 }
80}
81
David Tolnay26a2a1d2020-03-25 17:26:43 -070082fn check_type_box(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -070083 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -070084 if cx.types.cxx.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -070085 cx.error(ptr, error::BOX_CXX_TYPE.msg);
David Tolnayd4e68302020-03-25 12:04:17 -070086 }
David Tolnaya420f012020-03-25 17:55:56 -070087
David Tolnayd4e68302020-03-25 12:04:17 -070088 if Atom::from(ident).is_none() {
89 return;
90 }
91 }
David Tolnaya420f012020-03-25 17:55:56 -070092
93 cx.error(ptr, "unsupported target type of Box");
David Tolnayd4e68302020-03-25 12:04:17 -070094}
95
David Tolnayc6d891e2020-04-25 12:06:34 -070096fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
97 if let Type::Ident(ident) = &ty.inner {
98 if cx.types.cxx.contains(ident) {
99 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
Myron Ahneba35cf2020-02-05 19:41:51 +0700100 return;
David Tolnayc6d891e2020-04-25 12:06:34 -0700101 }
102
103 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700104 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
105 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
106 Some(Bool) | Some(RustString) => { /* todo */ }
107 Some(CxxString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700108 }
109 }
110
David Tolnayc6d891e2020-04-25 12:06:34 -0700111 cx.error(ty, "unsupported element type of Vec");
Myron Ahneba35cf2020-02-05 19:41:51 +0700112}
113
David Tolnay26a2a1d2020-03-25 17:26:43 -0700114fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -0700115 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700116 if cx.types.rust.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -0700117 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
David Tolnayd4e68302020-03-25 12:04:17 -0700118 }
David Tolnaya420f012020-03-25 17:55:56 -0700119
David Tolnayd4e68302020-03-25 12:04:17 -0700120 match Atom::from(ident) {
121 None | Some(CxxString) => return,
122 _ => {}
123 }
David Tolnay4377a9e2020-04-24 15:20:26 -0700124 } else if let Type::CxxVector(_) = &ptr.inner {
Myron Ahneba35cf2020-02-05 19:41:51 +0700125 return;
David Tolnayd4e68302020-03-25 12:04:17 -0700126 }
David Tolnaya420f012020-03-25 17:55:56 -0700127
128 cx.error(ptr, "unsupported unique_ptr target type");
David Tolnayd4e68302020-03-25 12:04:17 -0700129}
130
David Tolnayfff4c8a2020-04-25 11:45:20 -0700131fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
Myron Ahneba35cf2020-02-05 19:41:51 +0700132 if let Type::Ident(ident) = &ptr.inner {
133 if cx.types.rust.contains(ident) {
David Tolnayc0faaf62020-04-25 12:18:38 -0700134 cx.error(
135 ptr,
136 "C++ vector containing a Rust type is not supported yet",
137 );
Myron Ahneba35cf2020-02-05 19:41:51 +0700138 }
139
140 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700141 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
142 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
143 Some(CxxString) => { /* todo */ }
144 Some(Bool) | Some(RustString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700145 }
146 }
David Tolnayc0faaf62020-04-25 12:18:38 -0700147
Myron Ahneba35cf2020-02-05 19:41:51 +0700148 cx.error(ptr, "unsupported vector target type");
149}
150
David Tolnay26a2a1d2020-03-25 17:26:43 -0700151fn check_type_ref(cx: &mut Check, ty: &Ref) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700152 if ty.lifetime.is_some() {
153 cx.error(ty, "references with explicit lifetimes are not supported");
154 }
155
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700156 match ty.inner {
157 Type::Fn(_) | Type::Void(_) => {}
David Tolnay776fd892020-04-28 13:38:21 -0700158 Type::Ref(_) => {
159 cx.error(ty, "C++ does not allow references to references");
160 return;
161 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700162 _ => return,
David Tolnayd4e68302020-03-25 12:04:17 -0700163 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700164
165 cx.error(ty, "unsupported reference type");
David Tolnayd4e68302020-03-25 12:04:17 -0700166}
167
David Tolnayeebe9b72020-04-14 16:32:18 -0700168fn check_type_slice(cx: &mut Check, ty: &Slice) {
169 cx.error(ty, "only &[u8] is supported so far, not other slice types");
170}
171
David Tolnay26a2a1d2020-03-25 17:26:43 -0700172fn check_api_struct(cx: &mut Check, strct: &Struct) {
David Tolnay0b368ae2020-04-22 17:55:02 -0700173 check_reserved_name(cx, &strct.ident);
174
David Tolnayd4e68302020-03-25 12:04:17 -0700175 if strct.fields.is_empty() {
David Tolnaya420f012020-03-25 17:55:56 -0700176 let span = span_for_struct_error(strct);
177 cx.error(span, "structs without any fields are not supported");
David Tolnayd4e68302020-03-25 12:04:17 -0700178 }
David Tolnaya420f012020-03-25 17:55:56 -0700179
David Tolnayd4e68302020-03-25 12:04:17 -0700180 for field in &strct.fields {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700181 if is_unsized(cx, &field.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700182 let desc = describe(cx, &field.ty);
183 let msg = format!("using {} by value is not supported", desc);
184 cx.error(field, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700185 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700186 if let Type::Fn(_) = field.ty {
187 cx.error(
188 field,
189 "function pointers in a struct field are not implemented yet",
190 );
191 }
David Tolnayd4e68302020-03-25 12:04:17 -0700192 }
193}
194
Joel Galensonc03402a2020-04-23 17:31:09 -0700195fn check_api_enum(cx: &mut Check, enm: &Enum) {
196 check_reserved_name(cx, &enm.ident);
197
198 if enm.variants.is_empty() {
199 let span = span_for_enum_error(enm);
200 cx.error(span, "enums without any variants are not supported");
201 }
202
203 let mut discriminants = HashSet::new();
204 enm.variants.iter().fold(0, |next_discriminant, variant| {
205 let discriminant = match variant.discriminant {
206 None => next_discriminant,
207 Some(val) => val,
208 };
209 if !discriminants.insert(discriminant) {
210 let msg = format!("discriminant value `{}` already exists", discriminant);
211 cx.error(span_for_enum_error(enm), msg);
212 }
213 discriminant + 1
214 });
215}
216
David Tolnay0b368ae2020-04-22 17:55:02 -0700217fn check_api_type(cx: &mut Check, ty: &ExternType) {
218 check_reserved_name(cx, &ty.ident);
219}
220
David Tolnay26a2a1d2020-03-25 17:26:43 -0700221fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700222 if let Some(receiver) = &efn.receiver {
David Tolnaya1f29c42020-04-22 18:01:38 -0700223 let ref span = span_for_receiver_error(receiver);
224
225 if receiver.ty == "Self" {
226 let mutability = match receiver.mutability {
227 Some(_) => "mut ",
228 None => "",
229 };
230 let msg = format!(
231 "unnamed receiver type is only allowed if the surrounding \
232 extern block contains exactly one extern type; \
233 use `self: &{mutability}TheType`",
234 mutability = mutability,
235 );
236 cx.error(span, msg);
237 } else if !cx.types.structs.contains_key(&receiver.ty)
David Tolnay8b60bf12020-04-22 16:52:19 -0700238 && !cx.types.cxx.contains(&receiver.ty)
239 && !cx.types.rust.contains(&receiver.ty)
240 {
David Tolnay8b60bf12020-04-22 16:52:19 -0700241 cx.error(span, "unrecognized receiver type");
242 }
243
David Tolnayd763f4c2020-04-22 16:09:19 -0700244 if receiver.lifetime.is_some() {
David Tolnayd763f4c2020-04-22 16:09:19 -0700245 cx.error(span, "references with explicit lifetimes are not supported");
246 }
247 }
248
David Tolnayd4e68302020-03-25 12:04:17 -0700249 for arg in &efn.args {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700250 if is_unsized(cx, &arg.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700251 let desc = describe(cx, &arg.ty);
252 let msg = format!("passing {} by value is not supported", desc);
253 cx.error(arg, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700254 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700255 if let Type::Fn(_) = arg.ty {
David Tolnay75dca2e2020-03-25 20:17:52 -0700256 if efn.lang == Lang::Rust {
257 cx.error(
258 arg,
259 "passing a function pointer from C++ to Rust is not implemented yet",
260 );
261 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700262 }
David Tolnayd4e68302020-03-25 12:04:17 -0700263 }
David Tolnaya420f012020-03-25 17:55:56 -0700264
David Tolnayd4e68302020-03-25 12:04:17 -0700265 if let Some(ty) = &efn.ret {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700266 if is_unsized(cx, ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700267 let desc = describe(cx, ty);
268 let msg = format!("returning {} by value is not supported", desc);
269 cx.error(ty, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700270 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700271 if let Type::Fn(_) = ty {
272 cx.error(ty, "returning a function pointer is not implemented yet");
273 }
David Tolnayd4e68302020-03-25 12:04:17 -0700274 }
David Tolnay7db73692019-10-20 14:51:12 -0400275}
276
David Tolnay26a2a1d2020-03-25 17:26:43 -0700277fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400278 match &efn.ret {
279 Some(Type::Ref(ty)) if ty.mutability.is_some() => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700280 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400281 }
282
283 for arg in &efn.args {
284 if let Type::Ref(ty) = &arg.ty {
285 if ty.mutability.is_some() {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700286 return;
David Tolnay7db73692019-10-20 14:51:12 -0400287 }
288 }
289 }
290
David Tolnaya420f012020-03-25 17:55:56 -0700291 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400292 efn,
293 "&mut return type is not allowed unless there is a &mut argument",
David Tolnaya420f012020-03-25 17:55:56 -0700294 );
David Tolnay7db73692019-10-20 14:51:12 -0400295}
296
David Tolnay26a2a1d2020-03-25 17:26:43 -0700297fn check_multiple_arg_lifetimes(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400298 match &efn.ret {
299 Some(Type::Ref(_)) => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700300 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400301 }
302
303 let mut reference_args = 0;
304 for arg in &efn.args {
305 if let Type::Ref(_) = &arg.ty {
306 reference_args += 1;
307 }
308 }
309
Joel Galenson3d4f6122020-04-07 15:54:05 -0700310 if efn.receiver.is_some() {
311 reference_args += 1;
312 }
313
David Tolnay26a2a1d2020-03-25 17:26:43 -0700314 if reference_args != 1 {
David Tolnaya420f012020-03-25 17:55:56 -0700315 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400316 efn,
317 "functions that return a reference must take exactly one input reference",
David Tolnaya420f012020-03-25 17:55:56 -0700318 );
David Tolnay7db73692019-10-20 14:51:12 -0400319 }
320}
321
David Tolnay0b368ae2020-04-22 17:55:02 -0700322fn check_reserved_name(cx: &mut Check, ident: &Ident) {
David Tolnay99c93d82020-04-25 14:07:44 -0700323 if ident == "Box"
324 || ident == "UniquePtr"
325 || ident == "Vec"
326 || ident == "CxxVector"
327 || Atom::from(ident).is_some()
328 {
David Tolnay0b368ae2020-04-22 17:55:02 -0700329 cx.error(ident, "reserved name");
330 }
331}
332
David Tolnay26a2a1d2020-03-25 17:26:43 -0700333fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
David Tolnayd4e68302020-03-25 12:04:17 -0700334 let ident = match ty {
335 Type::Ident(ident) => ident,
David Tolnaye70303c2020-04-25 15:02:37 -0700336 Type::CxxVector(_) | Type::Slice(_) | Type::Void(_) => return true,
David Tolnayd4e68302020-03-25 12:04:17 -0700337 _ => return false,
338 };
David Tolnay26a2a1d2020-03-25 17:26:43 -0700339 ident == CxxString || cx.types.cxx.contains(ident) || cx.types.rust.contains(ident)
340}
341
David Tolnaya420f012020-03-25 17:55:56 -0700342fn span_for_struct_error(strct: &Struct) -> TokenStream {
343 let struct_token = strct.struct_token;
344 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
345 brace_token.set_span(strct.brace_token.span);
346 quote!(#struct_token #brace_token)
347}
348
Joel Galensonc03402a2020-04-23 17:31:09 -0700349fn span_for_enum_error(enm: &Enum) -> TokenStream {
350 let enum_token = enm.enum_token;
351 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
352 brace_token.set_span(enm.brace_token.span);
353 quote!(#enum_token #brace_token)
354}
355
David Tolnayd763f4c2020-04-22 16:09:19 -0700356fn span_for_receiver_error(receiver: &Receiver) -> TokenStream {
357 let ampersand = receiver.ampersand;
358 let lifetime = &receiver.lifetime;
359 let mutability = receiver.mutability;
360 if receiver.shorthand {
361 let var = receiver.var;
362 quote!(#ampersand #lifetime #mutability #var)
363 } else {
364 let ty = &receiver.ty;
365 quote!(#ampersand #lifetime #mutability #ty)
366 }
367}
368
David Tolnay26a2a1d2020-03-25 17:26:43 -0700369fn combine_errors(errors: Vec<Error>) -> Result<()> {
370 let mut iter = errors.into_iter();
371 let mut all_errors = match iter.next() {
372 Some(err) => err,
373 None => return Ok(()),
374 };
375 for err in iter {
376 all_errors.combine(err);
377 }
378 Err(all_errors)
David Tolnayd4e68302020-03-25 12:04:17 -0700379}
380
David Tolnaya420f012020-03-25 17:55:56 -0700381fn describe(cx: &mut Check, ty: &Type) -> String {
David Tolnay7db73692019-10-20 14:51:12 -0400382 match ty {
383 Type::Ident(ident) => {
David Tolnaya420f012020-03-25 17:55:56 -0700384 if cx.types.structs.contains_key(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400385 "struct".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700386 } else if cx.types.cxx.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400387 "C++ type".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700388 } else if cx.types.rust.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400389 "opaque Rust type".to_owned()
390 } else if Atom::from(ident) == Some(CxxString) {
391 "C++ string".to_owned()
392 } else {
393 ident.to_string()
394 }
395 }
396 Type::RustBox(_) => "Box".to_owned(),
Myron Ahneba35cf2020-02-05 19:41:51 +0700397 Type::RustVec(_) => "Vec".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400398 Type::UniquePtr(_) => "unique_ptr".to_owned(),
399 Type::Ref(_) => "reference".to_owned(),
400 Type::Str(_) => "&str".to_owned(),
David Tolnayfa85fce2020-04-25 15:03:25 -0700401 Type::CxxVector(_) => "C++ vector".to_owned(),
Adrian Taylorf5dd5522020-04-13 16:50:14 -0700402 Type::Slice(_) => "slice".to_owned(),
403 Type::SliceRefU8(_) => "&[u8]".to_owned(),
David Tolnay417305a2020-03-18 13:54:00 -0700404 Type::Fn(_) => "function pointer".to_owned(),
David Tolnay2fb14e92020-03-15 23:11:38 -0700405 Type::Void(_) => "()".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400406 }
407}