Improve type checking and error messages for slice type
diff --git a/syntax/check.rs b/syntax/check.rs
index c71295e..181c530 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -1,5 +1,5 @@
use crate::syntax::atom::Atom::{self, *};
-use crate::syntax::{error, ident, Api, ExternFn, Lang, Ref, Struct, Ty1, Type, Types};
+use crate::syntax::{error, ident, Api, ExternFn, Lang, Ref, Slice, Struct, Ty1, Type, Types};
use proc_macro2::{Delimiter, Group, Ident, TokenStream};
use quote::{quote, ToTokens};
use std::fmt::Display;
@@ -29,6 +29,7 @@
Type::RustBox(ptr) => check_type_box(cx, ptr),
Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
Type::Ref(ty) => check_type_ref(cx, ty),
+ Type::Slice(ty) => check_type_slice(cx, ty),
_ => {}
}
}
@@ -107,6 +108,10 @@
cx.error(ty, "unsupported reference type");
}
+fn check_type_slice(cx: &mut Check, ty: &Slice) {
+ cx.error(ty, "only &[u8] is supported so far, not other slice types");
+}
+
fn check_api_struct(cx: &mut Check, strct: &Struct) {
if strct.fields.is_empty() {
let span = span_for_struct_error(strct);
@@ -201,7 +206,7 @@
fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
let ident = match ty {
Type::Ident(ident) => ident,
- Type::Void(_) => return true,
+ Type::Slice(_) | Type::Void(_) => return true,
_ => return false,
};
ident == CxxString || cx.types.cxx.contains(ident) || cx.types.rust.contains(ident)