Skip to content

Commit

Permalink
[refactor]: Add new lints to 1.62
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Petrosyan <[email protected]>
  • Loading branch information
appetrosyan committed Aug 18, 2022
1 parent ea4b64e commit a633281
Show file tree
Hide file tree
Showing 111 changed files with 485 additions and 227 deletions.
3 changes: 3 additions & 0 deletions actor/src/actor_id.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Actor identification.
#![allow(clippy::std_instead_of_core, clippy::std_instead_of_alloc)]
use std::{
fmt::{self, Debug, Display},
hash::Hash,
Expand Down Expand Up @@ -48,4 +50,5 @@ impl PartialEq for ActorId {
self.id == other.id
}
}

impl Eq for ActorId {}
123 changes: 66 additions & 57 deletions actor/src/broker.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
#![allow(clippy::module_name_repetitions)]

//! Module with message broker for `iroha_actor`
///
/// ```rust
/// use iroha_actor::{prelude::*, broker::*};
///
/// #[derive(Clone)]
/// struct Message1(String);
/// impl Message for Message1 { type Result = (); }
///
/// #[derive(Clone)] struct Message2(String);
/// impl Message for Message2 { type Result = (); }
///
/// struct Actor1(Broker);
/// struct Actor2(Broker);
///
/// #[async_trait::async_trait]
/// impl Actor for Actor1 {
/// async fn on_start(&mut self, ctx: &mut Context<Self>) {
/// self.0.subscribe::<Message1, _>(ctx);
/// self.0.issue_send(Message2("Hello".to_string())).await;
/// }
/// }
///
/// #[async_trait::async_trait]
/// impl Handler<Message1> for Actor1 {
/// type Result = ();
/// async fn handle(&mut self, msg: Message1) {
/// println!("Actor1: {}", msg.0);
/// }
/// }
///
/// #[async_trait::async_trait]
/// impl Actor for Actor2 {
/// async fn on_start(&mut self, ctx: &mut Context<Self>) {
/// self.0.subscribe::<Message2, _>(ctx);
/// }
/// }
///
/// #[async_trait::async_trait]
/// impl Handler<Message2> for Actor2 {
/// type Result = ();
/// async fn handle(&mut self, msg: Message2) {
/// println!("Actor2: {}", msg.0);
/// self.0.issue_send(Message1(msg.0.clone() + " world")).await;
/// }
/// }
/// tokio::runtime::Runtime::new().unwrap().block_on(async {
/// let broker = Broker::new();
/// Actor2(broker.clone()).start().await;
/// Actor1(broker).start().await;
/// // Actor2: Hello
/// // Actor1: Hello world
/// })
/// ```
use std::any::{Any, TypeId};
use std::{collections::HashMap, sync::Arc};
//!
//! ```rust
//! use iroha_actor::{prelude::*, broker::*};
//!
//! #[derive(Clone)]
//! struct Message1(String);
//! impl Message for Message1 { type Result = (); }
//!
//! #[derive(Clone)] struct Message2(String);
//! impl Message for Message2 { type Result = (); }
//!
//! struct Actor1(Broker);
//! struct Actor2(Broker);
//!
//! #[async_trait::async_trait]
//! impl Actor for Actor1 {
//! async fn on_start(&mut self, ctx: &mut Context<Self>) {
//! self.0.subscribe::<Message1, _>(ctx);
//! self.0.issue_send(Message2("Hello".to_string())).await;
//! }
//! }
//!
//! #[async_trait::async_trait]
//! impl Handler<Message1> for Actor1 {
//! type Result = ();
//! async fn handle(&mut self, msg: Message1) {
//! println!("Actor1: {}", msg.0);
//! }
//! }
//!
//! #[async_trait::async_trait]
//! impl Actor for Actor2 {
//! async fn on_start(&mut self, ctx: &mut Context<Self>) {
//! self.0.subscribe::<Message2, _>(ctx);
//! }
//! }
//!
//! #[async_trait::async_trait]
//! impl Handler<Message2> for Actor2 {
//! type Result = ();
//! async fn handle(&mut self, msg: Message2) {
//! println!("Actor2: {}", msg.0);
//! self.0.issue_send(Message1(msg.0.clone() + " world")).await;
//! }
//! }
//! tokio::runtime::Runtime::new().unwrap().block_on(async {
//! let broker = Broker::new();
//! Actor2(broker.clone()).start().await;
//! Actor1(broker).start().await;
//! // Actor2: Hello
//! // Actor1: Hello world
//! })
//! ```
#![allow(
clippy::module_name_repetitions,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc,
clippy::arithmetic
)]

