Skip to content

Commit aed0e90

Browse files
Fix clippy lints (#456)
* Fix clippy warnings in redismodule-rs-macros-internals * Fix clippy warnings in redismodule-rs-macros * chore: Format * Fix clippy warnings in main crate
1 parent 927bc5c commit aed0e90

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

redismodule-rs-macros-internals/src/api_versions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ pub(crate) fn get_feature_flags(
6161
(
6262
all_lower_versions
6363
.into_iter()
64-
.map(|s| quote!(feature = #s).into())
64+
.map(|s| quote!(feature = #s))
6565
.collect(),
6666
all_upper_versions
6767
.into_iter()
68-
.map(|s| quote!(feature = #s).into())
68+
.map(|s| quote!(feature = #s))
6969
.collect(),
7070
)
7171
}

redismodule-rs-macros-internals/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn api(item: TokenStream) -> TokenStream {
7272
// if we do not have a version mapping, we assume the API exists and return the minimum version.
7373
let api_version = API_VERSION_MAPPING
7474
.get(&item.to_string())
75-
.map(|v| *v)
75+
.copied()
7676
.unwrap_or(*API_OLDEST_VERSION);
7777
api_version.max(min_api_version)
7878
});

redismodule-rs-macros/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,20 @@ pub fn info_command_handler(_attr: TokenStream, item: TokenStream) -> TokenStrea
433433
/// # Notes
434434
///
435435
/// 1. The name of the struct is taken "as is", so if it starts with
436-
/// a capital letter (written in the "Upper Camel Case"), like in this
437-
/// example - `Info`, then it will be compiled into a string prefixed
438-
/// with the module name, ending up being `"module_name_Info"`-named
439-
/// section. The fields of the struct are also prefixed with the module
440-
/// name, so the `field_1` will be prefixed with `module_name_` as well.
436+
/// a capital letter (written in the "Upper Camel Case"), like in this
437+
/// example - `Info`, then it will be compiled into a string prefixed
438+
/// with the module name, ending up being `"module_name_Info"`-named
439+
/// section. The fields of the struct are also prefixed with the module
440+
/// name, so the `field_1` will be prefixed with `module_name_` as well.
441441
/// 2. In dictionaries, the type of dictionaries supported varies,
442-
/// for now it is [`std::collections::BTreeMap`] and
443-
/// [`std::collections::HashMap`].
442+
/// for now it is [`std::collections::BTreeMap`] and
443+
/// [`std::collections::HashMap`].
444444
/// 3. In dictionaries, the value type can be anything that can be
445-
/// converted into an object of type
446-
/// [`redis_module::InfoContextBuilderFieldBottomLevelValue`], for
447-
/// example, a [`std::string::String`] or [`u64`]. Please, refer to
448-
/// [`redis_module::InfoContextBuilderFieldBottomLevelValue`] for more
449-
/// information.
445+
/// converted into an object of type
446+
/// [`redis_module::InfoContextBuilderFieldBottomLevelValue`], for
447+
/// example, a [`std::string::String`] or [`u64`]. Please, refer to
448+
/// [`redis_module::InfoContextBuilderFieldBottomLevelValue`] for more
449+
/// information.
450450
#[proc_macro_derive(InfoSection)]
451451
pub fn info_section(item: TokenStream) -> TokenStream {
452452
info_section::info_section(item)

src/configuration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ extern "C" fn i64_configuration_get<T: ConfigurationValue<i64> + 'static>(
227227
private_data.get_val()
228228
}
229229

230+
#[expect(clippy::too_many_arguments)]
230231
pub fn register_i64_configuration<T: ConfigurationValue<i64>>(
231232
ctx: &Context,
232233
name: &str,

src/context/commands.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ pub struct FindKeysNum {
203203
/// After Redis finds the location from where it needs to start looking for keys,
204204
/// Redis will start finding keys base on the information in this enum.
205205
/// There are 2 possible options:
206-
/// 1. Range - Required to specify additional 3 more values, `last_key`, `steps`, and `limit`.
207-
/// 2. Keynum - Required to specify additional 3 more values, `keynumidx`, `firstkey`, and `keystep`.
208-
/// Redis will consider the argument at `keynumidx` as an indicator
209-
/// to the number of keys that will follow. Then it will start
210-
/// from `firstkey` and jump each `keystep` to find the keys.
206+
/// 1. Range - Required to specify additional 3 more values, `last_key`, `steps`, and `limit`.
207+
/// 2. Keynum - Required to specify additional 3 more values, `keynumidx`, `firstkey`, and `keystep`.
208+
/// Redis will consider the argument at `keynumidx` as an indicator
209+
/// to the number of keys that will follow. Then it will start
210+
/// from `firstkey` and jump each `keystep` to find the keys.
211211
pub enum FindKeys {
212212
Range(FindKeysRange),
213213
Keynum(FindKeysNum),
@@ -358,6 +358,7 @@ pub struct RedisModuleCommandArg {
358358
}
359359

360360
impl RedisModuleCommandArg {
361+
#[expect(clippy::too_many_arguments)]
361362
pub fn new(
362363
name: String,
363364
type_: u32,
@@ -402,6 +403,7 @@ pub struct CommandInfo {
402403
}
403404

404405
impl CommandInfo {
406+
#[expect(clippy::too_many_arguments)]
405407
pub fn new(
406408
name: String,
407409
flags: Option<String>,

src/context/defrag.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ unsafe impl RedisLockIndicator for DefragContext {}
2929

3030
impl DefragContext {
3131
/// Creates a new [`DefragContext`] from a poiter to [`raw::RedisModuleDefragCtx`].
32-
/// The function is considered unsafe because the provided pointer
33-
/// must be a valid pointer to [`raw::RedisModuleDefragCtx`], and the Redis GIL must be held.
3432
/// The function is exposed for users that wants to implement the defrag function
3533
/// on their module datatype, they can use this function to create [`DefragContext`]
3634
/// that can be used in a safely manner.
35+
///
36+
/// # Safety
37+
///
38+
/// The function is considered unsafe because the provided pointer
39+
/// must be a valid pointer to [`raw::RedisModuleDefragCtx`], and the Redis GIL must be held.
3740
/// Notice that the returned [`DefragContext`] borrows the pointer to [`raw::RedisModuleDefragCtx`]
3841
/// so it can not outlive it (this means that it should not be used once the defrag callback ends).
3942
pub unsafe fn new(defrag_ctx: *mut raw::RedisModuleDefragCtx) -> DefragContext {
@@ -120,12 +123,14 @@ impl DefragContext {
120123
/// If defragmentation was not necessary, NULL is returned and the operation has
121124
/// no other effect.
122125
///
123-
/// If a non-NULL value is returned, the caller should use the new pointer instead
124-
/// of the old one and update any reference to the old pointer, which must not
125-
/// be used again.
126+
/// # Safety
126127
///
127128
/// The function is unsafe because it is assumed that the pointer is valid and previusly
128129
/// allocated. It is considered undefined if this is not the case.
130+
///
131+
/// If a non-NULL value is returned, the caller should use the new pointer instead
132+
/// of the old one and update any reference to the old pointer, which must not
133+
/// be used again.
129134
pub unsafe fn defrag_realloc<T>(&self, mut ptr: *mut T) -> *mut T {
130135
let new_ptr: *mut T = RedisModule_DefragAlloc
131136
.expect("RedisModule_DefragAlloc should be available.")(

src/raw.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ extern "C" {
206206

207207
///////////////////////////////////////////////////////////////
208208

209-
pub const FMT: *const c_char = b"v\0".as_ptr().cast::<c_char>();
209+
pub const FMT: *const c_char = c"v".as_ptr().cast::<c_char>();
210210

211211
// REDISMODULE_HASH_DELETE is defined explicitly here because bindgen cannot
212212
// parse typecasts in C macro constants yet.
213213
// See https://github.com/rust-lang/rust-bindgen/issues/316
214-
pub const REDISMODULE_HASH_DELETE: *const RedisModuleString = 1 as *const RedisModuleString;
214+
pub const REDISMODULE_HASH_DELETE: *const RedisModuleString =
215+
std::ptr::dangling::<RedisModuleString>();
215216

216217
// Helper functions for the raw bindings.
217218

0 commit comments

Comments
 (0)