Skip to content

Clippy #5778

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

Open
wants to merge 5 commits into
base: release/2025.10-brie
Choose a base branch
from
Open

Clippy #5778

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ jobs:
runs-on: ubuntu-22.04
env:
CARGO_TERM_COLOR: always
RUSTUP_PERMIT_COPY_RENAME: 1
steps:
- uses: actions/checkout@v4

- name: Setup rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
# pinned due to issues building contracts
toolchain: 1.86.0
target: wasm32-unknown-unknown
override: true
components: rustfmt, clippy
Expand Down
2 changes: 2 additions & 0 deletions clients/socks5/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2021 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::result_large_err)]

use std::error::Error;

use clap::{crate_name, crate_version, Parser};
Expand Down
4 changes: 3 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
allow-panic-in-tests = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like just kicking the can down the road -> could we not fix it "properly" instead? which errors is clippy complaining about? could we box something?

large-error-threshold = 196
enum-variant-size-threshold = 1000
3 changes: 1 addition & 2 deletions common/config/src/legacy_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub mod nym_config {
log::trace!("Loading from file: {:#?}", filepath.as_ref().to_owned());
let config_contents = fs::read_to_string(filepath)?;

toml::from_str(&config_contents)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
toml::from_str(&config_contents).map_err(io::Error::other)
}
}
}
3 changes: 1 addition & 2 deletions common/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ where
let content = fs::read_to_string(path)?;

// TODO: should we be preserving original error type instead?
deserialize_config_from_toml_str(&content)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
deserialize_config_from_toml_str(&content).map_err(io::Error::other)
}

//
Expand Down
15 changes: 6 additions & 9 deletions common/pemstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ where
let key_pem = read_pem_file(path)?;

if T::pem_type() != key_pem.tag {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"unexpected key pem tag. Got '{}', expected: '{}'",
key_pem.tag,
T::pem_type()
),
));
return Err(io::Error::other(format!(
"unexpected key pem tag. Got '{}', expected: '{}'",
key_pem.tag,
T::pem_type()
)));
}

let key = match T::from_bytes(&key_pem.contents) {
Expand All @@ -84,7 +81,7 @@ fn read_pem_file<P: AsRef<Path>>(filepath: P) -> io::Result<Pem> {
let mut pem_bytes = File::open(filepath)?;
let mut buf = Vec::new();
pem_bytes.read_to_end(&mut buf)?;
pem::parse(&buf).map_err(|e| io::Error::new(io::ErrorKind::Other, e))
pem::parse(&buf).map_err(io::Error::other)
}

fn write_pem_file<P: AsRef<Path>>(filepath: P, data: Vec<u8>, tag: &str) -> io::Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions common/wasm/utils/src/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ fn map_ws_error(err: WebSocketError) -> WsError {
// TODO: are we preserving correct semantics?
WebSocketError::ConnectionError => WsError::ConnectionClosed,
WebSocketError::ConnectionClose(_event) => WsError::ConnectionClosed,
WebSocketError::MessageSendError(err) => {
WsError::Io(io::Error::new(io::ErrorKind::Other, err.to_string()))
}
_ => WsError::Io(io::Error::new(io::ErrorKind::Other, "new websocket error")),
WebSocketError::MessageSendError(err) => WsError::Io(io::Error::other(err.to_string())),
_ => WsError::Io(io::Error::other("new websocket error")),
}
}

Expand Down
1 change: 1 addition & 0 deletions nym-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2023 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

#![allow(clippy::result_large_err)]
#![warn(clippy::todo)]
#![warn(clippy::dbg_macro)]

Expand Down
1 change: 1 addition & 0 deletions nym-node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

#![allow(clippy::result_large_err)]
#![warn(clippy::expect_used)]
#![warn(clippy::unwrap_used)]

Expand Down
1 change: 1 addition & 0 deletions nym-validator-rewarder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023-2024 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

#![allow(clippy::result_large_err)]
#![warn(clippy::expect_used)]
#![warn(clippy::unwrap_used)]
#![warn(clippy::todo)]
Expand Down
10 changes: 4 additions & 6 deletions nym-wallet/src-tauri/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Config {
let location = Self::config_file_path(None);

match toml::to_string_pretty(&global)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
.map_err(io::Error::other)
.map(|toml| fs::write(location.clone(), toml))
{
Ok(_) => log::debug!("Writing to: {:#?}", location),
Expand All @@ -162,7 +162,7 @@ impl Config {

let location = Self::config_file_path(Some(network));
match toml::to_string_pretty(config)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
.map_err(io::Error::other)
.map(|toml| fs::write(location.clone(), toml))
{
Ok(_) => log::debug!("Writing to: {:#?}", location),
Expand Down Expand Up @@ -367,10 +367,8 @@ fn load_from_file<T>(file: PathBuf) -> Result<T, io::Error>
where
T: DeserializeOwned,
{
fs::read_to_string(file).and_then(|contents| {
toml::from_str::<T>(&contents)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))
})
fs::read_to_string(file)
.and_then(|contents| toml::from_str::<T>(&contents).map_err(io::Error::other))
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
Expand Down
2 changes: 2 additions & 0 deletions nyx-chain-watcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::result_large_err)]

use clap::{crate_name, crate_version, Parser};
use nym_bin_common::bin_info_owned;
use nym_bin_common::logging::maybe_print_banner;
Expand Down
18 changes: 4 additions & 14 deletions sdk/rust/nym-sdk/examples/libp2p_shared/substream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Substream {
}

fn check_closed(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Result<(), IoError> {
let closed_err = IoError::new(ErrorKind::Other, "stream closed");
let closed_err = IoError::other("stream closed");

// close_rx will return an error if the channel is closed (ie. sender was dropped),
// or if it's empty
Expand Down Expand Up @@ -172,12 +172,7 @@ impl AsyncWrite for Substream {
),
}),
})
.map_err(|e| {
IoError::new(
ErrorKind::Other,
format!("poll_write outbound_tx error: {}", e),
)
})?;
.map_err(|e| IoError::other(format!("poll_write outbound_tx error: {}", e)))?;

