From 854005b977e40ac702e03fe604c7e0be7666550b Mon Sep 17 00:00:00 2001 From: Lauri Virtanen Date: Sun, 29 Dec 2024 18:54:08 +0200 Subject: [PATCH 1/4] Run `cargo clippy --fix && cargo fmt` --- core/json/de.rs | 2 +- core/json/ser.rs | 16 ++++++++-------- core/storage/btree.rs | 8 ++++---- core/translate/emitter.rs | 12 ++++++------ core/translate/insert.rs | 4 ++-- core/translate/optimizer.rs | 2 +- core/translate/planner.rs | 4 ++-- core/types.rs | 2 +- core/vdbe/likeop.rs | 8 +++----- core/vdbe/mod.rs | 6 +++--- 10 files changed, 31 insertions(+), 33 deletions(-) diff --git a/core/json/de.rs b/core/json/de.rs index 02bad4adb..b96a29792 100644 --- a/core/json/de.rs +++ b/core/json/de.rs @@ -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(self, visitor: V) -> Result diff --git a/core/json/ser.rs b/core/json/ser.rs index 1afb8b497..3d5646584 100644 --- a/core/json/ser.rs +++ b/core/json/ser.rs @@ -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; diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 77f459968..ed9070514 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -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; diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index c9b66d98e..e8d0a788c 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -663,7 +663,7 @@ fn open_loop( }); } - return Ok(()); + Ok(()) } SourceOperator::Scan { id, @@ -722,7 +722,7 @@ fn open_loop( } } - return Ok(()); + Ok(()) } SourceOperator::Search { id, @@ -905,10 +905,10 @@ fn open_loop( } } - return Ok(()); + Ok(()) } SourceOperator::Nothing => { - return Ok(()); + Ok(()) } } } @@ -978,14 +978,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, diff --git a/core/translate/insert.rs b/core/translate/insert.rs index 31b263195..50d0277f7 100644 --- a/core/translate/insert.rs +++ b/core/translate/insert.rs @@ -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, diff --git a/core/translate/optimizer.rs b/core/translate/optimizer.rs index 1463c0402..217241f2a 100644 --- a/core/translate/optimizer.rs +++ b/core/translate/optimizer.rs @@ -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)), diff --git a/core/translate/planner.rs b/core/translate/planner.rs index 154f7e1c0..24b5a5d73 100644 --- a/core/translate/planner.rs +++ b/core/translate/planner.rs @@ -476,7 +476,7 @@ pub fn prepare_select_plan<'a>(schema: &Schema, select: ast::Select) -> Result

{ Blob(&'a Vec), } -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"), diff --git a/core/vdbe/likeop.rs b/core/vdbe/likeop.rs index f4ef62f8d..2d01e6c0d 100644 --- a/core/vdbe/likeop.rs +++ b/core/vdbe/likeop.rs @@ -8,11 +8,9 @@ pub fn construct_like_escape_arg(escape_value: &OwnedValue) -> Result 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(), + )), } } _ => { diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 2d731d133..8a8c60c97 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -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::() .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()); } } From 55916fdd9d6276887693090149c0e19cf6134995 Mon Sep 17 00:00:00 2001 From: Lauri Virtanen Date: Sun, 29 Dec 2024 18:57:02 +0200 Subject: [PATCH 2/4] Remove function parameter as it's only used in recursion --- core/translate/emitter.rs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index e8d0a788c..9d1c124da 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -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()); @@ -907,9 +897,7 @@ fn open_loop( Ok(()) } - SourceOperator::Nothing => { - Ok(()) - } + SourceOperator::Nothing => Ok(()), } } @@ -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(()) } From 10065bda35f3ccd9d9a88848742b9b322a7bf05c Mon Sep 17 00:00:00 2001 From: Lauri Virtanen Date: Sun, 29 Dec 2024 19:03:47 +0200 Subject: [PATCH 3/4] Don't use inaccurate pi values, make clippy happy --- core/types.rs | 9 +++++---- core/vdbe/mod.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/types.rs b/core/types.rs index fc0f5301a..7b5814397 100644 --- a/core/types.rs +++ b/core/types.rs @@ -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::()]; 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::()); } @@ -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 diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 8a8c60c97..609b8ad86 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -4097,7 +4097,7 @@ mod tests { expected_len: 2, }, TestCase { - input: OwnedValue::Float(-3.14), + input: OwnedValue::Float(-3.15), expected_len: 1, }, TestCase { From db384c6828a21d449d1c7d984650c6730b41fad0 Mon Sep 17 00:00:00 2001 From: Lauri Virtanen Date: Sun, 29 Dec 2024 19:08:34 +0200 Subject: [PATCH 4/4] Simplify init of `delimiter_expr`s Clippy: https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init --- core/translate/expr.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/core/translate/expr.rs b/core/translate/expr.rs index ff17aa0b0..8b91a2969 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -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"), };