Skip to content

Commit 68511bc

Browse files
authored
Add clippy to CI and fix several clippy warnings (#625)
* Remove ambiguity when using deps * Fix doc and some linting hints * Make tests more readable * Run clippy during the CI checks * Fix formatting * A few more linting fixes * Remove old comment
1 parent ac72c85 commit 68511bc

File tree

26 files changed

+193
-214
lines changed

26 files changed

+193
-214
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ checkstyle-linux-stable:
4545
<<: *only
4646
<<: *docker-env
4747
script:
48-
- rustup component add rustfmt
48+
- rustup component add rustfmt clippy
4949
- cargo fmt --all -- --check
50+
- cargo clippy
5051
allow_failure: true
5152

5253
# test rust stable

core-client/transports/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for TypedSubscriptionStream<T
178178
.map_err(|error| RpcError::ParseError(self.returns.into(), Box::new(error))),
179179
),
180180
None => None,
181-
Some(Err(err)) => Some(Err(err.into())),
181+
Some(Err(err)) => Some(Err(err)),
182182
}
183183
.into()
184184
}

core-client/transports/src/transports/duplex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ where
281281
}
282282
match self.outgoing.pop_front() {
283283
Some(request) => {
284-
if let Err(_) = self.sink.as_mut().start_send(request) {
284+
if self.sink.as_mut().start_send(request).is_err() {
285285
// the channel is disconnected.
286286
return err().into();
287287
}

core-client/transports/src/transports/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl From<ClientResponse> for Result<Value, Error> {
151151
(Some(_), _, Some(error)) => {
152152
let error = serde_json::from_value::<Error>(error.to_owned())
153153
.ok()
154-
.unwrap_or_else(|| Error::parse_error());
154+
.unwrap_or_else(Error::parse_error);
155155
Err(error)
156156
}
157157
_ => Ok(n.params.into()),

core/src/io.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::pin::Pin;
88
use std::sync::Arc;
99

1010
use futures_util::{self, future, FutureExt};
11-
use serde_json;
1211

1312
use crate::calls::{
1413
Metadata, RemoteProcedure, RpcMethod, RpcMethodSimple, RpcMethodSync, RpcNotification, RpcNotificationSimple,
@@ -60,10 +59,10 @@ impl Default for Compatibility {
6059

6160
impl Compatibility {
6261
fn is_version_valid(self, version: Option<Version>) -> bool {
63-
match (self, version) {
64-
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _) => true,
65-
_ => false,
66-
}
62+
matches!(
63+
(self, version),
64+
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _)
65+
)
6766
}
6867

6968
fn default_version(self) -> Option<Version> {
@@ -208,10 +207,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
208207
use self::future::Either::{Left, Right};
209208
fn as_string(response: Option<Response>) -> Option<String> {
210209
let res = response.map(write_response);
211-
debug!(target: "rpc", "Response: {}.", match res {
212-
Some(ref res) => res,
213-
None => "None",
214-
});
210+
debug!(target: "rpc", "Response: {}.", res.as_ref().unwrap_or(&"None".to_string()));
215211
res
216212
}
217213

@@ -237,7 +233,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
237233
}
238234

239235
fn outputs_as_batch(outs: Vec<Option<Output>>) -> Option<Response> {
240-
let outs: Vec<_> = outs.into_iter().filter_map(|v| v).collect();
236+
let outs: Vec<_> = outs.into_iter().flatten().collect();
241237
if outs.is_empty() {
242238
None
243239
} else {

core/src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
//! Right now it supports only server side handling requests.
44
//!
55
//! ```rust
6-
//! use jsonrpc_core::*;
6+
//! use jsonrpc_core::IoHandler;
7+
//! use jsonrpc_core::Value;
8+
//! let mut io = IoHandler::new();
9+
//! io.add_sync_method("say_hello", |_| {
10+
//! Ok(Value::String("Hello World!".into()))
11+
//! });
712
//!
8-
//! fn main() {
9-
//! let mut io = IoHandler::new();
10-
//! io.add_sync_method("say_hello", |_| {
11-
//! Ok(Value::String("Hello World!".into()))
12-
//! });
13+
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
14+
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
1315
//!
14-
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
15-
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
16-
//!
17-
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
18-
//! }
16+
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
1917
//! ```
2018
2119
#![deny(missing_docs)]

core/src/types/params.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! jsonrpc params field
22
33
use serde::de::DeserializeOwned;
4-
use serde_json;
54
use serde_json::value::from_value;
65

76
use super::{Error, Value};

core/src/types/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl Output {
4343
/// Creates new output given `Result`, `Id` and `Version`.
4444
pub fn from(result: CoreResult<Value>, id: Id, jsonrpc: Option<Version>) -> Self {
4545
match result {
46-
Ok(result) => Output::Success(Success { id, jsonrpc, result }),
47-
Err(error) => Output::Failure(Failure { id, jsonrpc, error }),
46+
Ok(result) => Output::Success(Success { jsonrpc, result, id }),
47+
Err(error) => Output::Failure(Failure { jsonrpc, error, id }),
4848
}
4949
}
5050

0 commit comments

Comments
 (0)