Fn makes more sense to treat like unsized
diff --git a/syntax/check.rs b/syntax/check.rs
index f077bd3..6ffdbb1 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -186,12 +186,7 @@
}
fn check_type_array(cx: &mut Check, ty: &Array) {
- let supported = match &ty.inner {
- Type::Fn(_) => false,
- element => !is_unsized(cx, element),
- };
-
- if !supported {
+ if is_unsized(cx, &ty.inner) {
cx.error(ty, "unsupported array element type");
}
}
@@ -219,16 +214,15 @@
}
for field in &strct.fields {
- if is_unsized(cx, &field.ty) {
- let desc = describe(cx, &field.ty);
- let msg = format!("using {} by value is not supported", desc);
- cx.error(field, msg);
- }
if let Type::Fn(_) = field.ty {
cx.error(
field,
"function pointers in a struct field are not implemented yet",
);
+ } else if is_unsized(cx, &field.ty) {
+ let desc = describe(cx, &field.ty);
+ let msg = format!("using {} by value is not supported", desc);
+ cx.error(field, msg);
}
}
}
@@ -314,11 +308,6 @@
}
for arg in &efn.args {
- if is_unsized(cx, &arg.ty) {
- let desc = describe(cx, &arg.ty);
- let msg = format!("passing {} by value is not supported", desc);
- cx.error(arg, msg);
- }
if let Type::Fn(_) = arg.ty {
if efn.lang == Lang::Rust {
cx.error(
@@ -326,18 +315,21 @@
"passing a function pointer from C++ to Rust is not implemented yet",
);
}
+ } else if is_unsized(cx, &arg.ty) {
+ let desc = describe(cx, &arg.ty);
+ let msg = format!("passing {} by value is not supported", desc);
+ cx.error(arg, msg);
}
}
if let Some(ty) = &efn.ret {
- if is_unsized(cx, ty) {
+ if let Type::Fn(_) = ty {
+ cx.error(ty, "returning a function pointer is not implemented yet");
+ } else if is_unsized(cx, ty) {
let desc = describe(cx, ty);
let msg = format!("returning {} by value is not supported", desc);
cx.error(ty, msg);
}
- if let Type::Fn(_) = ty {
- cx.error(ty, "returning a function pointer is not implemented yet");
- }
}
if efn.lang == Lang::Cxx {
@@ -427,13 +419,12 @@
ident == CxxString || is_opaque_cxx(cx, ident) || cx.types.rust.contains(ident)
}
Type::Array(array) => is_unsized(cx, &array.inner),
- Type::CxxVector(_) | Type::Slice(_) | Type::Void(_) => true,
+ Type::CxxVector(_) | Type::Slice(_) | Type::Fn(_) | Type::Void(_) => true,
Type::RustBox(_)
| Type::RustVec(_)
| Type::UniquePtr(_)
| Type::Ref(_)
| Type::Str(_)
- | Type::Fn(_)
| Type::SliceRefU8(_) => false,
}
}