From 0d01a42e5bb666c12c15ee95875c4df07640d629 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Thu, 20 Feb 2025 19:10:12 +0700 Subject: [PATCH] chore: address clippy lints for Rust 1.86.0-beta Pull-Request: #5876. --- misc/quick-protobuf-codec/src/lib.rs | 2 +- protocols/autonat/src/v2/client/handler/dial_request.rs | 5 ++--- protocols/kad/src/kbucket/key.rs | 1 + protocols/kad/src/lib.rs | 4 ++-- transports/webrtc/src/tokio/udp_mux.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/misc/quick-protobuf-codec/src/lib.rs b/misc/quick-protobuf-codec/src/lib.rs index d49315a54c3..28b53946899 100644 --- a/misc/quick-protobuf-codec/src/lib.rs +++ b/misc/quick-protobuf-codec/src/lib.rs @@ -252,7 +252,7 @@ mod tests { let mut src = BytesMut::new(); src.extend_from_slice(encoded_length); - src.extend(std::iter::repeat(0).take(length)); + src.extend(std::iter::repeat_n(0, length)); src } diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index 61f564505eb..9fb54c87a49 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -2,7 +2,7 @@ use std::{ collections::VecDeque, convert::Infallible, io, - iter::{once, repeat}, + iter::{once, repeat_n}, task::{Context, Poll}, time::Duration, }; @@ -326,8 +326,7 @@ where { let count_full = num_bytes / DATA_FIELD_LEN_UPPER_BOUND; let partial_len = num_bytes % DATA_FIELD_LEN_UPPER_BOUND; - for req in repeat(DATA_FIELD_LEN_UPPER_BOUND) - .take(count_full) + for req in repeat_n(DATA_FIELD_LEN_UPPER_BOUND, count_full) .chain(once(partial_len)) .filter(|e| *e > 0) .map(|data_count| { diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index ce14a3f779a..4080657d239 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -17,6 +17,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#![allow(clippy::manual_div_ceil)] use std::{ borrow::Borrow, diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index 91983b9aaf7..5201832a2ba 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -88,7 +88,7 @@ pub use record::{store, Key as RecordKey, ProviderRecord, Record}; /// DHT should agree on the choices made for (1) and (2). /// /// The current value is `20`. -pub const K_VALUE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(20) }; +pub const K_VALUE: NonZeroUsize = NonZeroUsize::new(20).unwrap(); /// The `α` parameter of the Kademlia specification. /// @@ -98,7 +98,7 @@ pub const K_VALUE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(20) }; /// locating the closest peers to a key. /// /// The current value is `3`. -pub const ALPHA_VALUE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; +pub const ALPHA_VALUE: NonZeroUsize = NonZeroUsize::new(3).unwrap(); pub const PROTOCOL_NAME: StreamProtocol = protocol::DEFAULT_PROTO_NAME; diff --git a/transports/webrtc/src/tokio/udp_mux.rs b/transports/webrtc/src/tokio/udp_mux.rs index dcb88592c9b..090f99a8ef2 100644 --- a/transports/webrtc/src/tokio/udp_mux.rs +++ b/transports/webrtc/src/tokio/udp_mux.rs @@ -561,7 +561,7 @@ fn ufrag_from_stun_message(buffer: &[u8], local_ufrag: bool) -> Result Ok(s.to_owned()),