Skip to content

Commit 4b494e4

Browse files
jan-auermitsuhiko
authored andcommitted
Fix all clippy lints (redis-rs#267)
1 parent b05e184 commit 4b494e4

File tree

12 files changed

+76
-77
lines changed

12 files changed

+76
-77
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ required-features = ["aio"]
6060
[[bench]]
6161
name = "bench_basic"
6262
harness = false
63+
required-features = ["tokio-rt-core"]
6364

6465
[[example]]
6566
name = "async-multiplexed"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ style-check:
4040

4141
lint:
4242
@rustup component add clippy 2> /dev/null
43-
cargo clippy --all-features
43+
cargo clippy --all-features --all --tests --examples -- -D clippy::all
4444

4545
.PHONY: build test bench docs upload-docs style-check lint

benches/bench_basic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ fn bench_simple_getsetdel_async(b: &mut Bencher) {
3939
runtime
4040
.block_on(async {
4141
let key = "test_key";
42-
let () = redis::cmd("SET")
42+
redis::cmd("SET")
4343
.arg(key)
4444
.arg(42)
4545
.query_async(&mut con)
4646
.await?;
4747
let _: isize = redis::cmd("GET").arg(key).query_async(&mut con).await?;
48-
let () = redis::cmd("DEL").arg(key).query_async(&mut con).await?;
48+
redis::cmd("DEL").arg(key).query_async(&mut con).await?;
4949
Ok(())
5050
})
5151
.map_err(|err: RedisError| err)
@@ -112,7 +112,7 @@ fn bench_long_pipeline(b: &mut Bencher) {
112112
let pipe = long_pipeline();
113113

114114
b.iter(|| {
115-
let _: () = pipe.query(&mut con).unwrap();
115+
let () = pipe.query(&mut con).unwrap();
116116
});
117117
}
118118

@@ -140,7 +140,7 @@ fn bench_multiplexed_async_long_pipeline(b: &mut Bencher) {
140140
let pipe = long_pipeline();
141141

142142
b.iter(|| {
143-
let _: () = runtime
143+
let () = runtime
144144
.block_on(async { pipe.query_async(&mut con).await })
145145
.unwrap();
146146
});
@@ -162,7 +162,7 @@ fn bench_multiplexed_async_implicit_pipeline(b: &mut Bencher) {
162162
.collect::<Vec<_>>();
163163

164164
b.iter(|| {
165-
let _: () = runtime
165+
let () = runtime
166166
.block_on(async {
167167
cmds.iter()
168168
.zip(&mut connections)

examples/async-await.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ async fn main() -> redis::RedisResult<()> {
55
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
66
let mut con = client.get_async_connection().await?;
77

8-
let () = con.set("key1", b"foo").await?;
8+
con.set("key1", b"foo").await?;
99

10-
let () = redis::cmd("SET")
10+
redis::cmd("SET")
1111
.arg(&["key2", "bar"])
1212
.query_async(&mut con)
1313
.await?;

examples/basic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn do_show_scanning(con: &mut redis::Connection) -> redis::RedisResult<()> {
5151

5252
// since we don't care about the return value of the pipeline we can
5353
// just cast it into the unit type.
54-
let _: () = pipe.query(con)?;
54+
pipe.query(con)?;
5555

5656
// since rust currently does not track temporaries for us, we need to
5757
// store it in a local variable.
@@ -61,7 +61,7 @@ fn do_show_scanning(con: &mut redis::Connection) -> redis::RedisResult<()> {
6161
// as a simple exercise we just sum up the iterator. Since the fold
6262
// method carries an initial value we do not need to define the
6363
// type of the iterator, rust will figure "int" out for us.
64-
let sum = cmd.iter::<i32>(con)?.fold(0, |a, b| a + b);
64+
let sum: i32 = cmd.iter::<i32>(con)?.sum();
6565

6666
println!("The sum of all numbers in the set 0-1000: {}", sum);
6767

@@ -74,12 +74,12 @@ fn do_atomic_increment_lowlevel(con: &mut redis::Connection) -> redis::RedisResu
7474
println!("Run low-level atomic increment:");
7575

7676
// set the initial value so we have something to test with.
77-
let _: () = redis::cmd("SET").arg(key).arg(42).query(con)?;
77+
redis::cmd("SET").arg(key).arg(42).query(con)?;
7878

7979
loop {
8080
// we need to start watching the key we care about, so that our
8181
// exec fails if the key changes.
82-
let _: () = redis::cmd("WATCH").arg(key).query(con)?;
82+
redis::cmd("WATCH").arg(key).query(con)?;
8383

8484
// load the old value, so we know what to increment.
8585
let val: isize = redis::cmd("GET").arg(key).query(con)?;
@@ -117,7 +117,7 @@ fn do_atomic_increment(con: &mut redis::Connection) -> redis::RedisResult<()> {
117117
println!("Run high-level atomic increment:");
118118

119119
// set the initial value so we have something to test with.
120-
let _: () = con.set(key, 42)?;
120+
con.set(key, 42)?;
121121

122122
// run the transaction block.
123123
let (new_val,): (isize,) = transaction(con, &[key], |con, pipe| {

src/cluster.rs

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,32 @@
1111
//! use redis::Commands;
1212
//! use redis::cluster::ClusterClient;
1313
//!
14-
//! fn main() {
15-
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
16-
//! let client = ClusterClient::open(nodes).unwrap();
17-
//! let mut connection = client.get_connection().unwrap();
14+
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
15+
//! let client = ClusterClient::open(nodes).unwrap();
16+
//! let mut connection = client.get_connection().unwrap();
1817
//!
19-
//! let _: () = connection.set("test", "test_data").unwrap();
20-
//! let rv: String = connection.get("test").unwrap();
18+
//! let _: () = connection.set("test", "test_data").unwrap();
19+
//! let rv: String = connection.get("test").unwrap();
2120
//!
22-
//! assert_eq!(rv, "test_data");
23-
//! }
21+
//! assert_eq!(rv, "test_data");
2422
//! ```
2523
//!
2624
//! # Pipelining
2725
//! ```rust,no_run
2826
//! use redis::{Commands, pipe};
2927
//! use redis::cluster::ClusterClient;
3028
//!
31-
//! fn main() {
32-
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
33-
//! let client = ClusterClient::open(nodes).unwrap();
34-
//! let mut connection = client.get_connection().unwrap();
29+
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
30+
//! let client = ClusterClient::open(nodes).unwrap();
31+
//! let mut connection = client.get_connection().unwrap();
3532
//!
36-
//! let key = "test";
33+
//! let key = "test";
3734
//!
38-
//! let _: () = pipe()
39-
//! .rpush(key, "123").ignore()
40-
//! .ltrim(key, -10, -1).ignore()
41-
//! .expire(key, 60).ignore()
42-
//! .query(&mut connection).unwrap();
43-
//! }
35+
//! let _: () = pipe()
36+
//! .rpush(key, "123").ignore()
37+
//! .ltrim(key, -10, -1).ignore()
38+
//! .expire(key, 60).ignore()
39+
//! .query(&mut connection).unwrap();
4440
//! ```
4541
use std::cell::RefCell;
4642
use std::collections::{BTreeMap, HashMap, HashSet};
@@ -290,22 +286,18 @@ impl ClusterConnection {
290286
// Query a node to discover slot-> master mappings.
291287
fn refresh_slots(&self) -> RedisResult<()> {
292288
let mut slots = self.slots.borrow_mut();
293-
*slots = {
294-
let new_slots = if self.readonly {
295-
let mut rng = thread_rng();
296-
self.create_new_slots(|slot_data| {
297-
let replicas = slot_data.replicas();
298-
if replicas.is_empty() {
299-
slot_data.master().to_string()
300-
} else {
301-
replicas.choose(&mut rng).unwrap().to_string()
302-
}
303-
})?
304-
} else {
305-
self.create_new_slots(|slot_data| slot_data.master().to_string())?
306-
};
307-
308-
new_slots
289+
*slots = if self.readonly {
290+
let mut rng = thread_rng();
291+
self.create_new_slots(|slot_data| {
292+
let replicas = slot_data.replicas();
293+
if replicas.is_empty() {
294+
slot_data.master().to_string()
295+
} else {
296+
replicas.choose(&mut rng).unwrap().to_string()
297+
}
298+
})?
299+
} else {
300+
self.create_new_slots(|slot_data| slot_data.master().to_string())?
309301
};
310302

311303
let mut connections = self.connections.borrow_mut();
@@ -421,7 +413,7 @@ impl ClusterConnection {
421413
} else {
422414
// Create new connection.
423415
// TODO: error handling
424-
let conn = connect(addr.as_ref(), self.readonly, self.password.clone())?;
416+
let conn = connect(addr, self.readonly, self.password.clone())?;
425417
Ok(connections.entry(addr.to_string()).or_insert(conn))
426418
}
427419
}
@@ -442,6 +434,7 @@ impl ClusterConnection {
442434
Ok(T::merge_results(results))
443435
}
444436

437+
#[allow(clippy::unnecessary_unwrap)]
445438
fn request<T, F>(&self, cmd: &[u8], mut func: F) -> RedisResult<T>
446439
where
447440
T: MergeResults + std::fmt::Debug,
@@ -454,10 +447,10 @@ impl ClusterConnection {
454447
return self.execute_on_all_nodes(func);
455448
}
456449
None => {
457-
return Err(((
450+
return Err((
458451
ErrorKind::ClientError,
459452
"this command cannot be safely routed in cluster mode",
460-
))
453+
)
461454
.into())
462455
}
463456
};

src/commands.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ macro_rules! implement_commands {
4141
/// use redis::Commands;
4242
/// let client = redis::Client::open("redis://127.0.0.1/")?;
4343
/// let mut con = client.get_connection()?;
44-
/// let () = con.set("my_key", 42)?;
44+
/// con.set("my_key", 42)?;
4545
/// assert_eq!(con.get("my_key"), Ok(42));
4646
/// # Ok(()) }
4747
/// ```
4848
pub trait Commands : ConnectionLike+Sized {
4949
$(
5050
$(#[$attr])*
5151
#[inline]
52+
#[allow(clippy::extra_unused_lifetimes, clippy::needless_lifetimes)]
5253
fn $name<$lifetime, $($tyargs: $ty, )* RV: FromRedisValue>(
5354
&mut self $(, $argname: $argty)*) -> RedisResult<RV>
5455
{ Cmd::$name($($argname),*).query(self) }
@@ -126,6 +127,7 @@ macro_rules! implement_commands {
126127
impl Cmd {
127128
$(
128129
$(#[$attr])*
130+
#[allow(clippy::extra_unused_lifetimes, clippy::needless_lifetimes)]
129131
pub fn $name<$lifetime, $($tyargs: $ty),*>($($argname: $argty),*) -> Self {
130132
::std::mem::replace($body, Cmd::new())
131133
}
@@ -143,7 +145,7 @@ macro_rules! implement_commands {
143145
/// # async fn do_something() -> redis::RedisResult<()> {
144146
/// let client = redis::Client::open("redis://127.0.0.1/")?;
145147
/// let mut con = client.get_async_connection().await?;
146-
/// let () = redis::cmd("SET").arg("my_key").arg(42i32).query_async(&mut con).await?;
148+
/// redis::cmd("SET").arg("my_key").arg(42i32).query_async(&mut con).await?;
147149
/// assert_eq!(redis::cmd("GET").arg("my_key").query_async(&mut con).await, Ok(42i32));
148150
/// # Ok(()) }
149151
/// ```
@@ -156,7 +158,7 @@ macro_rules! implement_commands {
156158
/// use redis::Commands;
157159
/// let client = redis::Client::open("redis://127.0.0.1/")?;
158160
/// let mut con = client.get_async_connection().await?;
159-
/// let () = con.set("my_key", 42i32).await?;
161+
/// con.set("my_key", 42i32).await?;
160162
/// assert_eq!(con.get("my_key").await, Ok(42i32));
161163
/// # Ok(()) }
162164
/// ```
@@ -165,11 +167,13 @@ macro_rules! implement_commands {
165167
$(
166168
$(#[$attr])*
167169
#[inline]
170+
#[allow(clippy::extra_unused_lifetimes, clippy::needless_lifetimes)]
168171
fn $name<$lifetime, $($tyargs: $ty + Send + Sync + $lifetime,)* RV>(
169172
& $lifetime mut self
170173
$(, $argname: $argty)*
171-
) -> crate::types::RedisFuture<'a, RV>
172-
where RV: FromRedisValue,
174+
) -> crate::types::RedisFuture<'a, RV>
175+
where
176+
RV: FromRedisValue,
173177
{
174178
Box::pin(async move { ($body).query_async(self).await })
175179
}
@@ -183,9 +187,12 @@ macro_rules! implement_commands {
183187
$(
184188
$(#[$attr])*
185189
#[inline]
190+
#[allow(clippy::extra_unused_lifetimes, clippy::needless_lifetimes)]
186191
pub fn $name<$lifetime, $($tyargs: $ty),*>(
187-
&mut self $(, $argname: $argty)*) -> &mut Self
188-
{ self.add_command(::std::mem::replace($body, Cmd::new())) }
192+
&mut self $(, $argname: $argty)*
193+
) -> &mut Self {
194+
self.add_command(::std::mem::replace($body, Cmd::new()))
195+
}
189196
)*
190197
}
191198
)

src/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
155155
),
156156
None => 0,
157157
},
158-
passwd: url.password().and_then(|pw| Some(pw.to_string())),
158+
passwd: url.password().map(|pw| pw.to_string()),
159159
})
160160
}
161161

@@ -233,7 +233,7 @@ impl ActualConnection {
233233
Some(timeout) => {
234234
let mut tcp = None;
235235
let mut last_error = None;
236-
for addr in ((host, *port)).to_socket_addrs()? {
236+
for addr in (host, *port).to_socket_addrs()? {
237237
match TcpStream::connect_timeout(&addr, timeout) {
238238
Ok(l) => {
239239
tcp = Some(l);

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
//!
4646
//! Ok(())
4747
//! }
48-
//! # fn main() {}
4948
//! ```
5049
//!
5150
//! ## Optional Features
@@ -106,7 +105,6 @@
106105
//! let _ : () = con.set("my_key", 42)?;
107106
//! Ok(())
108107
//! }
109-
//! # fn main() {}
110108
//! ```
111109
//!
112110
//! Note that high-level commands are work in progress and many are still
@@ -306,9 +304,9 @@
306304
//! let client = redis::Client::open("redis://127.0.0.1/").unwrap();
307305
//! let mut con = client.get_async_connection().await?;
308306
//!
309-
//! let () = con.set("key1", b"foo").await?;
307+
//! con.set("key1", b"foo").await?;
310308
//!
311-
//! let () = redis::cmd("SET").arg(&["key2", "bar"]).query_async(&mut con).await?;
309+
//! redis::cmd("SET").arg(&["key2", "bar"]).query_async(&mut con).await?;
312310
//!
313311
//! let result = redis::cmd("MGET")
314312
//! .arg(&["key1", "key2"])

src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ where
203203
// SAFETY We either drop `self.reader` and return a slice with the lifetime of the
204204
// reader or we return Pending/Err (neither which contains `'a`).
205205
// In either case `poll_fill_buf` can not be called while its contents are exposed
206-
Poll::Ready(Ok(x)) => unsafe { return Ok(&*(x as *const _)).into() },
206+
Poll::Ready(Ok(x)) => Ok(unsafe { &*(x as *const _) }).into(),
207207
Poll::Ready(Err(err)) => Err(err).into(),
208208
Poll::Pending => {
209209
reader = Some(r);
@@ -227,7 +227,7 @@ where
227227

228228
let (opt, mut removed) = {
229229
let buffer = fill_buf(&mut reader).await?;
230-
if buffer.len() == 0 {
230+
if buffer.is_empty() {
231231
return Err((ErrorKind::ResponseError, "Could not read enough bytes").into());
232232
}
233233
let buffer = if !remaining.is_empty() {

src/script.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ impl<'a> ScriptInvocation<'a> {
167167
match eval_cmd.query_async(con).await {
168168
Ok(val) => {
169169
// Return the value from the script evaluation
170-
return Ok(val).into();
170+
Ok(val)
171171
}
172172
Err(err) => {
173173
// Load the script into Redis if the script hash wasn't there already
174174
if err.kind() == ErrorKind::NoScriptError {
175-
let _hash = load_cmd.query_async(con).await?;
175+
load_cmd.query_async(con).await?;
176176
eval_cmd.query_async(con).await
177177
} else {
178178
Err(err)

0 commit comments

Comments
 (0)