Skip to content

Commit

Permalink
add clippy msrv and some clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang authored and zaidoon1 committed May 17, 2024
1 parent 4cc90fc commit d8feceb
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 35 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.70.0"
2 changes: 1 addition & 1 deletion src/compaction_filter_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe extern "C" fn name_callback<F>(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()
}

Expand Down
14 changes: 7 additions & 7 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ impl<T: ThreadMode> DBWithThreadMode<T> {

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(
Expand Down Expand Up @@ -1161,7 +1161,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
.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()];
Expand Down Expand Up @@ -1239,7 +1239,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
);
pinned_values
.into_iter()
.zip(errors.into_iter())
.zip(errors)
.map(|(v, e)| {
if e.is_null() {
if v.is_null() {
Expand Down Expand Up @@ -2014,7 +2014,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
self.inner.inner(),
cpaths.as_ptr(),
paths_v.len(),
opts.inner as *const _
opts.inner.cast_const()
));
Ok(())
}
Expand All @@ -2033,7 +2033,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
cf.inner(),
cpaths.as_ptr(),
paths_v.len(),
opts.inner as *const _
opts.inner.cast_const()
));
Ok(())
}
Expand Down Expand Up @@ -2326,8 +2326,8 @@ pub(crate) fn convert_values(
) -> Vec<Result<Option<Vec<u8>>, 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) };
Expand Down
18 changes: 6 additions & 12 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/merge_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/prop_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
4 changes: 2 additions & 2 deletions src/transactions/optimistic_transaction_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<T: ThreadMode> OptimisticTransactionDB<T> {

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)?;
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<T: ThreadMode> OptimisticTransactionDB<T> {
std::ptr::null_mut(),
)
},
_marker: PhantomData::default(),
_marker: PhantomData,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/transactions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
8 changes: 4 additions & 4 deletions src/transactions/transaction_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<T: ThreadMode> TransactionDB<T> {

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(
Expand Down Expand Up @@ -408,7 +408,7 @@ impl<T: ThreadMode> TransactionDB<T> {
std::ptr::null_mut(),
)
},
_marker: PhantomData::default(),
_marker: PhantomData,
}
}

Expand All @@ -423,7 +423,7 @@ impl<T: ThreadMode> TransactionDB<T> {
.drain(0..)
.map(|inner| Transaction {
inner,
_marker: PhantomData::default(),
_marker: PhantomData,
})
.collect()
}
Expand Down Expand Up @@ -600,7 +600,7 @@ impl<T: ThreadMode> TransactionDB<T> {
.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()];
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transaction_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit d8feceb

Please sign in to comment.