Skip to content

Commit

Permalink
clippy: fix clippy lints for 1.83
Browse files Browse the repository at this point in the history
- derive(FromPrimitive) does not work with new clippy. Need to implement it manually
  We can maybe revert it in the future. However, this change is not a big deal.
- Converted all manually created c-strings to c"" literals
- Removed some unnecessary return statements detected by clippy
  • Loading branch information
muzarski committed Nov 28, 2024
1 parent 08bc6a5 commit ae42eb2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
2 changes: 2 additions & 0 deletions scylla-rust-wrapper/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,8 @@ mod tests {
);

// empty strings
// Allow it, since c"" somehow clashes with #[ntest] proc macro...
#[allow(clippy::manual_c_str_literals)]
let empty_str = "\0".as_ptr() as *const i8;
assert_cass_error_eq!(
cass_cluster_set_load_balance_dc_aware(cluster_raw, std::ptr::null(), 0, 0),
Expand Down
6 changes: 3 additions & 3 deletions scylla-rust-wrapper/src/exec_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ mod tests {
assert_cass_error_eq!(
cass_execution_profile_set_load_balance_dc_aware(
profile_raw,
"eu\0".as_ptr() as *const i8,
c"eu".as_ptr(),
0,
0
),
Expand Down Expand Up @@ -562,7 +562,7 @@ mod tests {
assert_cass_error_eq!(
cass_execution_profile_set_load_balance_dc_aware(
profile_raw,
"eu\0".as_ptr() as *const i8,
c"eu".as_ptr(),
1,
0
),
Expand All @@ -571,7 +571,7 @@ mod tests {
assert_cass_error_eq!(
cass_execution_profile_set_load_balance_dc_aware(
profile_raw,
"eu\0".as_ptr() as *const i8,
c"eu".as_ptr(),
0,
1
),
Expand Down
24 changes: 22 additions & 2 deletions scylla-rust-wrapper/src/inet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::argconv::*;
use crate::cass_error::CassError;
use crate::types::*;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use std::convert::TryFrom;
use std::convert::TryInto;
Expand All @@ -14,12 +13,33 @@ pub(crate) use crate::cass_inet_types::CassInet;

#[repr(u8)] // address_length field in CassInet is cass_uint8_t
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, FromPrimitive)]
#[derive(Debug, Copy, Clone)]
pub enum CassInetLength {
CASS_INET_V4 = 4,
CASS_INET_V6 = 16,
}

// Need to implement manually, because of the clippy 0.1.83 lints:
// | `FromPrimitive` is not local
// | move the `impl` block outside of this constant `_IMPL_NUM_FromPrimitive_FOR_CassInetLength`
impl FromPrimitive for CassInetLength {
fn from_i64(n: i64) -> Option<Self> {
match n {
4 => Some(Self::CASS_INET_V4),
16 => Some(Self::CASS_INET_V6),
_ => None,
}
}

fn from_u64(n: u64) -> Option<Self> {
match n {
4 => Some(Self::CASS_INET_V4),
16 => Some(Self::CASS_INET_V6),
_ => None,
}
}
}

unsafe fn cass_inet_init(address: *const cass_uint8_t, address_length: CassInetLength) -> CassInet {
let mut array = [0; 16];
let length = address_length as usize;
Expand Down
2 changes: 1 addition & 1 deletion scylla-rust-wrapper/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
severity: (*event.metadata().level()).into(),
file: target.as_ptr() as *const c_char,
line: event.metadata().line().unwrap_or(0) as i32,
function: "\0".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata
function: c"".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata
message: str_to_arr(message),
};

Expand Down
12 changes: 5 additions & 7 deletions scylla-rust-wrapper/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n(
is_case_sensitive = true;
}

return row_from_raw
row_from_raw
.result_metadata
.col_specs
.iter()
Expand All @@ -1115,13 +1115,11 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n(
is_case_sensitive && col_spec.name == name_str
|| !is_case_sensitive && col_spec.name.eq_ignore_ascii_case(name_str)
})
.map(|(index, _)| {
return match row_from_raw.columns.get(index) {
Some(value) => value as *const CassValue,
None => std::ptr::null(),
};
.map(|(index, _)| match row_from_raw.columns.get(index) {
Some(value) => value as *const CassValue,
None => std::ptr::null(),
})
.unwrap_or(std::ptr::null());
.unwrap_or(std::ptr::null())
}

#[no_mangle]
Expand Down

0 comments on commit ae42eb2

Please sign in to comment.