From c831764d346a48f697ad861265ba573c68add35c Mon Sep 17 00:00:00 2001 From: Congyu WANG Date: Wed, 15 May 2024 08:43:21 +0800 Subject: [PATCH] add clippy msrv and some clippy fixes --- clippy.toml | 1 + src/compaction_filter_factory.rs | 2 +- src/db.rs | 14 +++++++------- src/db_options.rs | 18 ++++++------------ src/merge_operator.rs | 5 +---- src/prop_name.rs | 4 ++-- src/transactions/optimistic_transaction_db.rs | 4 ++-- src/transactions/transaction.rs | 2 +- src/transactions/transaction_db.rs | 8 ++++---- tests/test_backup.rs | 2 +- tests/test_transaction_db.rs | 2 +- 11 files changed, 27 insertions(+), 35 deletions(-) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 000000000..1645c19f3 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +msrv = "1.70.0" diff --git a/src/compaction_filter_factory.rs b/src/compaction_filter_factory.rs index 5895cdbe1..385533815 100644 --- a/src/compaction_filter_factory.rs +++ b/src/compaction_filter_factory.rs @@ -37,7 +37,7 @@ pub unsafe extern "C" fn name_callback(raw_self: *mut c_void) -> *const c_cha where F: CompactionFilterFactory, { - let self_ = &*(raw_self as *const c_void as *const F); + let self_ = &*(raw_self.cast_const() as *const F); self_.name().as_ptr() } diff --git a/src/db.rs b/src/db.rs index da4c37885..7f0a6de53 100644 --- a/src/db.rs +++ b/src/db.rs @@ -650,7 +650,7 @@ impl DBWithThreadMode { let cfopts: Vec<_> = cfs_v .iter() - .map(|cf| cf.options.inner as *const _) + .map(|cf| cf.options.inner.cast_const()) .collect(); db = Self::open_cf_raw( @@ -1161,7 +1161,7 @@ impl DBCommon { .collect(); let ptr_cfs: Vec<_> = cfs_and_keys .iter() - .map(|(c, _)| c.inner() as *const _) + .map(|(c, _)| c.inner().cast_const()) .collect(); let mut values = vec![ptr::null_mut(); ptr_keys.len()]; @@ -1239,7 +1239,7 @@ impl DBCommon { ); pinned_values .into_iter() - .zip(errors.into_iter()) + .zip(errors) .map(|(v, e)| { if e.is_null() { if v.is_null() { @@ -2014,7 +2014,7 @@ impl DBCommon { self.inner.inner(), cpaths.as_ptr(), paths_v.len(), - opts.inner as *const _ + opts.inner.cast_const() )); Ok(()) } @@ -2033,7 +2033,7 @@ impl DBCommon { cf.inner(), cpaths.as_ptr(), paths_v.len(), - opts.inner as *const _ + opts.inner.cast_const() )); Ok(()) } @@ -2326,8 +2326,8 @@ pub(crate) fn convert_values( ) -> Vec>, Error>> { values .into_iter() - .zip(values_sizes.into_iter()) - .zip(errors.into_iter()) + .zip(values_sizes) + .zip(errors) .map(|((v, s), e)| { if e.is_null() { let value = unsafe { crate::ffi_util::raw_data(v, s) }; diff --git a/src/db_options.rs b/src/db_options.rs index 2ee25b3fe..bae5b8613 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -217,16 +217,13 @@ pub(crate) struct OptionsMustOutliveDB { impl OptionsMustOutliveDB { pub(crate) fn clone(&self) -> Self { Self { - env: self.env.as_ref().map(Env::clone), - row_cache: self.row_cache.as_ref().map(Cache::clone), + env: self.env.clone(), + row_cache: self.row_cache.clone(), block_based: self .block_based .as_ref() .map(BlockBasedOptionsMustOutliveDB::clone), - write_buffer_manager: self - .write_buffer_manager - .as_ref() - .map(WriteBufferManager::clone), + write_buffer_manager: self.write_buffer_manager.clone(), } } } @@ -239,7 +236,7 @@ struct BlockBasedOptionsMustOutliveDB { impl BlockBasedOptionsMustOutliveDB { fn clone(&self) -> Self { Self { - block_cache: self.block_cache.as_ref().map(Cache::clone), + block_cache: self.block_cache.clone(), } } } @@ -1112,10 +1109,7 @@ impl Options { /// /// Default: empty pub fn set_db_paths(&mut self, paths: &[DBPath]) { - let mut paths: Vec<_> = paths - .iter() - .map(|path| path.inner as *const ffi::rocksdb_dbpath_t) - .collect(); + let mut paths: Vec<_> = paths.iter().map(|path| path.inner.cast_const()).collect(); let num_paths = paths.len(); unsafe { ffi::rocksdb_options_set_db_paths(self.inner, paths.as_mut_ptr(), num_paths); @@ -2499,7 +2493,7 @@ impl Options { unsafe { ffi::rocksdb_options_set_max_bytes_for_level_multiplier_additional( self.inner, - level_values.as_ptr() as *mut c_int, + level_values.as_ptr().cast_mut(), count, ); } diff --git a/src/merge_operator.rs b/src/merge_operator.rs index b52113e42..22b0cb780 100644 --- a/src/merge_operator.rs +++ b/src/merge_operator.rs @@ -211,10 +211,7 @@ impl MergeOperands { let len_ptr = (base_len + (spacing_len * index)) as *const size_t; let len = *len_ptr; let ptr = base + (spacing * index); - Some(slice::from_raw_parts( - *(ptr as *const *const u8) as *const u8, - len, - )) + Some(slice::from_raw_parts(*(ptr as *const *const u8), len)) } } } diff --git a/src/prop_name.rs b/src/prop_name.rs index 8f1c04671..6aa72cc5c 100644 --- a/src/prop_name.rs +++ b/src/prop_name.rs @@ -309,13 +309,13 @@ fn sanity_checks() { } #[test] -#[should_panic] +#[should_panic(expected = "input contained interior nul byte")] fn test_interior_nul() { PropName::new_unwrap("interior nul\0\0"); } #[test] -#[should_panic] +#[should_panic(expected = "input was not nul-terminated")] fn test_non_nul_terminated() { PropName::new_unwrap("no nul terminator"); } diff --git a/src/transactions/optimistic_transaction_db.rs b/src/transactions/optimistic_transaction_db.rs index 89a061ce5..f10df8b89 100644 --- a/src/transactions/optimistic_transaction_db.rs +++ b/src/transactions/optimistic_transaction_db.rs @@ -172,7 +172,7 @@ impl OptimisticTransactionDB { let cfopts: Vec<_> = cfs_v .iter() - .map(|cf| cf.options.inner as *const _) + .map(|cf| cf.options.inner.cast_const()) .collect(); db = Self::open_cf_raw(opts, &cpath, &cfs_v, &cfnames, &cfopts, &mut cfhandles)?; @@ -268,7 +268,7 @@ impl OptimisticTransactionDB { std::ptr::null_mut(), ) }, - _marker: PhantomData::default(), + _marker: PhantomData, } } diff --git a/src/transactions/transaction.rs b/src/transactions/transaction.rs index 089e1ad7d..f0bc6259d 100644 --- a/src/transactions/transaction.rs +++ b/src/transactions/transaction.rs @@ -556,7 +556,7 @@ impl<'db, DB> Transaction<'db, DB> { .collect(); let ptr_cfs: Vec<_> = cfs_and_keys .iter() - .map(|(c, _)| c.inner() as *const _) + .map(|(c, _)| c.inner().cast_const()) .collect(); let mut values = vec![ptr::null_mut(); ptr_keys.len()]; diff --git a/src/transactions/transaction_db.rs b/src/transactions/transaction_db.rs index 365ac2bba..09a488a94 100644 --- a/src/transactions/transaction_db.rs +++ b/src/transactions/transaction_db.rs @@ -266,7 +266,7 @@ impl TransactionDB { let cfopts: Vec<_> = cfs_v .iter() - .map(|cf| cf.options.inner as *const _) + .map(|cf| cf.options.inner.cast_const()) .collect(); db = Self::open_cf_raw( @@ -408,7 +408,7 @@ impl TransactionDB { std::ptr::null_mut(), ) }, - _marker: PhantomData::default(), + _marker: PhantomData, } } @@ -423,7 +423,7 @@ impl TransactionDB { .drain(0..) .map(|inner| Transaction { inner, - _marker: PhantomData::default(), + _marker: PhantomData, }) .collect() } @@ -600,7 +600,7 @@ impl TransactionDB { .collect(); let ptr_cfs: Vec<_> = cfs_and_keys .iter() - .map(|(c, _)| c.inner() as *const _) + .map(|(c, _)| c.inner().cast_const()) .collect(); let mut values = vec![ptr::null_mut(); ptr_keys.len()]; diff --git a/tests/test_backup.rs b/tests/test_backup.rs index 5109e5274..551830de3 100644 --- a/tests/test_backup.rs +++ b/tests/test_backup.rs @@ -90,7 +90,7 @@ fn restore_from_backup() { assert!(i.size > 0); }); - let backup_id = info.get(0).unwrap().backup_id; + let backup_id = info.first().unwrap().backup_id; let mut restore_option = RestoreOptions::default(); restore_option.set_keep_log_files(false); // true to keep log files let restore_status = backup_engine.restore_from_backup( diff --git a/tests/test_transaction_db.rs b/tests/test_transaction_db.rs index 2deb3dc83..901b7ec32 100644 --- a/tests/test_transaction_db.rs +++ b/tests/test_transaction_db.rs @@ -659,7 +659,7 @@ fn two_phase_commit() { let txns = db.prepared_transactions(); assert_eq!(txns.len(), 2); - for (_, txn) in txns.into_iter().enumerate() { + for txn in txns.into_iter() { let name = txn.get_name().unwrap(); if name == b"t1" {