blob: 72b4a6cecc0fbb4579c8e914f4a2bc1051b740db [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 Tolnaydf344a82020-05-03 23:23:18 -07003use crate::syntax::report::Errors;
David Tolnayd763f4c2020-04-22 16:09:19 -07004use crate::syntax::{
Joel Galensonc03402a2020-04-23 17:31:09 -07005 error, ident, Api, Enum, ExternFn, ExternType, Lang, Receiver, Ref, Slice, Struct, Ty1, Type,
6 Types,
David Tolnayd763f4c2020-04-22 16:09:19 -07007};
David Tolnay09462ac2020-03-20 14:58:41 -07008use proc_macro2::{Delimiter, Group, Ident, TokenStream};
David Tolnaya420f012020-03-25 17:55:56 -07009use quote::{quote, ToTokens};
Joel Galensonc03402a2020-04-23 17:31:09 -070010use std::collections::HashSet;
David Tolnaya420f012020-03-25 17:55:56 -070011use std::fmt::Display;
David Tolnay8adb2232020-05-01 10:14:27 -070012use std::u32;
David Tolnay7db73692019-10-20 14:51:12 -040013
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>,
David Tolnaydf344a82020-05-03 23:23:18 -070018 errors: &'a mut Errors,
David Tolnay26a2a1d2020-03-25 17:26:43 -070019}
20
David Tolnay0dd85ff2020-05-03 23:43:33 -070021pub(crate) fn typecheck(cx: &mut Errors, namespace: &Namespace, apis: &[Api], types: &Types) {
22 do_typecheck(&mut Check {
David Tolnay9dcb8332020-04-30 20:37:33 -070023 namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070024 apis,
25 types,
David Tolnay0dd85ff2020-05-03 23:43:33 -070026 errors: cx,
27 });
David Tolnay26a2a1d2020-03-25 17:26:43 -070028}
David Tolnay7db73692019-10-20 14:51:12 -040029
David Tolnay26a2a1d2020-03-25 17:26:43 -070030fn do_typecheck(cx: &mut Check) {
David Tolnay6b6423e2020-04-30 20:46:24 -070031 ident::check_all(cx, cx.namespace, cx.apis);
David Tolnay9dcb8332020-04-30 20:37:33 -070032
David Tolnay26a2a1d2020-03-25 17:26:43 -070033 for ty in cx.types {
David Tolnay7db73692019-10-20 14:51:12 -040034 match ty {
David Tolnay26a2a1d2020-03-25 17:26:43 -070035 Type::Ident(ident) => check_type_ident(cx, ident),
36 Type::RustBox(ptr) => check_type_box(cx, ptr),
David Tolnayc6d891e2020-04-25 12:06:34 -070037 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070038 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
David Tolnayfff4c8a2020-04-25 11:45:20 -070039 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
David Tolnay26a2a1d2020-03-25 17:26:43 -070040 Type::Ref(ty) => check_type_ref(cx, ty),
David Tolnayeebe9b72020-04-14 16:32:18 -070041 Type::Slice(ty) => check_type_slice(cx, ty),
David Tolnay7db73692019-10-20 14:51:12 -040042 _ => {}
43 }
44 }
45
David Tolnay26a2a1d2020-03-25 17:26:43 -070046 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040047 match api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070048 Api::Struct(strct) => check_api_struct(cx, strct),
Joel Galensonc03402a2020-04-23 17:31:09 -070049 Api::Enum(enm) => check_api_enum(cx, enm),
David Tolnay0b368ae2020-04-22 17:55:02 -070050 Api::CxxType(ty) | Api::RustType(ty) => check_api_type(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070051 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
David Tolnay7db73692019-10-20 14:51:12 -040052 _ => {}
53 }
54 }
David Tolnay7db73692019-10-20 14:51:12 -040055}
56
David Tolnaya420f012020-03-25 17:55:56 -070057impl Check<'_> {
David Tolnaya83301c2020-04-30 20:32:37 -070058 pub(crate) fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
David Tolnaydf344a82020-05-03 23:23:18 -070059 self.errors.error(sp, msg);
David Tolnaya420f012020-03-25 17:55:56 -070060 }
61}
62
David Tolnay26a2a1d2020-03-25 17:26:43 -070063fn check_type_ident(cx: &mut Check, ident: &Ident) {
David Tolnayd4e68302020-03-25 12:04:17 -070064 if Atom::from(ident).is_none()
David Tolnay26a2a1d2020-03-25 17:26:43 -070065 && !cx.types.structs.contains_key(ident)
Joel Galensonc03402a2020-04-23 17:31:09 -070066 && !cx.types.enums.contains_key(ident)
David Tolnay26a2a1d2020-03-25 17:26:43 -070067 && !cx.types.cxx.contains(ident)
68 && !cx.types.rust.contains(ident)
David Tolnayd4e68302020-03-25 12:04:17 -070069 {
David Tolnaya420f012020-03-25 17:55:56 -070070 cx.error(ident, "unsupported type");
David Tolnayd4e68302020-03-25 12:04:17 -070071 }
72}
73
David Tolnay26a2a1d2020-03-25 17:26:43 -070074fn check_type_box(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -070075 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -070076 if cx.types.cxx.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -070077 cx.error(ptr, error::BOX_CXX_TYPE.msg);
David Tolnayd4e68302020-03-25 12:04:17 -070078 }
David Tolnaya420f012020-03-25 17:55:56 -070079
David Tolnayd4e68302020-03-25 12:04:17 -070080 if Atom::from(ident).is_none() {
81 return;
82 }
83 }
David Tolnaya420f012020-03-25 17:55:56 -070084
85 cx.error(ptr, "unsupported target type of Box");
David Tolnayd4e68302020-03-25 12:04:17 -070086}
87
David Tolnayc6d891e2020-04-25 12:06:34 -070088fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
89 if let Type::Ident(ident) = &ty.inner {
90 if cx.types.cxx.contains(ident) {
91 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
Myron Ahneba35cf2020-02-05 19:41:51 +070092 return;
David Tolnayc6d891e2020-04-25 12:06:34 -070093 }
94
95 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -070096 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
97 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
98 Some(Bool) | Some(RustString) => { /* todo */ }
99 Some(CxxString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700100 }
101 }
102
David Tolnayc6d891e2020-04-25 12:06:34 -0700103 cx.error(ty, "unsupported element type of Vec");
Myron Ahneba35cf2020-02-05 19:41:51 +0700104}
105
David Tolnay26a2a1d2020-03-25 17:26:43 -0700106fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -0700107 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700108 if cx.types.rust.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -0700109 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
David Tolnayd4e68302020-03-25 12:04:17 -0700110 }
David Tolnaya420f012020-03-25 17:55:56 -0700111
David Tolnayd4e68302020-03-25 12:04:17 -0700112 match Atom::from(ident) {
113 None | Some(CxxString) => return,
114 _ => {}
115 }
David Tolnay4377a9e2020-04-24 15:20:26 -0700116 } else if let Type::CxxVector(_) = &ptr.inner {
Myron Ahneba35cf2020-02-05 19:41:51 +0700117 return;
David Tolnayd4e68302020-03-25 12:04:17 -0700118 }
David Tolnaya420f012020-03-25 17:55:56 -0700119
120 cx.error(ptr, "unsupported unique_ptr target type");
David Tolnayd4e68302020-03-25 12:04:17 -0700121}
122
David Tolnayfff4c8a2020-04-25 11:45:20 -0700123fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
Myron Ahneba35cf2020-02-05 19:41:51 +0700124 if let Type::Ident(ident) = &ptr.inner {
125 if cx.types.rust.contains(ident) {
David Tolnayc0faaf62020-04-25 12:18:38 -0700126 cx.error(
127 ptr,
128 "C++ vector containing a Rust type is not supported yet",
129 );
Myron Ahneba35cf2020-02-05 19:41:51 +0700130 }
131
132 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700133 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
134 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
135 Some(CxxString) => { /* todo */ }
136 Some(Bool) | Some(RustString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700137 }
138 }
David Tolnayc0faaf62020-04-25 12:18:38 -0700139
Myron Ahneba35cf2020-02-05 19:41:51 +0700140 cx.error(ptr, "unsupported vector target type");
141}
142
David Tolnay26a2a1d2020-03-25 17:26:43 -0700143fn check_type_ref(cx: &mut Check, ty: &Ref) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700144 if ty.lifetime.is_some() {
145 cx.error(ty, "references with explicit lifetimes are not supported");
146 }
147
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700148 match ty.inner {
149 Type::Fn(_) | Type::Void(_) => {}
David Tolnay776fd892020-04-28 13:38:21 -0700150 Type::Ref(_) => {
151 cx.error(ty, "C++ does not allow references to references");
152 return;
153 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700154 _ => return,
David Tolnayd4e68302020-03-25 12:04:17 -0700155 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700156
157 cx.error(ty, "unsupported reference type");
David Tolnayd4e68302020-03-25 12:04:17 -0700158}
159
David Tolnayeebe9b72020-04-14 16:32:18 -0700160fn check_type_slice(cx: &mut Check, ty: &Slice) {
161 cx.error(ty, "only &[u8] is supported so far, not other slice types");
162}
163
David Tolnay26a2a1d2020-03-25 17:26:43 -0700164fn check_api_struct(cx: &mut Check, strct: &Struct) {
David Tolnay0b368ae2020-04-22 17:55:02 -0700165 check_reserved_name(cx, &strct.ident);
166
David Tolnayd4e68302020-03-25 12:04:17 -0700167 if strct.fields.is_empty() {
David Tolnaya420f012020-03-25 17:55:56 -0700168 let span = span_for_struct_error(strct);
169 cx.error(span, "structs without any fields are not supported");
David Tolnayd4e68302020-03-25 12:04:17 -0700170 }
David Tolnaya420f012020-03-25 17:55:56 -0700171
David Tolnayd4e68302020-03-25 12:04:17 -0700172 for field in &strct.fields {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700173 if is_unsized(cx, &field.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700174 let desc = describe(cx, &field.ty);
175 let msg = format!("using {} by value is not supported", desc);
176 cx.error(field, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700177 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700178 if let Type::Fn(_) = field.ty {
179 cx.error(
180 field,
181 "function pointers in a struct field are not implemented yet",
182 );
183 }
David Tolnayd4e68302020-03-25 12:04:17 -0700184 }
185}
186
Joel Galensonc03402a2020-04-23 17:31:09 -0700187fn check_api_enum(cx: &mut Check, enm: &Enum) {
188 check_reserved_name(cx, &enm.ident);
189
190 if enm.variants.is_empty() {
191 let span = span_for_enum_error(enm);
192 cx.error(span, "enums without any variants are not supported");
193 }
194
195 let mut discriminants = HashSet::new();
Joel Galenson04fa0962020-05-01 10:00:31 -0700196 enm.variants
197 .iter()
198 .fold(None, |prev_discriminant, variant| {
199 if variant.discriminant.is_none() && prev_discriminant.unwrap_or(0) == u32::MAX {
200 let msg = format!("overflowed on value after {}", prev_discriminant.unwrap());
201 cx.error(span_for_enum_error(enm), msg);
202 return None;
203 }
204 let discriminant = variant
205 .discriminant
206 .unwrap_or_else(|| prev_discriminant.map_or(0, |n| n + 1));
207 if !discriminants.insert(discriminant) {
208 let msg = format!("discriminant value `{}` already exists", discriminant);
209 cx.error(span_for_enum_error(enm), msg);
210 }
211 Some(discriminant)
212 });
Joel Galensonc03402a2020-04-23 17:31:09 -0700213}
214
David Tolnay0b368ae2020-04-22 17:55:02 -0700215fn check_api_type(cx: &mut Check, ty: &ExternType) {
216 check_reserved_name(cx, &ty.ident);
217}
218
David Tolnay26a2a1d2020-03-25 17:26:43 -0700219fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700220 if let Some(receiver) = &efn.receiver {
David Tolnaya1f29c42020-04-22 18:01:38 -0700221 let ref span = span_for_receiver_error(receiver);
222
223 if receiver.ty == "Self" {
224 let mutability = match receiver.mutability {
225 Some(_) => "mut ",
226 None => "",
227 };
228 let msg = format!(
229 "unnamed receiver type is only allowed if the surrounding \
230 extern block contains exactly one extern type; \
231 use `self: &{mutability}TheType`",
232 mutability = mutability,
233 );
234 cx.error(span, msg);
235 } else if !cx.types.structs.contains_key(&receiver.ty)
David Tolnay8b60bf12020-04-22 16:52:19 -0700236 && !cx.types.cxx.contains(&receiver.ty)
237 && !cx.types.rust.contains(&receiver.ty)
238 {
David Tolnay8b60bf12020-04-22 16:52:19 -0700239 cx.error(span, "unrecognized receiver type");
240 }
241
David Tolnayd763f4c2020-04-22 16:09:19 -0700242 if receiver.lifetime.is_some() {
David Tolnayd763f4c2020-04-22 16:09:19 -0700243 cx.error(span, "references with explicit lifetimes are not supported");
244 }
245 }
246
David Tolnayd4e68302020-03-25 12:04:17 -0700247 for arg in &efn.args {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700248 if is_unsized(cx, &arg.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700249 let desc = describe(cx, &arg.ty);
250 let msg = format!("passing {} by value is not supported", desc);
251 cx.error(arg, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700252 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700253 if let Type::Fn(_) = arg.ty {
David Tolnay75dca2e2020-03-25 20:17:52 -0700254 if efn.lang == Lang::Rust {
255 cx.error(
256 arg,
257 "passing a function pointer from C++ to Rust is not implemented yet",
258 );
259 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700260 }
David Tolnayd4e68302020-03-25 12:04:17 -0700261 }
David Tolnaya420f012020-03-25 17:55:56 -0700262
David Tolnayd4e68302020-03-25 12:04:17 -0700263 if let Some(ty) = &efn.ret {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700264 if is_unsized(cx, ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700265 let desc = describe(cx, ty);
266 let msg = format!("returning {} by value is not supported", desc);
267 cx.error(ty, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700268 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700269 if let Type::Fn(_) = ty {
270 cx.error(ty, "returning a function pointer is not implemented yet");
271 }
David Tolnayd4e68302020-03-25 12:04:17 -0700272 }
David Tolnay96a826b2020-05-04 00:17:12 -0700273
274 if efn.lang == Lang::Cxx {
275 check_mut_return_restriction(cx, efn);
276 }
277
278 check_multiple_arg_lifetimes(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -0400279}
280
David Tolnay26a2a1d2020-03-25 17:26:43 -0700281fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400282 match &efn.ret {
283 Some(Type::Ref(ty)) if ty.mutability.is_some() => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700284 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400285 }
286
287 for arg in &efn.args {
288 if let Type::Ref(ty) = &arg.ty {
289 if ty.mutability.is_some() {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700290 return;
David Tolnay7db73692019-10-20 14:51:12 -0400291 }
292 }
293 }
294
David Tolnaya420f012020-03-25 17:55:56 -0700295 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400296 efn,
297 "&mut return type is not allowed unless there is a &mut argument",
David Tolnaya420f012020-03-25 17:55:56 -0700298 );
David Tolnay7db73692019-10-20 14:51:12 -0400299}
300
David Tolnay26a2a1d2020-03-25 17:26:43 -0700301fn check_multiple_arg_lifetimes(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400302 match &efn.ret {
303 Some(Type::Ref(_)) => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700304 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400305 }
306
307 let mut reference_args = 0;
308 for arg in &efn.args {
309 if let Type::Ref(_) = &arg.ty {
310 reference_args += 1;
311 }
312 }
313
Joel Galenson3d4f6122020-04-07 15:54:05 -0700314 if efn.receiver.is_some() {
315 reference_args += 1;
316 }
317
David Tolnay26a2a1d2020-03-25 17:26:43 -0700318 if reference_args != 1 {
David Tolnaya420f012020-03-25 17:55:56 -0700319 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400320 efn,
321 "functions that return a reference must take exactly one input reference",
David Tolnaya420f012020-03-25 17:55:56 -0700322 );
David Tolnay7db73692019-10-20 14:51:12 -0400323 }
324}
325
David Tolnay0b368ae2020-04-22 17:55:02 -0700326fn check_reserved_name(cx: &mut Check, ident: &Ident) {
David Tolnay99c93d82020-04-25 14:07:44 -0700327 if ident == "Box"
328 || ident == "UniquePtr"
329 || ident == "Vec"
330 || ident == "CxxVector"
331 || Atom::from(ident).is_some()
332 {
David Tolnay0b368ae2020-04-22 17:55:02 -0700333 cx.error(ident, "reserved name");
334 }
335}
336
David Tolnay26a2a1d2020-03-25 17:26:43 -0700337fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
David Tolnayd4e68302020-03-25 12:04:17 -0700338 let ident = match ty {
339 Type::Ident(ident) => ident,
David Tolnaye70303c2020-04-25 15:02:37 -0700340 Type::CxxVector(_) | Type::Slice(_) | Type::Void(_) => return true,
David Tolnayd4e68302020-03-25 12:04:17 -0700341 _ => return false,
342 };
David Tolnay26a2a1d2020-03-25 17:26:43 -0700343 ident == CxxString || cx.types.cxx.contains(ident) || cx.types.rust.contains(ident)
344}
345
David Tolnaya420f012020-03-25 17:55:56 -0700346fn span_for_struct_error(strct: &Struct) -> TokenStream {
347 let struct_token = strct.struct_token;
348 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
349 brace_token.set_span(strct.brace_token.span);
350 quote!(#struct_token #brace_token)
351}
352
Joel Galensonc03402a2020-04-23 17:31:09 -0700353fn span_for_enum_error(enm: &Enum) -> TokenStream {
354 let enum_token = enm.enum_token;
355 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
356 brace_token.set_span(enm.brace_token.span);
357 quote!(#enum_token #brace_token)
358}
359
David Tolnayd763f4c2020-04-22 16:09:19 -0700360fn span_for_receiver_error(receiver: &Receiver) -> TokenStream {
361 let ampersand = receiver.ampersand;
362 let lifetime = &receiver.lifetime;
363 let mutability = receiver.mutability;
364 if receiver.shorthand {
365 let var = receiver.var;
366 quote!(#ampersand #lifetime #mutability #var)
367 } else {
368 let ty = &receiver.ty;
369 quote!(#ampersand #lifetime #mutability #ty)
370 }
371}
372
David Tolnaya420f012020-03-25 17:55:56 -0700373fn describe(cx: &mut Check, ty: &Type) -> String {
David Tolnay7db73692019-10-20 14:51:12 -0400374 match ty {
375 Type::Ident(ident) => {
David Tolnaya420f012020-03-25 17:55:56 -0700376 if cx.types.structs.contains_key(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400377 "struct".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700378 } else if cx.types.cxx.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400379 "C++ type".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700380 } else if cx.types.rust.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400381 "opaque Rust type".to_owned()
382 } else if Atom::from(ident) == Some(CxxString) {
383 "C++ string".to_owned()
384 } else {
385 ident.to_string()
386 }
387 }
388 Type::RustBox(_) => "Box".to_owned(),
Myron Ahneba35cf2020-02-05 19:41:51 +0700389 Type::RustVec(_) => "Vec".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400390 Type::UniquePtr(_) => "unique_ptr".to_owned(),
391 Type::Ref(_) => "reference".to_owned(),
392 Type::Str(_) => "&str".to_owned(),
David Tolnayfa85fce2020-04-25 15:03:25 -0700393 Type::CxxVector(_) => "C++ vector".to_owned(),
Adrian Taylorf5dd5522020-04-13 16:50:14 -0700394 Type::Slice(_) => "slice".to_owned(),
395 Type::SliceRefU8(_) => "&[u8]".to_owned(),
David Tolnay417305a2020-03-18 13:54:00 -0700396 Type::Fn(_) => "function pointer".to_owned(),
David Tolnay2fb14e92020-03-15 23:11:38 -0700397 Type::Void(_) => "()".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400398 }
399}