blob: 3fb0d065fbb3fea0b059912a8f92e48695ccd31c [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 Tolnaydf344a82020-05-03 23:23:18 -070013use syn::Result;
David Tolnay7db73692019-10-20 14:51:12 -040014
David Tolnaya83301c2020-04-30 20:32:37 -070015pub(crate) struct Check<'a> {
David Tolnay9dcb8332020-04-30 20:37:33 -070016 namespace: &'a Namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070017 apis: &'a [Api],
18 types: &'a Types<'a>,
David Tolnaydf344a82020-05-03 23:23:18 -070019 errors: &'a mut Errors,
David Tolnay26a2a1d2020-03-25 17:26:43 -070020}
21
David Tolnay9dcb8332020-04-30 20:37:33 -070022pub(crate) fn typecheck(namespace: &Namespace, apis: &[Api], types: &Types) -> Result<()> {
David Tolnaydf344a82020-05-03 23:23:18 -070023 let mut errors = Errors::new();
David Tolnay26a2a1d2020-03-25 17:26:43 -070024 let mut cx = Check {
David Tolnay9dcb8332020-04-30 20:37:33 -070025 namespace,
David Tolnay26a2a1d2020-03-25 17:26:43 -070026 apis,
27 types,
28 errors: &mut errors,
29 };
30 do_typecheck(&mut cx);
David Tolnaydf344a82020-05-03 23:23:18 -070031 errors.propagate()
David Tolnay26a2a1d2020-03-25 17:26:43 -070032}
David Tolnay7db73692019-10-20 14:51:12 -040033
David Tolnay26a2a1d2020-03-25 17:26:43 -070034fn do_typecheck(cx: &mut Check) {
David Tolnay6b6423e2020-04-30 20:46:24 -070035 ident::check_all(cx, cx.namespace, cx.apis);
David Tolnay9dcb8332020-04-30 20:37:33 -070036
David Tolnay26a2a1d2020-03-25 17:26:43 -070037 for ty in cx.types {
David Tolnay7db73692019-10-20 14:51:12 -040038 match ty {
David Tolnay26a2a1d2020-03-25 17:26:43 -070039 Type::Ident(ident) => check_type_ident(cx, ident),
40 Type::RustBox(ptr) => check_type_box(cx, ptr),
David Tolnayc6d891e2020-04-25 12:06:34 -070041 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070042 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
David Tolnayfff4c8a2020-04-25 11:45:20 -070043 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
David Tolnay26a2a1d2020-03-25 17:26:43 -070044 Type::Ref(ty) => check_type_ref(cx, ty),
David Tolnayeebe9b72020-04-14 16:32:18 -070045 Type::Slice(ty) => check_type_slice(cx, ty),
David Tolnay7db73692019-10-20 14:51:12 -040046 _ => {}
47 }
48 }
49
David Tolnay26a2a1d2020-03-25 17:26:43 -070050 for api in cx.apis {
David Tolnay7db73692019-10-20 14:51:12 -040051 match api {
David Tolnay26a2a1d2020-03-25 17:26:43 -070052 Api::Struct(strct) => check_api_struct(cx, strct),
Joel Galensonc03402a2020-04-23 17:31:09 -070053 Api::Enum(enm) => check_api_enum(cx, enm),
David Tolnay0b368ae2020-04-22 17:55:02 -070054 Api::CxxType(ty) | Api::RustType(ty) => check_api_type(cx, ty),
David Tolnay26a2a1d2020-03-25 17:26:43 -070055 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
David Tolnay7db73692019-10-20 14:51:12 -040056 _ => {}
57 }
58 }
David Tolnay7db73692019-10-20 14:51:12 -040059}
60
David Tolnaya420f012020-03-25 17:55:56 -070061impl Check<'_> {
David Tolnaya83301c2020-04-30 20:32:37 -070062 pub(crate) fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
David Tolnaydf344a82020-05-03 23:23:18 -070063 self.errors.error(sp, msg);
David Tolnaya420f012020-03-25 17:55:56 -070064 }
65}
66
David Tolnay26a2a1d2020-03-25 17:26:43 -070067fn check_type_ident(cx: &mut Check, ident: &Ident) {
David Tolnayd4e68302020-03-25 12:04:17 -070068 if Atom::from(ident).is_none()
David Tolnay26a2a1d2020-03-25 17:26:43 -070069 && !cx.types.structs.contains_key(ident)
Joel Galensonc03402a2020-04-23 17:31:09 -070070 && !cx.types.enums.contains_key(ident)
David Tolnay26a2a1d2020-03-25 17:26:43 -070071 && !cx.types.cxx.contains(ident)
72 && !cx.types.rust.contains(ident)
David Tolnayd4e68302020-03-25 12:04:17 -070073 {
David Tolnaya420f012020-03-25 17:55:56 -070074 cx.error(ident, "unsupported type");
David Tolnayd4e68302020-03-25 12:04:17 -070075 }
76}
77
David Tolnay26a2a1d2020-03-25 17:26:43 -070078fn check_type_box(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -070079 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -070080 if cx.types.cxx.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -070081 cx.error(ptr, error::BOX_CXX_TYPE.msg);
David Tolnayd4e68302020-03-25 12:04:17 -070082 }
David Tolnaya420f012020-03-25 17:55:56 -070083
David Tolnayd4e68302020-03-25 12:04:17 -070084 if Atom::from(ident).is_none() {
85 return;
86 }
87 }
David Tolnaya420f012020-03-25 17:55:56 -070088
89 cx.error(ptr, "unsupported target type of Box");
David Tolnayd4e68302020-03-25 12:04:17 -070090}
91
David Tolnayc6d891e2020-04-25 12:06:34 -070092fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
93 if let Type::Ident(ident) = &ty.inner {
94 if cx.types.cxx.contains(ident) {
95 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
Myron Ahneba35cf2020-02-05 19:41:51 +070096 return;
David Tolnayc6d891e2020-04-25 12:06:34 -070097 }
98
99 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700100 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
101 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
102 Some(Bool) | Some(RustString) => { /* todo */ }
103 Some(CxxString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700104 }
105 }
106
David Tolnayc6d891e2020-04-25 12:06:34 -0700107 cx.error(ty, "unsupported element type of Vec");
Myron Ahneba35cf2020-02-05 19:41:51 +0700108}
109
David Tolnay26a2a1d2020-03-25 17:26:43 -0700110fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
David Tolnayd4e68302020-03-25 12:04:17 -0700111 if let Type::Ident(ident) = &ptr.inner {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700112 if cx.types.rust.contains(ident) {
David Tolnaya420f012020-03-25 17:55:56 -0700113 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
David Tolnayd4e68302020-03-25 12:04:17 -0700114 }
David Tolnaya420f012020-03-25 17:55:56 -0700115
David Tolnayd4e68302020-03-25 12:04:17 -0700116 match Atom::from(ident) {
117 None | Some(CxxString) => return,
118 _ => {}
119 }
David Tolnay4377a9e2020-04-24 15:20:26 -0700120 } else if let Type::CxxVector(_) = &ptr.inner {
Myron Ahneba35cf2020-02-05 19:41:51 +0700121 return;
David Tolnayd4e68302020-03-25 12:04:17 -0700122 }
David Tolnaya420f012020-03-25 17:55:56 -0700123
124 cx.error(ptr, "unsupported unique_ptr target type");
David Tolnayd4e68302020-03-25 12:04:17 -0700125}
126
David Tolnayfff4c8a2020-04-25 11:45:20 -0700127fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
Myron Ahneba35cf2020-02-05 19:41:51 +0700128 if let Type::Ident(ident) = &ptr.inner {
129 if cx.types.rust.contains(ident) {
David Tolnayc0faaf62020-04-25 12:18:38 -0700130 cx.error(
131 ptr,
132 "C++ vector containing a Rust type is not supported yet",
133 );
Myron Ahneba35cf2020-02-05 19:41:51 +0700134 }
135
136 match Atom::from(ident) {
David Tolnay6bd63de2020-04-25 12:20:09 -0700137 None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8)
138 | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) => return,
139 Some(CxxString) => { /* todo */ }
140 Some(Bool) | Some(RustString) => {}
Myron Ahneba35cf2020-02-05 19:41:51 +0700141 }
142 }
David Tolnayc0faaf62020-04-25 12:18:38 -0700143
Myron Ahneba35cf2020-02-05 19:41:51 +0700144 cx.error(ptr, "unsupported vector target type");
145}
146
David Tolnay26a2a1d2020-03-25 17:26:43 -0700147fn check_type_ref(cx: &mut Check, ty: &Ref) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700148 if ty.lifetime.is_some() {
149 cx.error(ty, "references with explicit lifetimes are not supported");
150 }
151
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700152 match ty.inner {
153 Type::Fn(_) | Type::Void(_) => {}
David Tolnay776fd892020-04-28 13:38:21 -0700154 Type::Ref(_) => {
155 cx.error(ty, "C++ does not allow references to references");
156 return;
157 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700158 _ => return,
David Tolnayd4e68302020-03-25 12:04:17 -0700159 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700160
161 cx.error(ty, "unsupported reference type");
David Tolnayd4e68302020-03-25 12:04:17 -0700162}
163
David Tolnayeebe9b72020-04-14 16:32:18 -0700164fn check_type_slice(cx: &mut Check, ty: &Slice) {
165 cx.error(ty, "only &[u8] is supported so far, not other slice types");
166}
167
David Tolnay26a2a1d2020-03-25 17:26:43 -0700168fn check_api_struct(cx: &mut Check, strct: &Struct) {
David Tolnay0b368ae2020-04-22 17:55:02 -0700169 check_reserved_name(cx, &strct.ident);
170
David Tolnayd4e68302020-03-25 12:04:17 -0700171 if strct.fields.is_empty() {
David Tolnaya420f012020-03-25 17:55:56 -0700172 let span = span_for_struct_error(strct);
173 cx.error(span, "structs without any fields are not supported");
David Tolnayd4e68302020-03-25 12:04:17 -0700174 }
David Tolnaya420f012020-03-25 17:55:56 -0700175
David Tolnayd4e68302020-03-25 12:04:17 -0700176 for field in &strct.fields {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700177 if is_unsized(cx, &field.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700178 let desc = describe(cx, &field.ty);
179 let msg = format!("using {} by value is not supported", desc);
180 cx.error(field, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700181 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700182 if let Type::Fn(_) = field.ty {
183 cx.error(
184 field,
185 "function pointers in a struct field are not implemented yet",
186 );
187 }
David Tolnayd4e68302020-03-25 12:04:17 -0700188 }
189}
190
Joel Galensonc03402a2020-04-23 17:31:09 -0700191fn check_api_enum(cx: &mut Check, enm: &Enum) {
192 check_reserved_name(cx, &enm.ident);
193
194 if enm.variants.is_empty() {
195 let span = span_for_enum_error(enm);
196 cx.error(span, "enums without any variants are not supported");
197 }
198
199 let mut discriminants = HashSet::new();
Joel Galenson04fa0962020-05-01 10:00:31 -0700200 enm.variants
201 .iter()
202 .fold(None, |prev_discriminant, variant| {
203 if variant.discriminant.is_none() && prev_discriminant.unwrap_or(0) == u32::MAX {
204 let msg = format!("overflowed on value after {}", prev_discriminant.unwrap());
205 cx.error(span_for_enum_error(enm), msg);
206 return None;
207 }
208 let discriminant = variant
209 .discriminant
210 .unwrap_or_else(|| prev_discriminant.map_or(0, |n| n + 1));
211 if !discriminants.insert(discriminant) {
212 let msg = format!("discriminant value `{}` already exists", discriminant);
213 cx.error(span_for_enum_error(enm), msg);
214 }
215 Some(discriminant)
216 });
Joel Galensonc03402a2020-04-23 17:31:09 -0700217}
218
David Tolnay0b368ae2020-04-22 17:55:02 -0700219fn check_api_type(cx: &mut Check, ty: &ExternType) {
220 check_reserved_name(cx, &ty.ident);
221}
222
David Tolnay26a2a1d2020-03-25 17:26:43 -0700223fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
David Tolnayd763f4c2020-04-22 16:09:19 -0700224 if let Some(receiver) = &efn.receiver {
David Tolnaya1f29c42020-04-22 18:01:38 -0700225 let ref span = span_for_receiver_error(receiver);
226
227 if receiver.ty == "Self" {
228 let mutability = match receiver.mutability {
229 Some(_) => "mut ",
230 None => "",
231 };
232 let msg = format!(
233 "unnamed receiver type is only allowed if the surrounding \
234 extern block contains exactly one extern type; \
235 use `self: &{mutability}TheType`",
236 mutability = mutability,
237 );
238 cx.error(span, msg);
239 } else if !cx.types.structs.contains_key(&receiver.ty)
David Tolnay8b60bf12020-04-22 16:52:19 -0700240 && !cx.types.cxx.contains(&receiver.ty)
241 && !cx.types.rust.contains(&receiver.ty)
242 {
David Tolnay8b60bf12020-04-22 16:52:19 -0700243 cx.error(span, "unrecognized receiver type");
244 }
245
David Tolnayd763f4c2020-04-22 16:09:19 -0700246 if receiver.lifetime.is_some() {
David Tolnayd763f4c2020-04-22 16:09:19 -0700247 cx.error(span, "references with explicit lifetimes are not supported");
248 }
249 }
250
David Tolnayd4e68302020-03-25 12:04:17 -0700251 for arg in &efn.args {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700252 if is_unsized(cx, &arg.ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700253 let desc = describe(cx, &arg.ty);
254 let msg = format!("passing {} by value is not supported", desc);
255 cx.error(arg, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700256 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700257 if let Type::Fn(_) = arg.ty {
David Tolnay75dca2e2020-03-25 20:17:52 -0700258 if efn.lang == Lang::Rust {
259 cx.error(
260 arg,
261 "passing a function pointer from C++ to Rust is not implemented yet",
262 );
263 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700264 }
David Tolnayd4e68302020-03-25 12:04:17 -0700265 }
David Tolnaya420f012020-03-25 17:55:56 -0700266
David Tolnayd4e68302020-03-25 12:04:17 -0700267 if let Some(ty) = &efn.ret {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700268 if is_unsized(cx, ty) {
David Tolnaya420f012020-03-25 17:55:56 -0700269 let desc = describe(cx, ty);
270 let msg = format!("returning {} by value is not supported", desc);
271 cx.error(ty, msg);
David Tolnayd4e68302020-03-25 12:04:17 -0700272 }
David Tolnayd7e1f1e2020-03-18 21:06:37 -0700273 if let Type::Fn(_) = ty {
274 cx.error(ty, "returning a function pointer is not implemented yet");
275 }
David Tolnayd4e68302020-03-25 12:04:17 -0700276 }
David Tolnay96a826b2020-05-04 00:17:12 -0700277
278 if efn.lang == Lang::Cxx {
279 check_mut_return_restriction(cx, efn);
280 }
281
282 check_multiple_arg_lifetimes(cx, efn);
David Tolnay7db73692019-10-20 14:51:12 -0400283}
284
David Tolnay26a2a1d2020-03-25 17:26:43 -0700285fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400286 match &efn.ret {
287 Some(Type::Ref(ty)) if ty.mutability.is_some() => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700288 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400289 }
290
291 for arg in &efn.args {
292 if let Type::Ref(ty) = &arg.ty {
293 if ty.mutability.is_some() {
David Tolnay26a2a1d2020-03-25 17:26:43 -0700294 return;
David Tolnay7db73692019-10-20 14:51:12 -0400295 }
296 }
297 }
298
David Tolnaya420f012020-03-25 17:55:56 -0700299 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400300 efn,
301 "&mut return type is not allowed unless there is a &mut argument",
David Tolnaya420f012020-03-25 17:55:56 -0700302 );
David Tolnay7db73692019-10-20 14:51:12 -0400303}
304
David Tolnay26a2a1d2020-03-25 17:26:43 -0700305fn check_multiple_arg_lifetimes(cx: &mut Check, efn: &ExternFn) {
David Tolnay7db73692019-10-20 14:51:12 -0400306 match &efn.ret {
307 Some(Type::Ref(_)) => {}
David Tolnay26a2a1d2020-03-25 17:26:43 -0700308 _ => return,
David Tolnay7db73692019-10-20 14:51:12 -0400309 }
310
311 let mut reference_args = 0;
312 for arg in &efn.args {
313 if let Type::Ref(_) = &arg.ty {
314 reference_args += 1;
315 }
316 }
317
Joel Galenson3d4f6122020-04-07 15:54:05 -0700318 if efn.receiver.is_some() {
319 reference_args += 1;
320 }
321
David Tolnay26a2a1d2020-03-25 17:26:43 -0700322 if reference_args != 1 {
David Tolnaya420f012020-03-25 17:55:56 -0700323 cx.error(
David Tolnay7db73692019-10-20 14:51:12 -0400324 efn,
325 "functions that return a reference must take exactly one input reference",
David Tolnaya420f012020-03-25 17:55:56 -0700326 );
David Tolnay7db73692019-10-20 14:51:12 -0400327 }
328}
329
David Tolnay0b368ae2020-04-22 17:55:02 -0700330fn check_reserved_name(cx: &mut Check, ident: &Ident) {
David Tolnay99c93d82020-04-25 14:07:44 -0700331 if ident == "Box"
332 || ident == "UniquePtr"
333 || ident == "Vec"
334 || ident == "CxxVector"
335 || Atom::from(ident).is_some()
336 {
David Tolnay0b368ae2020-04-22 17:55:02 -0700337 cx.error(ident, "reserved name");
338 }
339}
340
David Tolnay26a2a1d2020-03-25 17:26:43 -0700341fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
David Tolnayd4e68302020-03-25 12:04:17 -0700342 let ident = match ty {
343 Type::Ident(ident) => ident,
David Tolnaye70303c2020-04-25 15:02:37 -0700344 Type::CxxVector(_) | Type::Slice(_) | Type::Void(_) => return true,
David Tolnayd4e68302020-03-25 12:04:17 -0700345 _ => return false,
346 };
David Tolnay26a2a1d2020-03-25 17:26:43 -0700347 ident == CxxString || cx.types.cxx.contains(ident) || cx.types.rust.contains(ident)
348}
349
David Tolnaya420f012020-03-25 17:55:56 -0700350fn span_for_struct_error(strct: &Struct) -> TokenStream {
351 let struct_token = strct.struct_token;
352 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
353 brace_token.set_span(strct.brace_token.span);
354 quote!(#struct_token #brace_token)
355}
356
Joel Galensonc03402a2020-04-23 17:31:09 -0700357fn span_for_enum_error(enm: &Enum) -> TokenStream {
358 let enum_token = enm.enum_token;
359 let mut brace_token = Group::new(Delimiter::Brace, TokenStream::new());
360 brace_token.set_span(enm.brace_token.span);
361 quote!(#enum_token #brace_token)
362}
363
David Tolnayd763f4c2020-04-22 16:09:19 -0700364fn span_for_receiver_error(receiver: &Receiver) -> TokenStream {
365 let ampersand = receiver.ampersand;
366 let lifetime = &receiver.lifetime;
367 let mutability = receiver.mutability;
368 if receiver.shorthand {
369 let var = receiver.var;
370 quote!(#ampersand #lifetime #mutability #var)
371 } else {
372 let ty = &receiver.ty;
373 quote!(#ampersand #lifetime #mutability #ty)
374 }
375}
376
David Tolnaya420f012020-03-25 17:55:56 -0700377fn describe(cx: &mut Check, ty: &Type) -> String {
David Tolnay7db73692019-10-20 14:51:12 -0400378 match ty {
379 Type::Ident(ident) => {
David Tolnaya420f012020-03-25 17:55:56 -0700380 if cx.types.structs.contains_key(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400381 "struct".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700382 } else if cx.types.cxx.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400383 "C++ type".to_owned()
David Tolnaya420f012020-03-25 17:55:56 -0700384 } else if cx.types.rust.contains(ident) {
David Tolnay7db73692019-10-20 14:51:12 -0400385 "opaque Rust type".to_owned()
386 } else if Atom::from(ident) == Some(CxxString) {
387 "C++ string".to_owned()
388 } else {
389 ident.to_string()
390 }
391 }
392 Type::RustBox(_) => "Box".to_owned(),
Myron Ahneba35cf2020-02-05 19:41:51 +0700393 Type::RustVec(_) => "Vec".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400394 Type::UniquePtr(_) => "unique_ptr".to_owned(),
395 Type::Ref(_) => "reference".to_owned(),
396 Type::Str(_) => "&str".to_owned(),
David Tolnayfa85fce2020-04-25 15:03:25 -0700397 Type::CxxVector(_) => "C++ vector".to_owned(),
Adrian Taylorf5dd5522020-04-13 16:50:14 -0700398 Type::Slice(_) => "slice".to_owned(),
399 Type::SliceRefU8(_) => "&[u8]".to_owned(),
David Tolnay417305a2020-03-18 13:54:00 -0700400 Type::Fn(_) => "function pointer".to_owned(),
David Tolnay2fb14e92020-03-15 23:11:38 -0700401 Type::Void(_) => "()".to_owned(),
David Tolnay7db73692019-10-20 14:51:12 -0400402 }
403}