blob: a99e98241e59dbb1e7f1c2e6a1ca3852ebde6428 [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 Tolnay7db73692019-10-20 14:51:12 -040011use syn::{Error, Result};
12
David Tolnaya83301c2020-04-30 20:32:37 -070013pub(crate) struct Check<'a> {
David Tolnay9dcb8332020-04-30 20:37:33 -070014 namespace: &'a Namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070015 apis: &'a [Api],
16 types: &'a Types<'a>,
17 errors: &'a mut Vec<Error>,
18}
19
David Tolnay9dcb8332020-04-30 20:37:33 -070020pub(crate) fn typecheck(namespace: &Namespace, apis: &[Api], types: &Types) -> Result<()> {
David Tolnay26a2a1d2020-03-25 17:26:43 -070021 let mut errors = Vec::new();
22 let mut cx = Check {
David Tolnay9dcb8332020-04-30 20:37:33 -070023 namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070024 apis,
25 types,
26 errors: &mut errors,
27 };
28 do_typecheck(&mut cx);
29 combine_errors(errors)
30}
David Tolnay7db73692019-10-20 14:51:12 -040031
David Tolnay26a2a1d2020-03-25 17:26:43 -070032fn do_typecheck(cx: &mut Check) {
David Tolnay6b6423e2020-04-30 20:46:24 -070033 ident::check_all(cx, cx.namespace, cx.apis);
David Tolnay9dcb8332020-04-30 20:37:33 -070034
David Tolnay26a2a1d2020-03-25 17:26:43 -070035 for ty in cx.types {
David Tolnay7db73692019-10-20 14:51:12 -040036 match ty {
David Tolnay26a2a1d2020-03-25 17:26:43 -070037 Type::Ident(ident) => check_type_ident(cx, ident),
38 Type::RustBox(ptr) => check_type_box(cx, ptr),
David Tolnayc6d891e2020-04-25 12:06:34 -070039 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070040 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
David Tolnayfff4c8a2020-04-25 11:45:20 -070041 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
David Tolnay26a2a1d2020-03-25 17:26:43 -070042 Type::Ref(ty) => check_type_ref(cx, ty),
David Tolnayeebe9b72020-04-14 16:32:18 -070043 Type::Slice(ty) => check_type_slice(cx, ty),
David Tolnay7db73692019-10-20 14:51:12 -040044 _ => {}
45 }
46 }
47
David Tolnay26a2a1d2020-03-25 17:26:43 -070048 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040049 match api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070050 Api::Struct(strct) => check_api_struct(cx, strct),
Joel Galensonc03402a2020-04-23 17:31:09 -070051 Api::Enum(enm) => check_api_enum(cx, enm),
David Tolnay0b368ae2020-04-22 17:55:02 -070052 Api::CxxType(ty) | Api::RustType(ty) => check_api_type(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070053 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
David Tolnay7db73692019-10-20 14:51:12 -040054 _ => {}
55 }
56 }
57
David Tolnay26a2a1d2020-03-25 17:26:43 -070058 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040059 if let Api::CxxFunction(efn) = api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070060 check_mut_return_restriction(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -040061 }
62 if let Api::CxxFunction(efn) | Api::RustFunction(efn) = api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070063 check_multiple_arg_lifetimes(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -040064 }
65 }
David Tolnay7db73692019-10-20 14:51:12 -040066}
67
David Tolnaya420f012020-03-25 17:55:56 -070068impl Check<'_> {
David Tolnaya83301c2020-04-30 20:32:37 -070069 pub(crate) fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
David Tolnaya420f012020-03-25 17:55:56 -070070 self.errors.push(Error::new_spanned(sp, msg));
71 }
72}
73
David Tolnay26a2a1d2020-03-25 17:26:43 -070074fn check_type_ident(cx: &mut Check, ident: &Ident) {
David Tolnayd4e68302020-03-25 12:04:17 -070075 if Atom::from(ident).is_none()
David Tolnay26a2a1d2020-03-25 17:26:43 -070076 && !cx.types.structs.contains_key(ident)
Joel Galensonc03402a2020-04-23 17:31:09 -070077 && !cx.types.enums.contains_key(ident)
David Tolnay26a2a1d2020-03-25 17:26:43 -070078 && !cx.types.cxx.contains(ident)
79 && !cx.types.rust.contains(ident)
David Tolnayd4e68302020-03-25 12:04:17 -070080 {
David Tolnaya420f012020-03-25 17:55:56 -070081 cx.error(ident, "unsupported type");
David Tolnayd4e68302020-03-25 12:04:17 -070082 }
83}
84
David Tolnay26a2a1d2020-03-25 17:26:43 -070085fn check_type_box(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -070086 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -070087 if cx.types.cxx.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -070088 cx.error(ptr, error::BOX_CXX_TYPE.msg);
David Tolnayd4e68302020-03-25 12:04:17 -070089 }
David Tolnaya420f012020-03-25 17:55:56 -070090
David Tolnayd4e68302020-03-25 12:04:17 -070091 if Atom::from(ident).is_none() {
92 return;
93 }
94 }
David Tolnaya420f012020-03-25 17:55:56 -070095
96 cx.error(ptr, "unsupported target type of Box");
David Tolnayd4e68302020-03-25 12:04:17 -070097}
98
David Tolnayc6d891e2020-04-25 12:06:34 -070099fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
100 if let Type::Ident(ident) = &ty.inner {
101 if cx.types.cxx.contains(ident) {
102 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
Myron Ahneba35cf2020-02-05 19:41:51 +0700103 return;
David Tolnayc6d891e2020-04-25 12:06:34 -0700104 }
105
106 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700107 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
108 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
109 Some(Bool) | Some(RustString) => { /* todo */ }
110 Some(CxxString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700111 }
112 }
113
David Tolnayc6d891e2020-04-25 12:06:34 -0700114 cx.error(ty, "unsupported element type of Vec");
Myron Ahneba35cf2020-02-05 19:41:51 +0700115}
116
David Tolnay26a2a1d2020-03-25 17:26:43 -0700117fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -0700118 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700119 if cx.types.rust.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -0700120 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
David Tolnayd4e68302020-03-25 12:04:17 -0700121 }
David Tolnaya420f012020-03-25 17:55:56 -0700122
David Tolnayd4e68302020-03-25 12:04:17 -0700123 match Atom::from(ident) {
124 None | Some(CxxString) => return,
125 _ => {}
126 }
David Tolnay4377a9e2020-04-24 15:20:26 -0700127 } else if let Type::CxxVector(_) = &ptr.inner {
Myron Ahneba35cf2020-02-05 19:41:51 +0700128 return;
David Tolnayd4e68302020-03-25 12:04:17 -0700129 }
David Tolnaya420f012020-03-25 17:55:56 -0700130
131 cx.error(ptr, "unsupported unique_ptr target type");
David Tolnayd4e68302020-03-25 12:04:17 -0700132}
133
David Tolnayfff4c8a2020-04-25 11:45:20 -0700134fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
Myron Ahneba35cf2020-02-05 19:41:51 +0700135 if let Type::Ident(ident) = &ptr.inner {
136 if cx.types.rust.contains(ident) {
David Tolnayc0faaf62020-04-25 12:18:38 -0700137 cx.error(
138 ptr,
139 "C++ vector containing a Rust type is not supported yet",
140 );
Myron Ahneba35cf2020-02-05 19:41:51 +0700141 }
142
143 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700144 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
145 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
146 Some(CxxString) => { /* todo */ }
147 Some(Bool) | Some(RustString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700148 }
149 }
David Tolnayc0faaf62020-04-25 12:18:38 -0700150
Myron Ahneba35cf2020-02-05 19:41:51 +0700151 cx.error(ptr, "unsupported vector target type");
152}
153
David Tolnay26a2a1d2020-03-25 17:26:43 -0700154fn check_type_ref(cx: &mut Check, ty: &Ref) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700155 if ty.lifetime.is_some() {
156 cx.error(ty, "references with explicit lifetimes are not supported");
157 }
158
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700159 match ty.inner {
160 Type::Fn(_) | Type::Void(_) => {}
David Tolnay776fd892020-04-28 13:38:21 -0700161 Type::Ref(_) => {
162 cx.error(ty, "C++ does not allow references to references");
163 return;
164 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700165 _ => return,
David Tolnayd4e68302020-03-25 12:04:17 -0700166 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700167
168 cx.error(ty, "unsupported reference type");
David Tolnayd4e68302020-03-25 12:04:17 -0700169}
170
David Tolnayeebe9b72020-04-14 16:32:18 -0700171fn check_type_slice(cx: &mut Check, ty: &Slice) {
172 cx.error(ty, "only &[u8] is supported so far, not other slice types");
173}
174
David Tolnay26a2a1d2020-03-25 17:26:43 -0700175fn check_api_struct(cx: &mut Check, strct: &Struct) {
David Tolnay0b368ae2020-04-22 17:55:02 -0700176 check_reserved_name(cx, &strct.ident);
177
David Tolnayd4e68302020-03-25 12:04:17 -0700178 if strct.fields.is_empty() {
David Tolnaya420f012020-03-25 17:55:56 -0700179 let span = span_for_struct_error(strct);
180 cx.error(span, "structs without any fields are not supported");
David Tolnayd4e68302020-03-25 12:04:17 -0700181 }
David Tolnaya420f012020-03-25 17:55:56 -0700182
David Tolnayd4e68302020-03-25 12:04:17 -0700183 for field in &strct.fields {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700184 if is_unsized(cx, &field.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700185 let desc = describe(cx, &field.ty);
186 let msg = format!("using {} by value is not supported", desc);
187 cx.error(field, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700188 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700189 if let Type::Fn(_) = field.ty {
190 cx.error(
191 field,
192 "function pointers in a struct field are not implemented yet",
193 );
194 }
David Tolnayd4e68302020-03-25 12:04:17 -0700195 }
196}
197
Joel Galensonc03402a2020-04-23 17:31:09 -0700198fn check_api_enum(cx: &mut Check, enm: &Enum) {
199 check_reserved_name(cx, &enm.ident);
200
201 if enm.variants.is_empty() {
202 let span = span_for_enum_error(enm);
203 cx.error(span, "enums without any variants are not supported");
204 }
205
206 let mut discriminants = HashSet::new();
207 enm.variants.iter().fold(0, |next_discriminant, variant| {
David Tolnayd7984c22020-04-30 20:09:31 -0700208 let discriminant = variant.discriminant.unwrap_or(next_discriminant);
Joel Galensonc03402a2020-04-23 17:31:09 -0700209 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}