Make clippy a happy chappy

This commit is contained in:
Andrew Morris
2023-07-07 16:08:28 +10:00
parent 6c72b32111
commit 581965e01b
59 changed files with 728 additions and 992 deletions

View File

@@ -3,6 +3,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static EVERY: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(EveryState::default()))),
};

View File

@@ -5,6 +5,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static FILTER: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(FilterState::default()))),
};
@@ -19,7 +20,7 @@ impl ArrayMappingState for FilterState {
self.filter_results.push(element.clone());
}
return None;
None
}
fn finish(&mut self) -> Val {

View File

@@ -3,6 +3,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static FIND: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(FindState::default()))),
};

View File

@@ -3,6 +3,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static FIND_INDEX: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(FindIndexState::default()))),
};

View File

@@ -5,6 +5,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static FLAT_MAP: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(FlatMapState::default()))),
};
@@ -24,7 +25,7 @@ impl ArrayMappingState for FlatMapState {
}
}
return None;
None
}
fn finish(&mut self) -> Val {

View File

@@ -5,6 +5,7 @@ use super::super::vs_value::Val;
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static MAP: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(MapState::default()))),
};
@@ -16,7 +17,7 @@ struct MapState {
impl ArrayMappingState for MapState {
fn process(&mut self, _i: usize, _element: &Val, mapped: Val) -> Option<Val> {
self.map_results.push(mapped);
return None;
None
}
fn finish(&mut self) -> Val {

View File

@@ -34,15 +34,15 @@ pub struct ArrayMappingFrame {
impl ArrayMappingFrame {
pub fn new(state: Box<dyn ArrayMappingState>) -> ArrayMappingFrame {
return ArrayMappingFrame {
state: state,
ArrayMappingFrame {
state,
early_exit: None,
this: None,
array_i: 0,
mapper: Val::Void,
this_arg: Val::Undefined,
param_i: 0,
};
}
}
}
@@ -139,7 +139,7 @@ impl StackFrameTrait for ArrayMappingFrame {
self.early_exit = self
.state
.process(array_i, element, call_result.return_)
.map(|v| Ok(v));
.map(Ok);
}
fn get_call_result(&mut self) -> CallResult {

View File

@@ -3,6 +3,7 @@ use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static SOME: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(SomeState::default()))),
};

View File

@@ -84,7 +84,7 @@ impl SortTreeNode {
let mid = vals.start + (vals.end - vals.start) / 2;
return SortTreeNode {
SortTreeNode {
data: SortTreeNodeData::Branch(
Box::new(SortTreeNode::new(VecSlice {
vec: vals.vec,
@@ -97,33 +97,27 @@ impl SortTreeNode {
end: vals.end,
})),
),
};
}
}
fn get_compare_elements(&self) -> Option<(Val, Val)> {
match &self.data {
SortTreeNodeData::Branch(left, right) => {
return left
.get_compare_elements()
.or_else(|| right.get_compare_elements());
}
SortTreeNodeData::Branch(left, right) => left
.get_compare_elements()
.or_else(|| right.get_compare_elements()),
SortTreeNodeData::Sorting(_vals, left, right) => {
let lval_opt = left.vec.get(left.pos);
let rval_opt = right.vec.get(right.pos);
match (lval_opt, rval_opt) {
(Some(lval), Some(rval)) => {
return Some((lval.clone(), rval.clone()));
}
(Some(lval), Some(rval)) => Some((lval.clone(), rval.clone())),
_ => {
panic!("Failed to get compare elements from sorting state");
}
}
}
SortTreeNodeData::Sorted(_) => {
return None;
}
};
SortTreeNodeData::Sorted(_) => None,
}
}
fn apply_outcome(&mut self, should_swap: bool) {
@@ -136,26 +130,23 @@ impl SortTreeNode {
SortTreeNodeData::Sorted(left_vals) => {
right.apply_outcome(should_swap);
match &mut right.data {
SortTreeNodeData::Sorted(right_vals) => {
let mut owned_left_vals = vec![];
std::mem::swap(&mut owned_left_vals, left_vals);
let mut owned_right_vals = vec![];
std::mem::swap(&mut owned_right_vals, right_vals);
if let SortTreeNodeData::Sorted(right_vals) = &mut right.data {
let mut owned_left_vals = vec![];
std::mem::swap(&mut owned_left_vals, left_vals);
let mut owned_right_vals = vec![];
std::mem::swap(&mut owned_right_vals, right_vals);
self.data = SortTreeNodeData::Sorting(
vec![],
VecPos {
vec: owned_left_vals,
pos: 0,
},
VecPos {
vec: owned_right_vals,
pos: 0,
},
);
}
_ => {}
self.data = SortTreeNodeData::Sorting(
vec![],
VecPos {
vec: owned_left_vals,
pos: 0,
},
VecPos {
vec: owned_right_vals,
pos: 0,
},
);
};
}
};
@@ -220,12 +211,9 @@ impl StackFrameTrait for SortFrame {
}
fn write_param(&mut self, param: Val) {
match self.param_i {
0 => {
self.comparator = param;
}
_ => {}
};
if self.param_i == 0 {
self.comparator = param;
}
self.param_i += 1;
}
@@ -241,9 +229,7 @@ impl StackFrameTrait for SortFrame {
Val::Void => {
let array_data_mut = Rc::make_mut(array_data);
array_data_mut
.elements
.sort_by(|a, b| a.to_string().cmp(&b.to_string()));
array_data_mut.elements.sort_by_key(|a| a.to_string());
return Ok(FrameStepOk::Pop(CallResult {
return_: Val::Array(array_data.clone()),