diff --git a/consensus/consensus-types/src/block_test_utils.rs b/consensus/consensus-types/src/block_test_utils.rs index 98b270fc181d..22c0ccf20132 100644 --- a/consensus/consensus-types/src/block_test_utils.rs +++ b/consensus/consensus-types/src/block_test_utils.rs @@ -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, diff --git a/consensus/src/quorum_store/utils.rs b/consensus/src/quorum_store/utils.rs index dee6ebdc5715..eac4b9900729 100644 --- a/consensus/src/quorum_store/utils.rs +++ b/consensus/src/quorum_store/utils.rs @@ -38,7 +38,7 @@ impl Timeouts { } pub(crate) fn expire(&mut self) -> Vec { - 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, diff --git a/crates/crash-handler/src/lib.rs b/crates/crash-handler/src/lib.rs index 6cd0472f7417..bf0d6cafc1f6 100644 --- a/crates/crash-handler/src/lib.rs +++ b/crates/crash-handler/src/lib.rs @@ -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, }; @@ -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()); diff --git a/crates/diem-crypto-derive/src/lib.rs b/crates/diem-crypto-derive/src/lib.rs index ed62923cf143..7b50eedd3545 100644 --- a/crates/diem-crypto-derive/src/lib.rs +++ b/crates/diem-crypto-derive/src/lib.rs @@ -96,7 +96,6 @@ //! } //! ``` -#![forbid(unsafe_code)] extern crate proc_macro; diff --git a/crates/diem-crypto/src/hash.rs b/crates/diem-crypto/src/hash.rs index 26480f1c233d..d2d931cde740 100644 --- a/crates/diem-crypto/src/hash.rs +++ b/crates/diem-crypto/src/hash.rs @@ -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; diff --git a/crates/diem-crypto/src/noise.rs b/crates/diem-crypto/src/noise.rs index 84601eb2c3d9..f007d690d052 100644 --- a/crates/diem-crypto/src/noise.rs +++ b/crates/diem-crypto/src/noise.rs @@ -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}; diff --git a/crates/diem-id-generator/src/lib.rs b/crates/diem-id-generator/src/lib.rs index e1a5278b9495..59af1f83dd93 100644 --- a/crates/diem-id-generator/src/lib.rs +++ b/crates/diem-id-generator/src/lib.rs @@ -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 { diff --git a/crates/diem-log-derive/src/lib.rs b/crates/diem-log-derive/src/lib.rs index 365a50b5e4a7..0778daa72be8 100644 --- a/crates/diem-log-derive/src/lib.rs +++ b/crates/diem-log-derive/src/lib.rs @@ -153,6 +153,7 @@ fn extract_attr(attrs: &[Attribute]) -> Option { 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 diff --git a/crates/diem-openapi/src/lib.rs b/crates/diem-openapi/src/lib.rs index 04190be54d34..d7259a4f7e1f 100644 --- a/crates/diem-openapi/src/lib.rs +++ b/crates/diem-openapi/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] // Copyright © Diem Foundation // SPDX-License-Identifier: Apache-2.0 diff --git a/crates/diem-time-service/src/lib.rs b/crates/diem-time-service/src/lib.rs index 9f0a1227335f..4bec6296d31d 100644 --- a/crates/diem-time-service/src/lib.rs +++ b/crates/diem-time-service/src/lib.rs @@ -267,7 +267,7 @@ impl From for Sleep { } } -#[cfg(any(test, feature = "fuzzing", feature = "testing"))] +#[cfg(any(test, feature = "testing"))] impl From for Sleep { fn from(sleep: MockSleep) -> Self { Sleep::MockSleep(sleep) @@ -304,7 +304,7 @@ 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), } } @@ -312,7 +312,7 @@ impl SleepTrait for Sleep { 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), } } @@ -320,7 +320,7 @@ impl SleepTrait for Sleep { 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), } } diff --git a/crates/diem-time-service/src/mock.rs b/crates/diem-time-service/src/mock.rs index 91c614014f15..1679c5375a1e 100644 --- a/crates/diem-time-service/src/mock.rs +++ b/crates/diem-time-service/src/mock.rs @@ -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) } diff --git a/crates/indexer/src/runtime.rs b/crates/indexer/src/runtime.rs index 6cbc3a1b9940..5d65e0a913c7 100644 --- a/crates/indexer/src/runtime.rs +++ b/crates/indexer/src/runtime.rs @@ -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); } diff --git a/crates/moving-average/src/lib.rs b/crates/moving-average/src/lib.rs index 028ea273cab1..7736ebc97a9f 100644 --- a/crates/moving-average/src/lib.rs +++ b/crates/moving-average/src/lib.rs @@ -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); } diff --git a/crates/short-hex-str/src/lib.rs b/crates/short-hex-str/src/lib.rs index 2b03c4d9234b..b4dbf4f56f0c 100644 --- a/crates/short-hex-str/src/lib.rs +++ b/crates/short-hex-str/src/lib.rs @@ -84,7 +84,7 @@ 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) @@ -92,7 +92,7 @@ fn byte2hex(byte: u8) -> (u8, u8) { /// 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()); diff --git a/ecosystem/indexer-grpc/indexer-grpc-server-framework/src/lib.rs b/ecosystem/indexer-grpc/indexer-grpc-server-framework/src/lib.rs index 4ec80f01dcbf..56983d6d8092 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-server-framework/src/lib.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-server-framework/src/lib.rs @@ -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}; @@ -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 }; diff --git a/storage/backup/backup-cli/src/lib.rs b/storage/backup/backup-cli/src/lib.rs index d5ecbe906268..9335043a3d32 100644 --- a/storage/backup/backup-cli/src/lib.rs +++ b/storage/backup/backup-cli/src/lib.rs @@ -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; diff --git a/storage/diemdb/src/event_store/mod.rs b/storage/diemdb/src/event_store/mod.rs index 57fc04547c29..78e817894364 100644 --- a/storage/diemdb/src/event_store/mod.rs +++ b/storage/diemdb/src/event_store/mod.rs @@ -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 { diff --git a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/ed25519.rs b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/ed25519.rs index 498b3bbe1d08..1dfa15aed680 100644 --- a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/ed25519.rs +++ b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/ed25519.rs @@ -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}, diff --git a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/hash.rs b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/hash.rs index 3768c1f8374e..a79a32503b5d 100644 --- a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/hash.rs +++ b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/hash.rs @@ -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::*; diff --git a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/noise.rs b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/noise.rs index 043e6ac7c7f0..7d7a1942f606 100644 --- a/third_party/move/documentation/examples/diem-framework/crates/crypto/src/noise.rs +++ b/third_party/move/documentation/examples/diem-framework/crates/crypto/src/noise.rs @@ -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::{ diff --git a/third_party/move/move-borrow-graph/src/graph.rs b/third_party/move/move-borrow-graph/src/graph.rs index 517baa14631a..f39b85cf4c7c 100644 --- a/third_party/move/move-borrow-graph/src/graph.rs +++ b/third_party/move/move-borrow-graph/src/graph.rs @@ -64,7 +64,8 @@ impl BorrowGraph { 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()) diff --git a/third_party/move/move-borrow-graph/src/references.rs b/third_party/move/move-borrow-graph/src/references.rs index ed04d89edb11..6461386c739d 100644 --- a/third_party/move/move-borrow-graph/src/references.rs +++ b/third_party/move/move-borrow-graph/src/references.rs @@ -209,6 +209,7 @@ impl PartialEq for BorrowEdge { impl Eq for BorrowEdge {} +#[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for BorrowEdge { fn partial_cmp(&self, other: &BorrowEdge) -> Option { BorrowEdgeNoLoc::new(self).partial_cmp(&BorrowEdgeNoLoc::new(other)) diff --git a/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/catch_unwind.rs b/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/catch_unwind.rs index b248c8584f0d..f986cb42b157 100644 --- a/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/catch_unwind.rs +++ b/third_party/move/move-bytecode-verifier/bytecode-verifier-tests/src/unit_tests/catch_unwind.rs @@ -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. @@ -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); })); diff --git a/third_party/move/move-core/types/src/gas_algebra.rs b/third_party/move/move-core/types/src/gas_algebra.rs index c6231a011e41..b62abc1a4ca4 100644 --- a/third_party/move/move-core/types/src/gas_algebra.rs +++ b/third_party/move/move-core/types/src/gas_algebra.rs @@ -125,6 +125,7 @@ impl From> for u64 { * Clone & Copy * **************************************************************************************************/ +#[allow(clippy::non_canonical_clone_impl)] impl Clone for GasQuantity { fn clone(&self) -> Self { Self::new(self.val) @@ -167,6 +168,7 @@ impl PartialEq for GasQuantity { impl Eq for GasQuantity {} +#[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for GasQuantity { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp_impl(other)) diff --git a/third_party/move/move-core/types/src/parser.rs b/third_party/move/move-core/types/src/parser.rs index 6145cf926352..ef74240931b8 100644 --- a/third_party/move/move-core/types/src/parser.rs +++ b/third_party/move/move-core/types/src/parser.rs @@ -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, diff --git a/third_party/move/move-core/types/src/u256.rs b/third_party/move/move-core/types/src/u256.rs index b73647ea06fe..7e76078c4271 100644 --- a/third_party/move/move-core/types/src/u256.rs +++ b/third_party/move/move-core/types/src/u256.rs @@ -567,7 +567,6 @@ impl Distribution 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,