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

Fixes to get clippy to run clean #27

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion consensus/consensus-types/src/block_test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Diem Foundation
// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

use crate::{
block::Block,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/quorum_store/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<T> Timeouts<T> {
}

pub(crate) fn expire(&mut self) -> Vec<T> {
let cur_time = chrono::Utc::now().naive_utc().timestamp_millis();
let cur_time = chrono::Utc::now().naive_utc().and_utc().timestamp_millis();
trace!(
"QS: expire cur time {} timeouts len {}",
cur_time,
Expand Down
8 changes: 4 additions & 4 deletions crates/crash-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use backtrace::Backtrace;
use move_core_types::state::{self, VMState};
use serde::Serialize;
use std::{
panic::{self, PanicInfo},
panic::{self, PanicHookInfo},
process,
};

Expand All @@ -25,14 +25,14 @@ pub struct CrashInfo {
/// ensure that all subsequent thread panics (even Tokio threads) will report the
/// details/backtrace and then exit.
pub fn setup_panic_handler() {
panic::set_hook(Box::new(move |pi: &PanicInfo<'_>| {
panic::set_hook(Box::new(move |pi: &PanicHookInfo<'_>| {
handle_panic(pi);
}));
}

// Formats and logs panic information
fn handle_panic(panic_info: &PanicInfo<'_>) {
// The Display formatter for a PanicInfo contains the message, payload and location.
fn handle_panic(panic_info: &PanicHookInfo<'_>) {
// The Display formatter for a PanicHookInfo contains the message, payload and location.
let details = format!("{}", panic_info);
let backtrace = format!("{:#?}", Backtrace::new());

Expand Down
1 change: 0 additions & 1 deletion crates/diem-crypto-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
//! }
//! ```

#![forbid(unsafe_code)]

extern crate proc_macro;

Expand Down
2 changes: 1 addition & 1 deletion crates/diem-crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
//! hasher.update("Test message".as_bytes());
//! let hash_value = hasher.finish();
//! ```
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]
use bytes::Bytes;
use hex::FromHex;
use more_asserts::debug_assert_lt;
Expand Down
2 changes: 1 addition & 1 deletion crates/diem-crypto/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
//! # }
//! ```
//!
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

use crate::{hash::HashValue, hkdf::Hkdf, traits::Uniform as _, x25519, ValidCryptoMaterial};
use ring::aead::{self, Aad, LessSafeKey, UnboundKey};
Expand Down
1 change: 1 addition & 0 deletions crates/diem-id-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct U32IdGenerator {
inner: AtomicU32,
}

#[allow(clippy::new_without_default)]
impl U32IdGenerator {
/// Creates a new [`U32IdGenerator`] initialized to `0`
pub const fn new() -> Self {
Expand Down
1 change: 1 addition & 0 deletions crates/diem-log-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fn extract_attr(attrs: &[Attribute]) -> Option<ValueType> {
for segment in path.segments {
// Only handle schema attrs
if segment.ident == "schema" {
#[allow(clippy::never_loop)]
for meta in &nested {
let path = if let NestedMeta::Meta(Meta::Path(path)) = meta {
path
Expand Down
1 change: 1 addition & 0 deletions crates/diem-openapi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_imports)]
// Copyright © Diem Foundation
// SPDX-License-Identifier: Apache-2.0

Expand Down
8 changes: 4 additions & 4 deletions crates/diem-time-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl From<RealSleep> for Sleep {
}
}

#[cfg(any(test, feature = "fuzzing", feature = "testing"))]
#[cfg(any(test, feature = "testing"))]
impl From<MockSleep> for Sleep {
fn from(sleep: MockSleep) -> Self {
Sleep::MockSleep(sleep)
Expand Down Expand Up @@ -304,23 +304,23 @@ impl SleepTrait for Sleep {
fn is_elapsed(&self) -> bool {
match self {
Sleep::RealSleep(inner) => SleepTrait::is_elapsed(inner),
#[cfg(any(test, feature = "fuzzing", feature = "testing"))]
#[cfg(any(test, feature = "testing"))]
Sleep::MockSleep(inner) => SleepTrait::is_elapsed(inner),
}
}

fn reset(self: Pin<&mut Self>, duration: Duration) {
match self.project() {
SleepProject::RealSleep(inner) => SleepTrait::reset(inner, duration),
#[cfg(any(test, feature = "fuzzing", feature = "testing"))]
#[cfg(any(test, feature = "testing"))]
SleepProject::MockSleep(inner) => SleepTrait::reset(Pin::new(inner), duration),
}
}

fn reset_until(self: Pin<&mut Self>, deadline: Instant) {
match self.project() {
SleepProject::RealSleep(inner) => SleepTrait::reset_until(inner, deadline),
#[cfg(any(test, feature = "fuzzing", feature = "testing"))]
#[cfg(any(test, feature = "testing"))]
SleepProject::MockSleep(inner) => SleepTrait::reset_until(Pin::new(inner), deadline),
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/diem-time-service/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use std::{

/// TODO(philiphayes): Use `Duration::MAX` once it stabilizes.
#[inline]
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::legacy_numeric_constants)]
#[allow(clippy::arithmetic_side_effects)]
fn duration_max() -> Duration {
Duration::new(std::u64::MAX, 1_000_000_000 - 1)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/indexer/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl MovingAverage {
}

pub fn tick_now(&mut self, value: u64) {
let now = chrono::Utc::now().naive_utc().timestamp_millis() as u64;
let now = chrono::Utc::now().naive_utc().and_utc().timestamp_millis() as u64;
self.tick(now, value);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/moving-average/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl MovingAverage {
}

pub fn tick_now(&mut self, value: u64) {
let now = chrono::Utc::now().naive_utc().timestamp_millis() as u64;
let now = chrono::Utc::now().naive_utc().and_utc().timestamp_millis() as u64;
self.tick(now, value);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/short-hex-str/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ const HEX_CHARS_LOWER: &[u8; 16] = b"0123456789abcdef";
/// the second character as ASCII bytes.
#[inline(always)]
fn byte2hex(byte: u8) -> (u8, u8) {
#[allow(clippy::integer_arithmetic)] // X >> 4 is valid for all bytes
#[allow(clippy::arithmetic_side_effects)] // X >> 4 is valid for all bytes
let hi = HEX_CHARS_LOWER[((byte >> 4) & 0x0F) as usize];
let lo = HEX_CHARS_LOWER[(byte & 0x0F) as usize];
(hi, lo)
}

/// Hex encode a byte slice into the destination byte slice.
#[inline(always)]
#[allow(clippy::integer_arithmetic)] // debug only assertion
#[allow(clippy::arithmetic_side_effects)] // debug only assertion
fn hex_encode(src: &[u8], dst: &mut [u8]) {
debug_checked_precondition!(dst.len() == 2 * src.len());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use backtrace::Backtrace;
use clap::Parser;
use prometheus::{Encoder, TextEncoder};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{fs::File, io::Read, panic::PanicInfo, path::PathBuf, process};
use std::{fs::File, io::Read, panic::PanicHookInfo, path::PathBuf, process};
use tracing::error;
use tracing_subscriber::EnvFilter;
use warp::{http::Response, Filter};
Expand Down Expand Up @@ -107,14 +107,14 @@ pub struct CrashInfo {
/// ensure that all subsequent thread panics (even Tokio threads) will report the
/// details/backtrace and then exit.
pub fn setup_panic_handler() {
std::panic::set_hook(Box::new(move |pi: &PanicInfo<'_>| {
std::panic::set_hook(Box::new(move |pi: &PanicHookInfo<'_>| {
handle_panic(pi);
}));
}

// Formats and logs panic information
fn handle_panic(panic_info: &PanicInfo<'_>) {
// The Display formatter for a PanicInfo contains the message, payload and location.
fn handle_panic(panic_info: &PanicHookInfo<'_>) {
// The Display formatter for a PanicHookInfo contains the message, payload and location.
let details = format!("{}", panic_info);
let backtrace = format!("{:#?}", Backtrace::new());
let info = CrashInfo { details, backtrace };
Expand Down
2 changes: 1 addition & 1 deletion storage/backup/backup-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

pub mod backup_types;
pub mod coordinators;
Expand Down
2 changes: 1 addition & 1 deletion storage/diemdb/src/event_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl EventStore {
};

// overflow not possible
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
{
let mut count = end - begin;
while count > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! ```
//! **Note**: The above example generates a private key using a private function intended only for
//! testing purposes. Production code should find an alternate means for secure key generation.
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

use crate::{
hash::{CryptoHash, CryptoHasher},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
//! hasher.update("Test message".as_bytes());
//! let hash_value = hasher.finish();
//! ```
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]
use bytes::Bytes;
use hex::FromHex;
use mirai_annotations::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
//! # }
//! ```
//!
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

use crate::{hash::HashValue, hkdf::Hkdf, traits::Uniform as _, x25519};
use aes_gcm::{
Expand Down
3 changes: 2 additions & 1 deletion third_party/move/move-borrow-graph/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl<Loc: Copy, Lbl: Clone + Ord> BorrowGraph<Loc, Lbl> {
for (borrower, edges) in &borrowed_by.0 {
let borrower = *borrower;
for edge in edges {
match edge.path.get(0) {
#[allow(clippy::unwrap_or_default)]
match edge.path.first() {
None => full_borrows.insert(borrower, edge.loc),
Some(f) => field_borrows
.entry(f.clone())
Expand Down
1 change: 1 addition & 0 deletions third_party/move/move-borrow-graph/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl<Loc: Copy, Lbl: Clone + Ord> PartialEq for BorrowEdge<Loc, Lbl> {

impl<Loc: Copy, Lbl: Clone + Ord> Eq for BorrowEdge<Loc, Lbl> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<Loc: Copy, Lbl: Clone + Ord> PartialOrd for BorrowEdge<Loc, Lbl> {
fn partial_cmp(&self, other: &BorrowEdge<Loc, Lbl>) -> Option<Ordering> {
BorrowEdgeNoLoc::new(self).partial_cmp(&BorrowEdgeNoLoc::new(other))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use move_core_types::{
state::{self, VMState},
vm_status::StatusCode,
};
use std::panic::{self, PanicInfo};
use std::panic::{self, PanicHookInfo};

// TODO: this tests must run in its own process since otherwise any crashing test here
// secondary-crashes in the panic handler.
Expand All @@ -17,7 +17,7 @@ fn test_unwind() {
let scenario = FailScenario::setup();
fail::cfg("verifier-failpoint-panic", "panic").unwrap();

panic::set_hook(Box::new(move |_: &PanicInfo<'_>| {
panic::set_hook(Box::new(move |_: &PanicHookInfo<'_>| {
assert_eq!(state::get_state(), VMState::VERIFIER);
}));

Expand Down
2 changes: 2 additions & 0 deletions third_party/move/move-core/types/src/gas_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<U> From<GasQuantity<U>> for u64 {
* Clone & Copy
*
**************************************************************************************************/
#[allow(clippy::non_canonical_clone_impl)]
impl<U> Clone for GasQuantity<U> {
fn clone(&self) -> Self {
Self::new(self.val)
Expand Down Expand Up @@ -167,6 +168,7 @@ impl<U> PartialEq for GasQuantity<U> {

impl<U> Eq for GasQuantity<U> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<U> PartialOrd for GasQuantity<U> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp_impl(other))
Expand Down
1 change: 1 addition & 0 deletions third_party/move/move-core/types/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use anyhow::{bail, format_err, Result};
use std::iter::Peekable;

#[derive(Eq, PartialEq, Debug)]
#[allow(clippy::upper_case_acronyms)]
enum Token {
U8Type,
U16Type,
Expand Down
1 change: 0 additions & 1 deletion third_party/move/move-core/types/src/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ impl Distribution<U256> for Standard {
// Rand impl below are inspired by u128 impl found in https://rust-random.github.io/rand/src/rand/distributions/uniform.rs.html

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct UniformU256 {
low: U256,
range: U256,
Expand Down
Loading