use std::{
any::{Any, TypeId},
collections::HashMap,
sync::Arc,
};

use dashmap::{mapref::entry::Entry, DashMap};
use futures::{prelude::*, stream::FuturesUnordered};
Expand Down
3 changes: 2 additions & 1 deletion actor/src/deadlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#![allow(
clippy::expect_used,
clippy::panic,
clippy::declare_interior_mutable_const
clippy::declare_interior_mutable_const,
clippy::std_instead_of_core
)]

use std::{future::Future, time::Duration};
Expand Down
12 changes: 7 additions & 5 deletions actor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Iroha simple actor framework.
#![allow(clippy::same_name_method)]
#![allow(clippy::expect_used)]

#![allow(
clippy::std_instead_of_core,
clippy::expect_used,
clippy::same_name_method
)]
#[cfg(feature = "deadlock_detection")]
use std::any::type_name;
use std::{
use core::any::type_name;
use core::{
fmt::Debug,
ops::{Deref, DerefMut},
time::Duration,
Expand Down
1 change: 1 addition & 0 deletions cli/derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Crate with a proc macro for torii endpoint generation
#![allow(clippy::arithmetic)] // We should remove `clippy::restriction`.

use proc_macro::TokenStream;
use proc_macro2::Span;
Expand Down
6 changes: 5 additions & 1 deletion cli/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Iroha is a quite dynamic system so many events can happen.
//! This module contains descriptions of such an events and
//! utility Iroha Special Instructions to work with them.
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use futures::TryStreamExt;
use iroha_data_model::events::prelude::*;
use iroha_macro::error::ErrorTryFromEnum;
Expand Down
7 changes: 6 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
//!
//! `Iroha` is the main instance of the peer program. `Arguments`
//! should be constructed externally: (see `main.rs`).
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use std::{panic, path::PathBuf, sync::Arc};

use color_eyre::eyre::{eyre, Result, WrapErr};
Expand Down Expand Up @@ -200,7 +205,7 @@ where
// Validate every transaction in genesis block
if let Some(ref genesis) = genesis {
transaction_validator
.validate_every(&***genesis)
.validate_every(genesis)
.wrap_err("Transaction validation failed in genesis block")?;
}

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Iroha peer command-line interface.
use std::str::FromStr;
use core::str::FromStr;

use eyre::WrapErr as _;
use iroha::Arguments;
Expand Down
3 changes: 1 addition & 2 deletions cli/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//! Adds support for sending custom Iroha messages over the stream, taking care
//! of encoding/decoding as well as timeouts
use core::result::Result;
use std::time::Duration;
use core::{result::Result, time::Duration};

use futures::{SinkExt, StreamExt};
use iroha_logger::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn create_torii() -> (Torii, KeyPair) {
format!("127.0.0.1:{}", unique_port::get_unique_free_port().unwrap());
let (events, _) = tokio::sync::broadcast::channel(100);
let wsv = Arc::new(WorldStateView::new(World::with(
('a'..'z')
('a'..='z')
.map(|name| DomainId::from_str(&name.to_string()).expect("Valid"))
.map(|domain_id| Domain::new(domain_id).build()),
vec![],
Expand Down
5 changes: 5 additions & 0 deletions client/benches/tps/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
//! using [criterion](https://github.com/bheisler/criterion.rs)
//! for performance check during development
#![allow(missing_docs)]
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]

use criterion::{
black_box, criterion_group, criterion_main,
Expand Down
5 changes: 5 additions & 0 deletions client/benches/tps/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use std::{fmt, fs::File, io::BufReader, path::Path, str::FromStr as _, sync::mpsc, thread, time};

use eyre::{Result, WrapErr};
Expand Down
16 changes: 8 additions & 8 deletions client/benches/tps/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ fn main() {
let config = lib::Config::from_path("benches/tps/config.json").expect("Failed to configure");
let tps = config.measure().expect("Failed to measure");

match flush_guard {
Some(guard) => {
flush_guard.map_or_else(
|| {
iroha_logger::info!(?config);
iroha_logger::info!(%tps);
},
|guard| {
guard.flush().expect("Flushed data without errors");
println!("Tracing data outputted to file: {}", &args[1]);
println!("TPS was {}", tps);
println!("Config was {:?}", config);
}
None => {
iroha_logger::info!(?config);
iroha_logger::info!(%tps);
}
}
},
)
}
6 changes: 4 additions & 2 deletions client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn main() {
.env("CARGO_TARGET_DIR", out_dir)
.current_dir(smartcontract_path)
.args(&[
"+nightly-2022-08-09",
"+nightly-2022-08-15",
"build",
"--release",
"-Z",
Expand All @@ -71,6 +71,8 @@ fn main() {
])
.status()
.expect("Failed to run `cargo build` on smartcontract");
assert!(build.success(), "Can't build smartcontract")
if !build.success() {
println!("cargo:warning=Compiling the smartcontract exited with status")
}
}
}
10 changes: 8 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Contains the end-point querying logic. This is where you need to
//! add any custom end-point related logic.
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use std::{
collections::HashMap, fmt::Debug, marker::PhantomData, sync::mpsc, thread, time::Duration,
};
Expand Down Expand Up @@ -1036,9 +1041,10 @@ pub mod events_api {
try_decode_all_or_just_decode!(VersionedEventPublisherMessage, &message)?
.into_v1()
{
return Ok(Events);
Ok(Events)
} else {
Err(eyre!("Expected `SubscriptionAccepted`."))
}
return Err(eyre!("Expected `SubscriptionAccepted`."));
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Borrow;
use core::borrow::Borrow;

use eyre::{eyre, Result};
pub use http::{Method, Response, StatusCode};
Expand Down
6 changes: 6 additions & 0 deletions client/src/http_default.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Defaults for various items used in communication over http(s).
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use std::{net::TcpStream, str::FromStr};

use attohttpc::{
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic_in_result_fn)]

#![allow(clippy::restriction)]
use std::{fmt::Write as _, sync::mpsc, thread};

use eyre::Result;
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() {
wait_for_genesis_committed(&vec![iroha_client.clone()], 0);
let pipeline_time = Configuration::pipeline_time();

let register: Vec<Instruction> = ('a'..'z')
let register: Vec<Instruction> = ('a'..='z') // This is a subtle mistake, I'm glad we can lint it now.
.map(|c| c.to_string())
.map(|name| (name + "#wonderland").parse().expect("Valid"))
.map(|asset_definition_id| {
Expand Down
1 change: 1 addition & 0 deletions client/tests/integration/unregister_peer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::restriction)]
use std::thread;

use eyre::Result;
Expand Down
5 changes: 5 additions & 0 deletions client/tests/wasm/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
use iroha_core::smartcontracts::wasm;

/// Return string containing exported memory, dummy allocator, and
Expand Down
6 changes: 5 additions & 1 deletion client_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! iroha client command line
#![allow(
clippy::arithmetic,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc
)]
#![allow(
missing_docs,
clippy::print_stdout,
Expand Down
2 changes: 2 additions & 0 deletions config/base/derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Contains various configuration related macro definitions.
#![allow(clippy::arithmetic, clippy::std_instead_of_core)]

use proc_macro::TokenStream;

pub(crate) mod documented;
Expand Down
Loading

0 comments on commit a633281

Please sign in to comment.