blob: 5d442ce3cc43b9ae5b1717bb977e6b775cfefe78 [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001use crate::syntax::atom::Atom::{self, *};
David Tolnay9dcb8332020-04-30 20:37:33 -07002use crate::syntax::namespace::Namespace;
David Tolnayd763f4c2020-04-22 16:09:19 -07003use crate::syntax::{
Joel Galensonc03402a2020-04-23 17:31:09 -07004 error, ident, Api, Enum, ExternFn, ExternType, Lang, Receiver, Ref, Slice, Struct, Ty1, Type,
5 Types,
David Tolnayd763f4c2020-04-22 16:09:19 -07006};
David Tolnay09462ac2020-03-20 14:58:41 -07007use proc_macro2::{Delimiter, Group, Ident, TokenStream};
David Tolnaya420f012020-03-25 17:55:56 -07008use quote::{quote, ToTokens};
Joel Galensonc03402a2020-04-23 17:31:09 -07009use std::collections::HashSet;
David Tolnaya420f012020-03-25 17:55:56 -070010use std::fmt::Display;
David Tolnay8adb2232020-05-01 10:14:27 -070011use std::u32;
David Tolnay7db73692019-10-20 14:51:12 -040012use syn::{Error, Result};
13
David Tolnaya83301c2020-04-30 20:32:37 -070014pub(crate) struct Check<'a> {
David Tolnay9dcb8332020-04-30 20:37:33 -070015 namespace: &'a Namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070016 apis: &'a [Api],
17 types: &'a Types<'a>,
18 errors: &'a mut Vec<Error>,
19}
20
David Tolnay9dcb8332020-04-30 20:37:33 -070021pub(crate) fn typecheck(namespace: &Namespace, apis: &[Api], types: &Types) -> Result<()> {
David Tolnay26a2a1d2020-03-25 17:26:43 -070022 let mut errors = Vec::new();
23 let mut cx = Check {
David Tolnay9dcb8332020-04-30 20:37:33 -070024 namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070025 apis,
26 types,
27 errors: &mut errors,
28 };
29 do_typecheck(&mut cx);
30 combine_errors(errors)
31}
David Tolnay7db73692019-10-20 14:51:12 -040032
David Tolnay26a2a1d2020-03-25 17:26:43 -070033fn do_typecheck(cx: &mut Check) {
David Tolnay6b6423e2020-04-30 20:46:24 -070034 ident::check_all(cx, cx.namespace, cx.apis);
David Tolnay9dcb8332020-04-30 20:37:33 -070035
David Tolnay26a2a1d2020-03-25 17:26:43 -070036 for ty in cx.types {
David Tolnay7db73692019-10-20 14:51:12 -040037 match ty {
David Tolnay26a2a1d2020-03-25 17:26:43 -070038 Type::Ident(ident) => check_type_ident(cx, ident),
39 Type::RustBox(ptr) => check_type_box(cx, ptr),
David Tolnayc6d891e2020-04-25 12:06:34 -070040 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070041 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
David Tolnayfff4c8a2020-04-25 11:45:20 -070042 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
David Tolnay26a2a1d2020-03-25 17:26:43 -070043 Type::Ref(ty) => check_type_ref(cx, ty),
David Tolnayeebe9b72020-04-14 16:32:18 -070044 Type::Slice(ty) => check_type_slice(cx, ty),
David Tolnay7db73692019-10-20 14:51:12 -040045 _ => {}
46 }
47 }
48
David Tolnay26a2a1d2020-03-25 17:26:43 -070049 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040050 match api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070051 Api::Struct(strct) => check_api_struct(cx, strct),
Joel Galensonc03402a2020-04-23 17:31:09 -070052 Api::Enum(enm) => check_api_enum(cx, enm),
David Tolnay0b368ae2020-04-22 17:55:02 -070053 Api::CxxType(ty) | Api::RustType(ty) => check_api_type(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070054 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
David Tolnay7db73692019-10-20 14:51:12 -040055 _ => {}
56 }
57 }
David Tolnay7db73692019-10-20 14:51:12 -040058}
59
David Tolnaya420f012020-03-25 17:55:56 -070060impl Check<'_> {
David Tolnaya83301c2020-04-30 20:32:37 -070061 pub(crate) fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
David Tolnaya420f012020-03-25 17:55:56 -070062 self.errors.push(Error::new_spanned(sp, msg));
63 }
64}
65
David Tolnay26a2a1d2020-03-25 17:26:43 -070066fn check_type_ident(cx: &mut Check, ident: &Ident) {
David Tolnayd4e68302020-03-25 12:04:17 -070067 if Atom::from(ident).is_none()
David Tolnay26a2a1d2020-03-25 17:26:43 -070068 && !cx.types.structs.contains_key(ident)
Joel Galensonc03402a2020-04-23 17:31:09 -070069 && !cx.types.enums.contains_key(ident)
David Tolnay26a2a1d2020-03-25 17:26:43 -070070 && !cx.types.cxx.contains(ident)
71 && !cx.types.rust.contains(ident)
David Tolnayd4e68302020-03-25 12:04:17 -070072 {
David Tolnaya420f012020-03-25 17:55:56 -070073 cx.error(ident, "unsupported type");
David Tolnayd4e68302020-03-25 12:04:17 -070074 }
75}
76
David Tolnay26a2a1d2020-03-25 17:26:43 -070077fn check_type_box(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -070078 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -070079 if cx.types.cxx.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -070080 cx.error(ptr, error::BOX_CXX_TYPE.msg);
David Tolnayd4e68302020-03-25 12:04:17 -070081 }
David Tolnaya420f012020-03-25 17:55:56 -070082
David Tolnayd4e68302020-03-25 12:04:17 -070083 if Atom::from(ident).is_none() {
84 return;
85 }
86 }
David Tolnaya420f012020-03-25 17:55:56 -070087
88 cx.error(ptr, "unsupported target type of Box");
David Tolnayd4e68302020-03-25 12:04:17 -070089}
90
David Tolnayc6d891e2020-04-25 12:06:34 -070091fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
92 if let Type::Ident(ident) = &ty.inner {
93 if cx.types.cxx.contains(ident) {
94 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
Myron Ahneba35cf2020-02-05 19:41:51 +070095 return;
David Tolnayc6d891e2020-04-25 12:06:34 -070096 }
97
98 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -070099 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
100 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
101 Some(Bool) | Some(RustString) => { /* todo */ }
102 Some(CxxString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700103 }
104 }
105
David Tolnayc6d891e2020-04-25 12:06:34 -0700106 cx.error(ty, "unsupported element type of Vec");
Myron Ahneba35cf2020-02-05 19:41:51 +0700107}
108
David Tolnay26a2a1d2020-03-25 17:26:43 -0700109fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -0700110 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700111 if cx.types.rust.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -0700112 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
David Tolnayd4e68302020-03-25 12:04:17 -0700113 }
David Tolnaya420f012020-03-25 17:55:56 -0700114
David Tolnayd4e68302020-03-25 12:04:17 -0700115 match Atom::from(ident) {
116 None | Some(CxxString) => return,
117 _ => {}
118 }
David Tolnay4377a9e2020-04-24 15:20:26 -0700119 } else if let Type::CxxVector(_) = &ptr.inner {
Myron Ahneba35cf2020-02-05 19:41:51 +0700120 return;
David Tolnayd4e68302020-03-25 12:04:17 -0700121 }
David Tolnaya420f012020-03-25 17:55:56 -0700122
123 cx.error(ptr, "unsupported unique_ptr target type");
David Tolnayd4e68302020-03-25 12:04:17 -0700124}
125
David Tolnayfff4c8a2020-04-25 11:45:20 -0700126fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
Myron Ahneba35cf2020-02-05 19:41:51 +0700127 if let Type::Ident(ident) = &ptr.inner {
128 if cx.types.rust.contains(ident) {
David Tolnayc0faaf62020-04-25 12:18:38 -0700129 cx.error(
130 ptr,
131 "C++ vector containing a Rust type is not supported yet",
132 );
Myron Ahneba35cf2020-02-05 19:41:51 +0700133 }
134
135 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700136 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
137 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
138 Some(CxxString) => { /* todo */ }
139 Some(Bool) | Some(RustString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700140 }
141 }
David Tolnayc0faaf62020-04-25 12:18:38 -0700142
Myron Ahneba35cf2020-02-05 19:41:51 +0700143 cx.error(ptr, "unsupported vector target type");
144}
145
David Tolnay26a2a1d2020-03-25 17:26:43 -0700146fn check_type_ref(cx: &mut Check, ty: &Ref) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700147 if ty.lifetime.is_some() {
148 cx.error(ty, "references with explicit lifetimes are not supported");
149 }
150
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700151 match ty.inner {
152 Type::Fn(_) | Type::Void(_) => {}
David Tolnay776fd892020-04-28 13:38:21 -0700153 Type::Ref(_) => {
154 cx.error(ty, "C++ does not allow references to references");
155 return;
156 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700157 _ => return,
David Tolnayd4e68302020-03-25 12:04:17 -0700158 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700159
160 cx.error(ty, "unsupported reference type");
David Tolnayd4e68302020-03-25 12:04:17 -0700161}
162
David Tolnayeebe9b72020-04-14 16:32:18 -0700163fn check_type_slice(cx: &mut Check, ty: &Slice) {
164 cx.error(ty, "only &[u8] is supported so far, not other slice types");
165}
166
David Tolnay26a2a1d2020-03-25 17:26:43 -0700167fn check_api_struct(cx: &mut Check, strct: &Struct) {
David Tolnay0b368ae2020-04-22 17:55:02 -0700168 check_reserved_name(cx, &strct.ident);
169
David Tolnayd4e68302020-03-25 12:04:17 -0700170 if strct.fields.is_empty() {
David Tolnaya420f012020-03-25 17:55:56 -0700171 let span = span_for_struct_error(strct);
172 cx.error(span, "structs without any fields are not supported");
David Tolnayd4e68302020-03-25 12:04:17 -0700173 }
David Tolnaya420f012020-03-25 17:55:56 -0700174
David Tolnayd4e68302020-03-25 12:04:17 -0700175 for field in &strct.fields {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700176 if is_unsized(cx, &field.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700177 let desc = describe(cx, &field.ty);
178 let msg = format!("using {} by value is not supported", desc);
179 cx.error(field, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700180 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700181 if let Type::Fn(_) = field.ty {
182 cx.error(
183 field,
184 "function pointers in a struct field are not implemented yet",
185 );
186 }
David Tolnayd4e68302020-03-25 12:04:17 -0700187 }
188}
189
Joel Galensonc03402a2020-04-23 17:31:09 -0700190fn check_api_enum(cx: &mut Check, enm: &Enum) {
191 check_reserved_name(cx, &enm.ident);
192
193 if enm.variants.is_empty() {
194 let span = span_for_enum_error(enm);
195 cx.error(span, "enums without any variants are not supported");
196 }
197
198 let mut discriminants = HashSet::new();
Joel Galenson04fa0962020-05-01 10:00:31 -0700199 enm.variants
200 .iter()
201 .fold(None, |prev_discriminant, variant| {
202 if variant.discriminant.is_none() && prev_discriminant.unwrap_or(0) == u32::MAX {
203 let msg = format!("overflowed on value after {}", prev_discriminant.unwrap());
204 cx.error(span_for_enum_error(enm), msg);
205 return None;
206 }
207 let discriminant = variant
208 .discriminant
209 .unwrap_or_else(|| prev_discriminant.map_or(0, |n| n + 1));
210 if !discriminants.insert(discriminant) {
211 let msg = format!("discriminant value `{}` already exists", discriminant);
212 cx.error(span_for_enum_error(enm), msg);
213 }
214 Some(discriminant)
215 });
Joel Galensonc03402a2020-04-23 17:31:09 -0700216}
217
David Tolnay0b368ae2020-04-22 17:55:02 -0700218fn check_api_type(cx: &mut Check, ty: &ExternType) {
219 check_reserved_name(cx, &ty.ident);
220}
221
David Tolnay26a2a1d2020-03-25 17:26:43 -0700222fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700223 if let Some(receiver) = &efn.receiver {
David Tolnaya1f29c42020-04-22 18:01:38 -0700224 let ref span = span_for_receiver_error(receiver);
225
226 if receiver.ty == "Self" {
227 let mutability = match receiver.mutability {
228 Some(_) => "mut ",
229 None => "",
230 };
231 let msg = format!(
232 "unnamed receiver type is only allowed if the surrounding \
233 extern block contains exactly one extern type; \
234 use `self: &{mutability}TheType`",
235 mutability = mutability,
236 );
237 cx.error(span, msg);
238 } else if !cx.types.structs.contains_key(&receiver.ty)
David Tolnay8b60bf12020-04-22 16:52:19 -0700239 && !cx.types.cxx.contains(&receiver.ty)
240 && !cx.types.rust.contains(&receiver.ty)
241 {
David Tolnay8b60bf12020-04-22 16:52:19 -0700242 cx.error(span, "unrecognized receiver type");
243 }
244
David Tolnayd763f4c2020-04-22 16:09:19 -0700245 if receiver.lifetime.is_some() {
David Tolnayd763f4c2020-04-22 16:09:19 -0700246 cx.error(span, "references with explicit lifetimes are not supported");
247 }
248 }
249
David Tolnayd4e68302020-03-25 12:04:17 -0700250 for arg in &efn.args {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700251 if is_unsized(cx, &arg.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700252 let desc = describe(cx, &arg.ty);
253 let msg = format!("passing {} by value is not supported", desc);
254 cx.error(arg, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700255 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700256 if let Type::Fn(_) = arg.ty {
David Tolnay75dca2e2020-03-25 20:17:52 -0700257 if efn.lang == Lang::Rust {
258 cx.error(
259 arg,
260 "passing a function pointer from C++ to Rust is not implemented yet",
261 );
262 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700263 }
David Tolnayd4e68302020-03-25 12:04:17 -0700264 }
David Tolnaya420f012020-03-25 17:55:56 -0700265
David Tolnayd4e68302020-03-25 12:04:17 -0700266 if let Some(ty) = &efn.ret {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700267 if is_unsized(cx, ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700268 let desc = describe(cx, ty);
269 let msg = format!("returning {} by value is not supported", desc);
270 cx.error(ty, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700271 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700272 if let Type::Fn(_) = ty {
273 cx.error(ty, "returning a function pointer is not implemented yet");
274 }
David Tolnayd4e68302020-03-25 12:04:17 -0700275 }
David Tolnay96a826b2020-05-04 00:17:12 -0700276
277 if efn.lang == Lang::Cxx {
278 check_mut_return_restriction(cx, efn);
279 }
280
281 check_multiple_arg_lifetimes(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -0400282}
283
David Tolnay26a2a1d2020-03-25 17:26:43 -0700284fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400285 match &efn.ret {
286 Some(Type::Ref(ty)) if ty.mutability.is_some() => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700287 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400288 }
289
290 for arg in &efn.args {
291 if let Type::Ref(ty) = &arg.ty {
292 if ty.mutability.is_some() {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700293 return;
David Tolnay7db73692019-10-20 14:51:12 -0400294 }
295 }
296 }
297
David Tolnaya420f012020-03-25 17:55:56 -0700298 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400299 efn,
300 "&mut return type is not allowed unless there is a &mut argument",
David Tolnaya420f012020-03-25 17:55:56 -0700301 );
David Tolnay7db73692019-10-20 14:51:12 -0400302}
303
David Tolnay26a2a1d2020-03-25 17:26:43 -0700304fn check_multiple_arg_lifetimes(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400305 match &efn.ret {
306 Some(Type::Ref(_)) => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700307 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400308 }
309
310 let mut reference_args = 0;
311 for arg in &efn.args {
312 if let Type::Ref(_) = &arg.ty {
313 reference_args += 1;
314 }
315 }
316
Joel Galenson3d4f6122020-04-07 15:54:05 -0700317 if efn.receiver.is_some() {
318 reference_args += 1;
319 }
320
David Tolnay26a2a1d2020-03-25 17:26:43 -0700321 if reference_args != 1 {
David Tolnaya420f012020-03-25 17:55:56 -0700322 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400323 efn,
324 "functions that return a reference must take exactly one input reference",
David Tolnaya420f012020-03-25 17:55:56 -0700325 );
David Tolnay7db73692019-10-20 14:51:12 -0400326 }
327}
328
David Tolnay0b368ae2020-04-22 17:55:02 -0700329fn check_reserved_name(cx: &mut Check, ident: &Ident) {
David Tolnay99c93d82020-04-25 14:07:44 -0700330 if ident == "Box"
331 || ident == "UniquePtr"
332 || ident == "Vec"
333 || ident == "CxxVector"
334 || Atom::from(ident).is_some()
335 {
David Tolnay0b368ae2020-04-22 17:55:02 -0700336 cx.error(ident, "reserved name");
337 }
338}
339
David Tolnay26a2a1d2020-03-25 17:26:43 -0700340fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
David Tolnayd4e68302020-03-25 12:04:17 -0700341 let ident = match ty {
342 Type::Ident(ident) => ident,
David Tolnaye70303c2020-04-25 15:02:37 -0700343 Type::CxxVector(_) | Type::Slice(_) | Type::Void(_) => return true,
David Tolnayd4e68302020-03-25 12:04:17 -0700344 _ => return false,
345 };
David Tolnay26a2a1d2020-03-25 17:26:43 -0700346 ident == CxxString || cx.types.cxx.contains(ident) || cx.types.rust.contains(ident)
347}
348
David Tolnaya420f012020-03-25 17:55:56 -0700349fn span_for_struct_error(strct: &Struct) -> TokenStream {
350 let struct_token = strct.struct_token;
351 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
352 brace_token.set_span(strct.brace_token.span);
353 quote!(#struct_token #brace_token)
354}
355
Joel Galensonc03402a2020-04-23 17:31:09 -0700356fn span_for_enum_error(enm: &Enum) -> TokenStream {
357 let enum_token = enm.enum_token;
358 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
359 brace_token.set_span(enm.brace_token.span);
360 quote!(#enum_token #brace_token)
361}
362
David Tolnayd763f4c2020-04-22 16:09:19 -0700363fn span_for_receiver_error(receiver: &Receiver) -> TokenStream {
364 let ampersand = receiver.ampersand;
365 let lifetime = &receiver.lifetime;
366 let mutability = receiver.mutability;
367 if receiver.shorthand {
368 let var = receiver.var;
369 quote!(#ampersand #lifetime #mutability #var)
370 } else {
371 let ty = &receiver.ty;
372 quote!(#ampersand #lifetime #mutability #ty)
373 }
374}
375
David Tolnay26a2a1d2020-03-25 17:26:43 -0700376fn combine_errors(errors: Vec<Error>) -> Result<()> {
377 let mut iter = errors.into_iter();
378 let mut all_errors = match iter.next() {
379 Some(err) => err,
380 None => return Ok(()),
381 };
382 for err in iter {
383 all_errors.combine(err);
384 }
385 Err(all_errors)
David Tolnayd4e68302020-03-25 12:04:17 -0700386}
387
David Tolnaya420f012020-03-25 17:55:56 -0700388fn describe(cx: &mut Check, ty: &Type) -> String {
David Tolnay7db73692019-10-20 14:51:12 -0400389 match ty {
390 Type::Ident(ident) => {
David Tolnaya420f012020-03-25 17:55:56 -0700391 if cx.types.structs.contains_key(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400392 "struct".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700393 } else if cx.types.cxx.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400394 "C++ type".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700395 } else if cx.types.rust.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400396 "opaque Rust type".to_owned()
397 } else if Atom::from(ident) == Some(CxxString) {
398 "C++ string".to_owned()
399 } else {
400 ident.to_string()
401 }
402 }
403 Type::RustBox(_) => "Box".to_owned(),
Myron Ahneba35cf2020-02-05 19:41:51 +0700404 Type::RustVec(_) => "Vec".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400405 Type::UniquePtr(_) => "unique_ptr".to_owned(),
406 Type::Ref(_) => "reference".to_owned(),
407 Type::Str(_) => "&str".to_owned(),
David Tolnayfa85fce2020-04-25 15:03:25 -0700408 Type::CxxVector(_) => "C++ vector".to_owned(),
Adrian Taylorf5dd5522020-04-13 16:50:14 -0700409 Type::Slice(_) => "slice".to_owned(),
410 Type::SliceRefU8(_) => "&[u8]".to_owned(),
David Tolnay417305a2020-03-18 13:54:00 -0700411 Type::Fn(_) => "function pointer".to_owned(),
David Tolnay2fb14e92020-03-15 23:11:38 -0700412 Type::Void(_) => "()".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400413 }
414}