Merge 'Clean up more Clippy warnings' from Lauri Virtanen

I ran `cargo clippy --fix` and also fixed some issues manually.
Clippy still warns about some issues - especially in Simulator code.

Closes #574
This commit is contained in:
Pekka Enberg
2024-12-31 10:30:19 +02:00
11 changed files with 47 additions and 69 deletions

View File

@@ -171,7 +171,7 @@ impl<'de> Deserializer<'de> {
}
}
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
impl<'de> de::Deserializer<'de> for &mut Deserializer<'de> {
type Error = Error;
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>

View File

@@ -30,7 +30,7 @@ impl Serializer {
}
}
impl<'a> ser::Serializer for &'a mut Serializer {
impl ser::Serializer for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -237,7 +237,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}
}
impl<'a> ser::SerializeSeq for &'a mut Serializer {
impl ser::SerializeSeq for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -257,7 +257,7 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
}
}
impl<'a> ser::SerializeTuple for &'a mut Serializer {
impl ser::SerializeTuple for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -273,7 +273,7 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
}
}
impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
impl ser::SerializeTupleStruct for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -289,7 +289,7 @@ impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
}
}
impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
impl ser::SerializeTupleVariant for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -306,7 +306,7 @@ impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
}
}
impl<'a> ser::SerializeMap for &'a mut Serializer {
impl ser::SerializeMap for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -334,7 +334,7 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
}
}
impl<'a> ser::SerializeStruct for &'a mut Serializer {
impl ser::SerializeStruct for &mut Serializer {
type Ok = ();
type Error = Error;
@@ -351,7 +351,7 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
}
}
impl<'a> ser::SerializeStructVariant for &'a mut Serializer {
impl ser::SerializeStructVariant for &mut Serializer {
type Ok = ();
type Error = Error;

View File

@@ -1378,10 +1378,10 @@ impl BTreeCursor {
PageType::IndexLeaf => todo!(),
};
cbrk -= size;
if cbrk < first_cell as u64 || pc + size > usable_space {
if cbrk < first_cell || pc + size > usable_space {
todo!("corrupt");
}
assert!(cbrk + size <= usable_space && cbrk >= first_cell as u64);
assert!(cbrk + size <= usable_space && cbrk >= first_cell);
// set new pointer
write_buf[cell_idx..cell_idx + 2].copy_from_slice(&(cbrk as u16).to_be_bytes());
// copy payload
@@ -1394,7 +1394,7 @@ impl BTreeCursor {
// if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
// return SQLITE_CORRUPT_PAGE(pPage);
// }
assert!(cbrk >= first_cell as u64);
assert!(cbrk >= first_cell);
let write_buf = page.as_ptr();
// set new first byte of cell content
@@ -1437,7 +1437,7 @@ impl BTreeCursor {
// #3. freeblocks (linked list of blocks of at least 4 bytes within the cell content area that are not in use due to e.g. deletions)
let mut free_space_bytes =
page.unallocated_region_size() as usize + page.num_frag_free_bytes() as usize;
page.unallocated_region_size() + page.num_frag_free_bytes() as usize;
// #3 is computed by iterating over the freeblocks linked list
let mut cur_freeblock_ptr = page.first_freeblock() as usize;

View File

@@ -241,12 +241,7 @@ fn emit_program_for_select(
inner_loop_emit(&mut program, &mut plan, &mut metadata)?;
// Clean up and close the main execution loop
close_loop(
&mut program,
&plan.source,
&mut metadata,
&plan.referenced_tables,
)?;
close_loop(&mut program, &plan.source, &mut metadata)?;
if let Some(skip_loops_label) = skip_loops_label {
program.resolve_label(skip_loops_label, program.offset());
@@ -338,12 +333,7 @@ fn emit_program_for_delete(
emit_delete_insns(&mut program, &plan.source, &plan.limit, &metadata)?;
// Clean up and close the main execution loop
close_loop(
&mut program,
&plan.source,
&mut metadata,
&plan.referenced_tables,
)?;
close_loop(&mut program, &plan.source, &mut metadata)?;
if let Some(skip_loops_label) = skip_loops_label {
program.resolve_label(skip_loops_label, program.offset());
@@ -663,7 +653,7 @@ fn open_loop(
});
}
return Ok(());
Ok(())
}
SourceOperator::Scan {
id,
@@ -722,7 +712,7 @@ fn open_loop(
}
}
return Ok(());
Ok(())
}
SourceOperator::Search {
id,
@@ -905,11 +895,9 @@ fn open_loop(
}
}
return Ok(());
}
SourceOperator::Nothing => {
return Ok(());
Ok(())
}
SourceOperator::Nothing => Ok(()),
}
}
@@ -978,14 +966,14 @@ fn inner_loop_emit(
);
}
// if we have neither, we emit a ResultRow. In that case, if we have a Limit, we handle that with DecrJumpZero.
return inner_loop_source_emit(
inner_loop_source_emit(
program,
&plan.result_columns,
&plan.aggregates,
metadata,
InnerLoopEmitTarget::ResultRow { limit: plan.limit },
&plan.referenced_tables,
);
)
}
/// This is a helper function for inner_loop_emit,
@@ -1111,7 +1099,6 @@ fn close_loop(
program: &mut ProgramBuilder,
source: &SourceOperator,
metadata: &mut Metadata,
referenced_tables: &[BTreeTableReference],
) -> Result<()> {
match source {
SourceOperator::Join {
@@ -1121,7 +1108,7 @@ fn close_loop(
outer,
..
} => {
close_loop(program, right, metadata, referenced_tables)?;
close_loop(program, right, metadata)?;
if *outer {
let lj_meta = metadata.left_joins.get(id).unwrap();
@@ -1168,7 +1155,7 @@ fn close_loop(
assert!(program.offset() == jump_offset);
}
close_loop(program, left, metadata, referenced_tables)?;
close_loop(program, left, metadata)?;
Ok(())
}

View File

@@ -2265,14 +2265,10 @@ pub fn translate_aggregation(
let delimiter_reg = program.alloc_register();
let expr = &agg.args[0];
let delimiter_expr: ast::Expr;
match &agg.args[1] {
ast::Expr::Column { .. } => {
delimiter_expr = agg.args[1].clone();
}
let delimiter_expr = match &agg.args[1] {
ast::Expr::Column { .. } => agg.args[1].clone(),
ast::Expr::Literal(ast::Literal::String(s)) => {
delimiter_expr = ast::Expr::Literal(ast::Literal::String(s.to_string()));
ast::Expr::Literal(ast::Literal::String(s.to_string()))
}
_ => crate::bail_parse_error!("Incorrect delimiter parameter"),
};
@@ -2448,14 +2444,10 @@ pub fn translate_aggregation_groupby(
let expr_reg = program.alloc_register();
let delimiter_reg = program.alloc_register();
let delimiter_expr: ast::Expr;
match &agg.args[1] {
ast::Expr::Column { .. } => {
delimiter_expr = agg.args[1].clone();
}
let delimiter_expr = match &agg.args[1] {
ast::Expr::Column { .. } => agg.args[1].clone(),
ast::Expr::Literal(ast::Literal::String(s)) => {
delimiter_expr = ast::Expr::Literal(ast::Literal::String(s.to_string()));
ast::Expr::Literal(ast::Literal::String(s.to_string()))
}
_ => crate::bail_parse_error!("Incorrect delimiter parameter"),
};

View File

@@ -349,7 +349,7 @@ pub fn translate_insert(
// Create new rowid if a) not provided by user or b) provided by user but is NULL
program.emit_insn(Insn::NewRowid {
cursor: cursor_id,
rowid_reg: rowid_reg,
rowid_reg,
prev_largest_reg: 0,
});
@@ -366,7 +366,7 @@ pub fn translate_insert(
program.emit_insn_with_label_dependency(
Insn::NotExists {
cursor: cursor_id,
rowid_reg: rowid_reg,
rowid_reg,
target_pc: make_record_label,
},
make_record_label,

View File

@@ -666,7 +666,7 @@ impl Optimizable for ast::Expr {
if id.0.eq_ignore_ascii_case("false") {
return Ok(Some(ConstantPredicate::AlwaysFalse));
}
return Ok(None);
Ok(None)
}
Self::Literal(lit) => match lit {
ast::Literal::Null => Ok(Some(ConstantPredicate::AlwaysFalse)),

View File

@@ -476,7 +476,7 @@ pub fn prepare_select_plan<'a>(schema: &Schema, select: ast::Select) -> Result<P
}
// Parse the LIMIT clause
plan.limit = select.limit.and_then(|limit| parse_limit(limit));
plan.limit = select.limit.and_then(parse_limit);
// Return the unoptimized query plan
Ok(Plan::Select(plan))
@@ -507,7 +507,7 @@ pub fn prepare_delete_plan(
let resolved_where_clauses = parse_where(where_clause, &[table_ref.clone()])?;
// Parse the LIMIT clause
let resolved_limit = limit.and_then(|limit| parse_limit(limit));
let resolved_limit = limit.and_then(parse_limit);
let plan = DeletePlan {
source: SourceOperator::Scan {

View File

@@ -15,7 +15,7 @@ pub enum Value<'a> {
Blob(&'a Vec<u8>),
}
impl<'a> Display for Value<'a> {
impl Display for Value<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Null => write!(f, "NULL"),
@@ -647,7 +647,8 @@ mod tests {
#[test]
fn test_serialize_float() {
let record = OwnedRecord::new(vec![OwnedValue::Float(3.14159)]);
#[warn(clippy::approx_constant)]
let record = OwnedRecord::new(vec![OwnedValue::Float(3.15555)]);
let mut buf = Vec::new();
record.serialize(&mut buf);
@@ -660,7 +661,7 @@ mod tests {
// Check that the bytes after the header can be interpreted as the float
let float_bytes = &buf[header_length..header_length + size_of::<f64>()];
let float = f64::from_be_bytes(float_bytes.try_into().unwrap());
assert_eq!(float, 3.14159);
assert_eq!(float, 3.15555);
// Check that buffer length is correct
assert_eq!(buf.len(), header_length + size_of::<f64>());
}
@@ -709,7 +710,7 @@ mod tests {
let record = OwnedRecord::new(vec![
OwnedValue::Null,
OwnedValue::Integer(42),
OwnedValue::Float(3.14),
OwnedValue::Float(3.15),
OwnedValue::Text(LimboText::new(text.clone())),
]);
let mut buf = Vec::new();
@@ -741,7 +742,7 @@ mod tests {
let val_text = String::from_utf8(text_bytes.to_vec()).unwrap();
assert_eq!(val_int8, 42);
assert_eq!(val_float, 3.14);
assert_eq!(val_float, 3.15);
assert_eq!(val_text, "test");
// Check that buffer length is correct

View File

@@ -8,11 +8,9 @@ pub fn construct_like_escape_arg(escape_value: &OwnedValue) -> Result<char, Limb
let mut escape_chars = text.value.chars();
match (escape_chars.next(), escape_chars.next()) {
(Some(escape), None) => Ok(escape),
_ => {
return Result::Err(LimboError::Constraint(
"ESCAPE expression must be a single character".to_string(),
))
}
_ => Result::Err(LimboError::Constraint(
"ESCAPE expression must be a single character".to_string(),
)),
}
}
_ => {

View File

@@ -2683,7 +2683,7 @@ pub fn exec_soundex(reg: &OwnedValue) -> OwnedValue {
let word: String = s
.value
.chars()
.filter(|c| !c.is_digit(10))
.filter(|c| !c.is_ascii_digit())
.collect::<String>()
.replace(" ", "");
if word.is_empty() {
@@ -2725,7 +2725,7 @@ pub fn exec_soundex(reg: &OwnedValue) -> OwnedValue {
// Remove adjacent same digits
let tmp = tmp.chars().fold(String::new(), |mut acc, ch| {
if acc.chars().last() != Some(ch) {
if !acc.ends_with(ch) {
acc.push(ch);
}
acc
@@ -2741,7 +2741,7 @@ pub fn exec_soundex(reg: &OwnedValue) -> OwnedValue {
// If the first symbol is a digit, replace it with the saved first letter
if let Some(first_digit) = result.chars().next() {
if first_digit.is_digit(10) {
if first_digit.is_ascii_digit() {
result.replace_range(0..1, &first_letter.to_string());
}
}
@@ -4097,7 +4097,7 @@ mod tests {
expected_len: 2,
},
TestCase {
input: OwnedValue::Float(-3.14),
input: OwnedValue::Float(-3.15),
expected_len: 1,
},
TestCase {