Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sword-Smith committed Nov 11, 2023
1 parent 107d32b commit d75a644
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
14 changes: 6 additions & 8 deletions src/ast_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl TryFrom<DataType> for tasm_lib::snippet::DataType {
Ok(tasm_lib::snippet::DataType::List(Box::new(element_type)))
}
DataType::Array(_array_type) => {
return Err("Array types not yet supported by tasm-lib".to_owned())
Err("Array types not yet supported by tasm-lib".to_owned())
}
DataType::Tuple(tuple_elements) => {
let tuple_elements = tuple_elements
Expand All @@ -392,11 +392,9 @@ impl TryFrom<DataType> for tasm_lib::snippet::DataType {
DataType::Function(_) => todo!(),
DataType::Struct(_) => todo!(),
DataType::Enum(_) => todo!(),
DataType::Unresolved(name) => {
return Err(format!(
"Cannot convert unresolved type {name} to tasm-lib type"
))
}
DataType::Unresolved(name) => Err(format!(
"Cannot convert unresolved type {name} to tasm-lib type"
)),
DataType::Boxed(value) => match *value {
// A Boxed list is just a list
// TODO: Default to `Unsafe` list here??
Expand Down Expand Up @@ -608,7 +606,7 @@ impl EnumType {
// Append padding code to ensure that all enum variants have the same size
// on the stack.
let padding = vec![triton_instr!(push 0); self.padding_size(variant_name)];
let discriminant = self.variant_discriminant(&variant_name);
let discriminant = self.variant_discriminant(variant_name);
let discriminant = triton_asm!(push { discriminant });

constructor.body = [constructor.body, padding, discriminant].concat();
Expand Down Expand Up @@ -805,7 +803,7 @@ impl std::ops::Index<usize> for Tuple {
}

impl Tuple {
pub fn len(&self) -> usize {
pub fn element_count(&self) -> usize {
self.fields.len()
}

Expand Down
8 changes: 4 additions & 4 deletions src/graft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl<'a> Graft<'a> {
let mut grafted_variants = vec![];
for variant in variants {
let variant_name = variant.ident.to_string();
let field_type = graft_tuple_struct(&graft_config, variant.fields);
let field_type = graft_tuple_struct(graft_config, variant.fields);
grafted_variants.push((variant_name, ast_types::DataType::Tuple(field_type)));
}

return grafted_variants;
grafted_variants
}

fn graft_struct_with_named_fields(
Expand Down Expand Up @@ -1285,8 +1285,8 @@ impl<'a> Graft<'a> {
fat_arrow_token: _,
body,
comma: _,
}: &syn::Arm = &arm;
let arm_body = graft_expr_stmt(graft_config, &body);
}: &syn::Arm = arm;
let arm_body = graft_expr_stmt(graft_config, body);

// TODO: Add support for `_` matching
let arm_body = if let ast::Stmt::Block(block_stmt) = arm_body {
Expand Down
4 changes: 2 additions & 2 deletions src/tasm_code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ impl<'a> CompilerState<'a> {
ast_types::DataType::List(_, _) | ast_types::DataType::Array(_) => {
return get_value_location_of_sequence_element(
self,
&ident,
&index_expr,
ident,
index_expr,
element_type,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub enum SimpleEnum {
B,
}

#[allow(clippy::assertions_on_constants)]
#[allow(clippy::match_single_binding)]
fn main() {
let a: SimpleEnum = SimpleEnum::A;
let b: SimpleEnum = SimpleEnum::B;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum SimpleEnum {
B,
}

#[allow(clippy::assertions_on_constants)]
fn main() {
let a: SimpleEnum = SimpleEnum::A(tasm::tasm_io_read_stdin___xfe());
let b: SimpleEnum = SimpleEnum::B;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl ProofItem {
};
}

#[allow(clippy::assertions_on_constants)]
fn _as_merkle_root(&self) -> Digest {
let mut ret: Digest = Digest::default();
match self {
Expand Down
8 changes: 4 additions & 4 deletions src/type_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ fn annotate_stmt(
ast::Stmt::Return(opt_expr) => match (opt_expr, &env_fn_signature.output) {
(None, ast_types::DataType::Tuple(tys)) => assert_eq!(
0,
tys.len(),
tys.element_count(),
"Return without value; expect {} to return nothing.",
env_fn_signature.name
),
Expand Down Expand Up @@ -565,7 +565,7 @@ fn annotate_stmt(
enum_name,
"Match conditions on type {} must all be of same type. Got bad type: {enum_name}", enum_type.name);
let variant_data_tuple = enum_type.variant_data_type(variant_name);
assert_eq!(variant_data_tuple.len(), data_bindings.len(), "Number of bindings must match number of elements in variant data tuple");
assert_eq!(variant_data_tuple.element_count(), data_bindings.len(), "Number of bindings must match number of elements in variant data tuple");
assert!(
has_unique_elements(data_bindings.iter().map(|x| &x.name)),
"Name repetition in pattern matching not allowed"
Expand Down Expand Up @@ -713,13 +713,13 @@ pub fn annotate_identifier_type(
}
ast::IndexExpr::Static(index) => Some(index),
};
statically_known_index.map(|x| {
if let Some(x) = statically_known_index {
assert!(
*x < array_type.length,
"Index for array out-of-range. Index was {x}, length is {}",
array_type.length
)
});
}

break &array_type.element_type;
} else if let ast_types::DataType::Reference(inner_type) = forced_sequence_type {
Expand Down

0 comments on commit d75a644

Please sign in to comment.