Support &mut [u8]
diff --git a/syntax/check.rs b/syntax/check.rs
index 2e94f4d..1ec6178 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -178,7 +178,10 @@
}
fn check_type_slice(cx: &mut Check, ty: &Slice) {
- cx.error(ty, "only &[u8] is supported so far, not other slice types");
+ cx.error(
+ ty,
+ "only &[u8] and &mut [u8] are supported so far, not other slice types",
+ );
}
fn check_type_fn(cx: &mut Check, ty: &Signature) {
@@ -489,7 +492,10 @@
Type::Str(_) => "&str".to_owned(),
Type::CxxVector(_) => "C++ vector".to_owned(),
Type::Slice(_) => "slice".to_owned(),
- Type::SliceRefU8(_) => "&[u8]".to_owned(),
+ Type::SliceRefU8(ty) => match ty.mutable {
+ false => "&[u8]".to_owned(),
+ true => "&mut [u8]".to_owned(),
+ },
Type::Fn(_) => "function pointer".to_owned(),
Type::Void(_) => "()".to_owned(),
}
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 38b3dcc..c6d6480 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -658,7 +658,7 @@
}
}
Type::Slice(slice) => match &slice.inner {
- Type::Ident(ident) if ident.rust == U8 && ty.mutability.is_none() => Type::SliceRefU8,
+ Type::Ident(ident) if ident.rust == U8 => Type::SliceRefU8,
_ => Type::Ref,
},
_ => Type::Ref,