From 8dffed032a8ef7be61d434b96f776072b6d21b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Mon, 14 Oct 2024 16:43:23 +0800 Subject: [PATCH] Chore: fix feature specific lint warnings - Fix: #1256 --- examples/raft-kv-memstore/tests/cluster/test_cluster.rs | 6 ++---- openraft/src/core/tick.rs | 8 ++++---- openraft/src/network/snapshot_transport.rs | 2 +- openraft/src/network/v2/network.rs | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs index 343ca565d..98b45f3f5 100644 --- a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs +++ b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs @@ -1,7 +1,6 @@ use std::backtrace::Backtrace; use std::collections::BTreeMap; -#[allow(deprecated)] // since nightly 1.82 -use std::panic::PanicInfo; +use std::panic::PanicHookInfo; use std::thread; use std::time::Duration; @@ -14,8 +13,7 @@ use raft_kv_memstore::store::Request; use tokio::runtime::Runtime; use tracing_subscriber::EnvFilter; -#[allow(deprecated)] // PanicInfo deprecated since nightly 1.82 -pub fn log_panic(panic: &PanicInfo) { +pub fn log_panic(panic: &PanicHookInfo) { let backtrace = { format!("{:?}", Backtrace::force_capture()) // #[cfg(feature = "bt")] diff --git a/openraft/src/core/tick.rs b/openraft/src/core/tick.rs index 4d25258e0..383b82860 100644 --- a/openraft/src/core/tick.rs +++ b/openraft/src/core/tick.rs @@ -156,6 +156,10 @@ where C: RaftTypeConfig } } +// AsyncRuntime::spawn is `spawn_local` with singlethreaded enabled. +// It will result in a panic: +// `spawn_local` called from outside of a `task::LocalSet`. +#[cfg(not(feature = "singlethreaded"))] #[cfg(test)] mod tests { use std::io::Cursor; @@ -181,10 +185,6 @@ mod tests { type Responder = crate::impls::OneshotResponder; } - // AsyncRuntime::spawn is `spawn_local` with singlethreaded enabled. - // It will result in a panic: - // `spawn_local` called from outside of a `task::LocalSet`. - #[cfg(not(feature = "singlethreaded"))] #[tokio::test] async fn test_shutdown() -> anyhow::Result<()> { let (tx, mut rx) = TickUTConfig::mpsc_unbounded(); diff --git a/openraft/src/network/snapshot_transport.rs b/openraft/src/network/snapshot_transport.rs index 4168ebde1..12e5b8adc 100644 --- a/openraft/src/network/snapshot_transport.rs +++ b/openraft/src/network/snapshot_transport.rs @@ -314,7 +314,7 @@ pub trait SnapshotTransport { /// /// - The receiving state `streaming` is maintained by the caller. /// - And it depends on `Raft::begin_receiving_snapshot()` to create a `SnapshotData` for - /// receiving data. + /// receiving data. /// /// Example usage: /// ```ignore diff --git a/openraft/src/network/v2/network.rs b/openraft/src/network/v2/network.rs index 01064a5d1..3a37abeb4 100644 --- a/openraft/src/network/v2/network.rs +++ b/openraft/src/network/v2/network.rs @@ -92,9 +92,9 @@ where C: RaftTypeConfig /// [`Raft::handle_transfer_leader()`]: crate::raft::Raft::handle_transfer_leader #[since(version = "0.10.0")] async fn transfer_leader(&mut self, _req: TransferLeaderRequest, _option: RPCOption) -> Result<(), RPCError> { - return Err(RPCError::Unreachable(Unreachable::new(&AnyError::error( + Err(RPCError::Unreachable(Unreachable::new(&AnyError::error( "transfer_leader not implemented", - )))); + )))) } /// Build a backoff instance if the target node is temporarily(or permanently) unreachable.