Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clippy to CI and fix several clippy warnings #625

Merged
merged 7 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ checkstyle-linux-stable:
<<: *only
<<: *docker-env
script:
- rustup component add rustfmt
- rustup component add rustfmt clippy
- cargo fmt --all -- --check
- cargo clippy
allow_failure: true

# test rust stable
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for TypedSubscriptionStream<T
.map_err(|error| RpcError::ParseError(self.returns.into(), Box::new(error))),
),
None => None,
Some(Err(err)) => Some(Err(err.into())),
Some(Err(err)) => Some(Err(err)),
}
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/transports/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ where
}
match self.outgoing.pop_front() {
Some(request) => {
if let Err(_) = self.sink.as_mut().start_send(request) {
if self.sink.as_mut().start_send(request).is_err() {
// the channel is disconnected.
return err().into();
}
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/transports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl From<ClientResponse> for Result<Value, Error> {
(Some(_), _, Some(error)) => {
let error = serde_json::from_value::<Error>(error.to_owned())
.ok()
.unwrap_or_else(|| Error::parse_error());
.unwrap_or_else(Error::parse_error);
Err(error)
}
_ => Ok(n.params.into()),
Expand Down
16 changes: 6 additions & 10 deletions core/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::pin::Pin;
use std::sync::Arc;

use futures_util::{self, future, FutureExt};
use serde_json;

use crate::calls::{
Metadata, RemoteProcedure, RpcMethod, RpcMethodSimple, RpcMethodSync, RpcNotification, RpcNotificationSimple,
Expand Down Expand Up @@ -60,10 +59,10 @@ impl Default for Compatibility {

impl Compatibility {
fn is_version_valid(self, version: Option<Version>) -> bool {
match (self, version) {
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _) => true,
_ => false,
}
matches!(
(self, version),
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _)
)
}

fn default_version(self) -> Option<Version> {
Expand Down Expand Up @@ -208,10 +207,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
use self::future::Either::{Left, Right};
fn as_string(response: Option<Response>) -> Option<String> {
let res = response.map(write_response);
debug!(target: "rpc", "Response: {}.", match res {
Some(ref res) => res,
None => "None",
});
debug!(target: "rpc", "Response: {}.", res.as_ref().unwrap_or(&"None".to_string()));
res
}

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

fn outputs_as_batch(outs: Vec<Option<Output>>) -> Option<Response> {
let outs: Vec<_> = outs.into_iter().filter_map(|v| v).collect();
let outs: Vec<_> = outs.into_iter().flatten().collect();
if outs.is_empty() {
None
} else {
Expand Down
20 changes: 9 additions & 11 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
//! Right now it supports only server side handling requests.
//!
//! ```rust
//! use jsonrpc_core::*;
//! use jsonrpc_core::IoHandler;
//! use jsonrpc_core::Value;
//! let mut io = IoHandler::new();
//! io.add_sync_method("say_hello", |_| {
//! Ok(Value::String("Hello World!".into()))
//! });
//!
//! fn main() {
//! let mut io = IoHandler::new();
//! io.add_sync_method("say_hello", |_| {
//! Ok(Value::String("Hello World!".into()))
//! });
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
//!
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
//!
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
//! }
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
//! ```

#![deny(missing_docs)]
Expand Down
1 change: 0 additions & 1 deletion core/src/types/params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! jsonrpc params field

use serde::de::DeserializeOwned;
use serde_json;
use serde_json::value::from_value;

use super::{Error, Value};
Expand Down
4 changes: 2 additions & 2 deletions core/src/types/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl Output {
/// Creates new output given `Result`, `Id` and `Version`.
pub fn from(result: CoreResult<Value>, id: Id, jsonrpc: Option<Version>) -> Self {
match result {
Ok(result) => Output::Success(Success { id, jsonrpc, result }),
Err(error) => Output::Failure(Failure { id, jsonrpc, error }),
Ok(result) => Output::Success(Success { jsonrpc, result, id }),
Err(error) => Output::Failure(Failure { jsonrpc, error, id }),
}
}

Expand Down