Poll::Ready(Ok(buf.len()))
}
Expand All @@ -195,7 +190,7 @@ impl AsyncWrite for Substream {

let mut closed = self.closed.lock();
if *closed {
return Poll::Ready(Err(IoError::new(ErrorKind::Other, "stream closed")));
return Poll::Ready(Err(IoError::other("stream closed")));
}

*closed = true;
Expand All @@ -210,12 +205,7 @@ impl AsyncWrite for Substream {
message: SubstreamMessage::new_close(self.substream_id.clone()),
}),
})
.map_err(|e| {
IoError::new(
ErrorKind::Other,
format!("poll_close outbound_rx error: {}", e),
)
})?;
.map_err(|e| IoError::other(format!("poll_close outbound_rx error: {}", e)))?;

Poll::Ready(Ok(()))
}
Expand Down
18 changes: 8 additions & 10 deletions sdk/rust/nym-sdk/src/mixnet/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,18 @@ where
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::result::Result<usize, std::io::Error>> {
ready!(self.tx.poll_ready_unpin(cx)).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet")
})?;
ready!(self.tx.poll_ready_unpin(cx))
.map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?;

let input_message = self
.message_translator
.to_input_message(buf)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
.map_err(std::io::Error::other)?;

// Pass it to the mixnet sender
self.tx.start_send_unpin(input_message).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet")
})?;
self.tx
.start_send_unpin(input_message)
.map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?;

Poll::Ready(Ok(buf.len()))
}
Expand All @@ -233,9 +232,8 @@ where
mut self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<std::result::Result<(), std::io::Error>> {
ready!(self.tx.poll_flush_unpin(cx)).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::Other, "failed to send packet to mixnet")
})?;
ready!(self.tx.poll_flush_unpin(cx))
.map_err(|_| std::io::Error::other("failed to send packet to mixnet"))?;
Poll::Ready(Ok(()))
}

Expand Down
20 changes: 4 additions & 16 deletions tools/nymvisor/src/upgrades/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ impl UpgradePlan {
pub(crate) fn try_load<P: AsRef<Path>>(path: P) -> Result<Self, NymvisorError> {
let path = path.as_ref();
let mut upgrade_plan: UpgradePlan = fs::File::open(path)
.and_then(|file| {
serde_json::from_reader(file)
.map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err))
})
.and_then(|file| serde_json::from_reader(file).map_err(io::Error::other))
.map_err(|source| NymvisorError::UpgradePlanLoadFailure {
path: path.to_path_buf(),
source,
Expand Down Expand Up @@ -274,10 +271,7 @@ impl UpgradeInfo {
pub(crate) fn try_load<P: AsRef<Path>>(path: P) -> Result<Self, NymvisorError> {
let path = path.as_ref();
fs::File::open(path)
.and_then(|file| {
serde_json::from_reader(file)
.map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err))
})
.and_then(|file| serde_json::from_reader(file).map_err(io::Error::other))
.map_err(|source| NymvisorError::UpgradeInfoLoadFailure {
path: path.to_path_buf(),
source,
Expand Down Expand Up @@ -426,10 +420,7 @@ impl UpgradeHistory {
pub(crate) fn try_load<P: AsRef<Path>>(path: P) -> Result<Self, NymvisorError> {
let path = path.as_ref();
let mut history: UpgradeHistory = fs::File::open(path)
.and_then(|file| {
serde_json::from_reader(file)
.map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err))
})
.and_then(|file| serde_json::from_reader(file).map_err(io::Error::other))
.map_err(|source| NymvisorError::UpgradeHistoryLoadFailure {
path: path.to_path_buf(),
source,
Expand Down Expand Up @@ -481,10 +472,7 @@ impl CurrentVersionInfo {
pub(crate) fn try_load<P: AsRef<Path>>(path: P) -> Result<Self, NymvisorError> {
let path = path.as_ref();
fs::File::open(path)
.and_then(|file| {
serde_json::from_reader(file)
.map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err))
})
.and_then(|file| serde_json::from_reader(file).map_err(io::Error::other))
.map_err(|source| NymvisorError::CurrentVersionInfoLoadFailure {
path: path.to_path_buf(),
source,
Expand Down
Loading