From 48f546aeed69648424a441766b8664de412e008d Mon Sep 17 00:00:00 2001 From: MingyuChen Date: Tue, 4 Jul 2023 11:33:49 +0800 Subject: [PATCH] fix lint problem Signed-off-by: MingyuChen --- ylong_runtime/src/executor/async_pool.rs | 2 +- ylong_runtime/src/net/async_source.rs | 2 +- ylong_runtime/src/select.rs | 2 +- ylong_runtime/src/util/fastrand.rs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ylong_runtime/src/executor/async_pool.rs b/ylong_runtime/src/executor/async_pool.rs index a3f42d9..5bf03f3 100644 --- a/ylong_runtime/src/executor/async_pool.rs +++ b/ylong_runtime/src/executor/async_pool.rs @@ -317,7 +317,7 @@ impl MultiThreadScheduler { } let num = self.locals.len(); - let start = fast_random() >> 56; + let start = (fast_random() >> 56) as usize; for i in 0..num { let i = (start + i) % num; diff --git a/ylong_runtime/src/net/async_source.rs b/ylong_runtime/src/net/async_source.rs index 910ad18..831b33a 100644 --- a/ylong_runtime/src/net/async_source.rs +++ b/ylong_runtime/src/net/async_source.rs @@ -53,7 +53,7 @@ impl AsyncSource { pub fn new(mut io: E, interest: Option) -> io::Result> { #[cfg(not(feature = "ffrt"))] let inner = { - let context = get_current_ctx().ok_or(io::Error::new(io::ErrorKind::Other, "get_current_ctx() fail"))?; + let context = get_current_ctx().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "get_current_ctx() fail"))?; match context { WorkerContext::Multi(ctx) => &ctx.handle, WorkerContext::Curr(ctx) => &ctx.handle, diff --git a/ylong_runtime/src/select.rs b/ylong_runtime/src/select.rs index c14c984..3b1c455 100644 --- a/ylong_runtime/src/select.rs +++ b/ylong_runtime/src/select.rs @@ -200,7 +200,7 @@ macro_rules! select { // When a branch ready first, modify this variable to // branch's index to ensure that the branch is executed first. use $crate::util::fastrand::fast_random; - let mut random_number = fast_random(); + let mut random_number = fast_random() as usize; let output = { let mut futures = ( $( $fut , )+ ); diff --git a/ylong_runtime/src/util/fastrand.rs b/ylong_runtime/src/util/fastrand.rs index d66aff9..8013c03 100644 --- a/ylong_runtime/src/util/fastrand.rs +++ b/ylong_runtime/src/util/fastrand.rs @@ -25,9 +25,9 @@ use std::num::Wrapping; /// ```rust /// use ylong_runtime::util::fastrand::fast_random; /// let rand = fast_random(); -/// assert!(rand <= usize::MAX); +/// assert!(rand <= u64::MAX); /// ``` -pub fn fast_random() -> usize { +pub fn fast_random() -> u64 { thread_local! { static RNG: Cell> = Cell::new(Wrapping(seed())); } @@ -39,7 +39,7 @@ pub fn fast_random() -> usize { s ^= s >> 27; rng.set(s); s.0.wrapping_mul(0x2545_f491_4f6c_dd1d) - }) as usize + }) } fn seed() -> u64 { -- Gitee