Commit 8a5fd250 authored by Ryan Hunt's avatar Ryan Hunt

Add better assertion messages

parent 462302c6
......@@ -69,22 +69,22 @@ impl CDecl {
match t {
&Type::Path(ref path) => {
if is_const {
assert!(self.type_qualifers.len() == 0);
assert!(self.type_qualifers.len() == 0, "error generating cdecl for {:?}", t);
self.type_qualifers = "const".to_owned();
}
assert!(self.type_name.len() == 0);
assert!(self.type_name.len() == 0, "error generating cdecl for {:?}", t);
self.type_name = path.name.clone();
assert!(self.type_generic_args.len() == 0);
assert!(self.type_generic_args.len() == 0, "error generating cdecl for {:?}", t);
self.type_generic_args = path.generics.clone();
}
&Type::Primitive(ref p) => {
if is_const {
assert!(self.type_qualifers.len() == 0);
assert!(self.type_qualifers.len() == 0, "error generating cdecl for {:?}", t);
self.type_qualifers = "const".to_owned();
}
assert!(self.type_name.len() == 0);
assert!(self.type_name.len() == 0, "error generating cdecl for {:?}", t);
self.type_name = p.to_string();
}
......
......@@ -74,7 +74,12 @@ impl Item for OpaqueItem {
_library: &Library,
out: &mut Monomorphs,
) {
assert!(self.generic_params.len() > 0 && self.generic_params.len() == generic_values.len());
assert!(self.generic_params.len() > 0, "{} is not generic", self.name);
assert!(self.generic_params.len() == generic_values.len(), "{} has {} params but is being instantiated with {} values",
self.name,
self.generic_params.len(),
generic_values.len(),
);
let monomorph = OpaqueItem {
name: mangle::mangle_path(&self.name, generic_values),
......
......@@ -24,7 +24,7 @@ impl GenericPath {
}
pub fn load(path: &syn::Path) -> Result<GenericPath, String> {
assert!(path.segments.len() > 0);
assert!(path.segments.len() > 0, "{:?} doesn't have any segments", path);
let last_segment_token = path.segments.last().unwrap();
let last_segment = last_segment_token.value();
let name = last_segment.ident.to_string();
......
......@@ -176,7 +176,12 @@ impl Item for Struct {
library: &Library,
out: &mut Monomorphs,
) {
assert!(self.generic_params.len() > 0 && self.generic_params.len() == generic_values.len());
assert!(self.generic_params.len() > 0, "{} is not generic", self.name);
assert!(self.generic_params.len() == generic_values.len(), "{} has {} params but is being instantiated with {} values",
self.name,
self.generic_params.len(),
generic_values.len(),
);
let mappings = self.generic_params
.iter()
......
......@@ -125,7 +125,12 @@ impl Item for Typedef {
library: &Library,
out: &mut Monomorphs,
) {
assert!(self.generic_params.len() > 0 && self.generic_params.len() == generic_values.len());
assert!(self.generic_params.len() > 0, "{} is not generic", self.name);
assert!(self.generic_params.len() == generic_values.len(), "{} has {} params but is being instantiated with {} values",
self.name,
self.generic_params.len(),
generic_values.len(),
);
let mappings = self.generic_params
.iter()
......
......@@ -165,7 +165,12 @@ impl Item for Union {
library: &Library,
out: &mut Monomorphs,
) {
assert!(self.generic_params.len() > 0 && self.generic_params.len() == generic_values.len());
assert!(self.generic_params.len() > 0, "{} is not generic", self.name);
assert!(self.generic_params.len() == generic_values.len(), "{} has {} params but is being instantiated with {} values",
self.name,
self.generic_params.len(),
generic_values.len(),
);
let mappings = self.generic_params
.iter()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment