Skip to content

Commit

Permalink
Cargo clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timfennis committed Nov 9, 2024
1 parent e6cab52 commit d5f8cef
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions andy-cpp-macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn wrap_function(function: syn::ItemFn) -> WrappedFunction {
#inner

// Initialize the arguments and map them from the Andy C types to the rust types
let [#(#arguments, )*] = values else { panic!("unable to unpack arguments") };
let [#(#arguments, )*] = values else { panic!("actual argument count did not match expected argument count when calling native method, this should be prevented by the runtime") };
#(#argument_init_code_blocks; )*

// Call the inner function with the unpacked arguments
Expand Down Expand Up @@ -202,7 +202,7 @@ fn create_temp_variable(
let crate::interpreter::value::Value::Function(#temp_var) = #argument_var_name else {
panic!("Value #position needed to be a Sequence::Map but wasn't");
};
let #argument_var_name = Callable {
let #argument_var_name = &Callable {
function: Rc::clone(#temp_var),
environment: environment
};
Expand Down
2 changes: 1 addition & 1 deletion src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ExpressionLocation {
values: tuple_values,
} => tuple_values
.iter()
.map(|it| it.try_into_identifier().map(|ident| ident.to_string()))
.map(|it| it.try_into_identifier().map(std::string::ToString::to_string))
.collect::<Result<Vec<String>, EvaluationError>>(),
_ => Err(EvaluationError::syntax_error(
"expected a parameter list".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ pub(crate) fn evaluate_expression(
if let Some(name) = name {
environment
.borrow_mut()
.declare_function(&name, user_function);
.declare_function(name, user_function);

Value::Unit
} else {
Expand Down Expand Up @@ -627,7 +627,7 @@ fn declare_or_assign_variable(
environment.borrow_mut().declare(identifier, value.clone());
} else {
if !environment.borrow().contains(identifier) {
return Err(EvaluationError::undefined_variable(identifier, span))?;
Err(EvaluationError::undefined_variable(identifier, span))?;
}

environment.borrow_mut().assign(identifier, value.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::interpreter::sequence::Sequence;
use crate::interpreter::value::{Value, ValueType};
use crate::lexer::Span;

/// Callable is a wrapper aroudn a OverloadedFunction pointer and the environment to make it
/// Callable is a wrapper aroudn a `OverloadedFunction` pointer and the environment to make it
/// easy to have an executable fucntion as a method signature in the standard library
pub struct Callable<'a> {
pub function: Rc<RefCell<OverloadedFunction>>,
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod inner {
Sequence::Iterator(rc) => {
let mut iter = rc.borrow_mut();
let mut out = HashMap::new();
while let Some(item) = iter.next() {
for item in iter.by_ref() {
out.insert(item, Value::Unit);
}
out
Expand Down
26 changes: 13 additions & 13 deletions src/stdlib/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ mod inner {
}
}

pub fn fold(seq: &mut Sequence, initial: Value, function: Callable) -> EvaluationResult {
pub fn fold(seq: &mut Sequence, initial: Value, function: &Callable) -> EvaluationResult {
fold_iterator(mut_seq_into_iterator(seq), initial, function)
}

pub fn reduce(seq: &mut Sequence, function: Callable) -> EvaluationResult {
pub fn reduce(seq: &mut Sequence, function: &Callable) -> EvaluationResult {
let mut iterator = mut_seq_into_iterator(seq);
let fst = iterator
.next()
Expand All @@ -180,7 +180,7 @@ mod inner {
fold_iterator(iterator, fst, function)
}

pub fn filter(seq: &mut Sequence, predicate: Callable) -> EvaluationResult {
pub fn filter(seq: &mut Sequence, predicate: &Callable) -> EvaluationResult {
let iterator = mut_seq_into_iterator(seq);
let mut out = Vec::new();
for element in iterator {
Expand All @@ -199,7 +199,7 @@ mod inner {
Ok(out.into())
}

pub fn none(seq: &mut Sequence, function: Callable) -> EvaluationResult {
pub fn none(seq: &mut Sequence, function: &Callable) -> EvaluationResult {
for item in mut_seq_into_iterator(seq) {
match function.call(&mut [item?])? {
Value::Bool(true) => return Ok(Value::Bool(false)),
Expand All @@ -216,7 +216,7 @@ mod inner {

Ok(Value::Bool(true))
}
pub fn all(seq: &mut Sequence, function: Callable) -> EvaluationResult {
pub fn all(seq: &mut Sequence, function: &Callable) -> EvaluationResult {
for item in mut_seq_into_iterator(seq) {
match function.call(&mut [item?])? {
Value::Bool(true) => {}
Expand All @@ -234,7 +234,7 @@ mod inner {
Ok(Value::Bool(true))
}

pub fn any(seq: &mut Sequence, function: Callable) -> EvaluationResult {
pub fn any(seq: &mut Sequence, function: &Callable) -> EvaluationResult {
for item in mut_seq_into_iterator(seq) {
match function.call(&mut [item?])? {
Value::Bool(true) => return Ok(Value::Bool(true)),
Expand All @@ -252,11 +252,11 @@ mod inner {
Ok(Value::Bool(false))
}

pub fn map(seq: &mut Sequence, function: Callable) -> EvaluationResult {
let mut iterator = mut_seq_into_iterator(seq);
pub fn map(seq: &mut Sequence, function: &Callable) -> EvaluationResult {
let iterator = mut_seq_into_iterator(seq);
let mut out = Vec::new();

while let Some(item) = iterator.next() {
for item in iterator {
let item = item?;
out.push(function.call(&mut [item])?);
}
Expand All @@ -273,7 +273,7 @@ mod inner {
})
}

pub fn first_or_else(seq: &mut Sequence, default: Callable) -> EvaluationResult {
pub fn first_or_else(seq: &mut Sequence, default: &Callable) -> EvaluationResult {
let mut iterator = mut_seq_into_iterator(seq);
Ok(if let Some(item) = iterator.next() {
item?
Expand All @@ -284,12 +284,12 @@ mod inner {
}

fn fold_iterator(
mut iterator: MutableValueIntoIterator,
iterator: MutableValueIntoIterator,
initial: Value,
function: Callable,
function: &Callable,
) -> EvaluationResult {
let mut acc = initial;
while let Some(item) = iterator.next() {
for item in iterator {
acc = function.call(&mut [acc, item?])?;
}

Expand Down

0 comments on commit d5f8cef

Please sign in to comment.