From ffe7c9ae3bd0d96313299b4d641b1270fc341dd1 Mon Sep 17 00:00:00 2001 From: Dat Tien Nguyen Date: Sun, 20 Oct 2024 12:09:09 +0700 Subject: [PATCH] fix: remove some `allow` directive Signed-off-by: Dat Tien Nguyen --- datadriven/src/datadriven.rs | 6 ++---- datadriven/src/test_data_reader.rs | 6 ++---- src/lib.rs | 33 +++++++++++++----------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/datadriven/src/datadriven.rs b/datadriven/src/datadriven.rs index f3778441..64dda20b 100644 --- a/datadriven/src/datadriven.rs +++ b/datadriven/src/datadriven.rs @@ -138,7 +138,6 @@ where // run_directive runs just one directive in the input. // -#[allow(clippy::manual_inspect)] fn run_directive(r: &mut TestDataReader, mut f: F) where F: FnMut(&TestData) -> String, @@ -157,10 +156,9 @@ where if has_blank_line(&actual) { r.emit("----"); - r.rewrite_buffer.as_mut().map(|rb| { + if let Some(rb) = r.rewrite_buffer.as_mut() { rb.push_str(&actual); - rb - }); + } r.emit("----"); r.emit("----"); diff --git a/datadriven/src/test_data_reader.rs b/datadriven/src/test_data_reader.rs index 6b1be754..9d11d22c 100644 --- a/datadriven/src/test_data_reader.rs +++ b/datadriven/src/test_data_reader.rs @@ -205,12 +205,10 @@ impl<'a> TestDataReader<'a> { } } - #[allow(clippy::manual_inspect)] pub fn emit(&mut self, str: &str) { - self.rewrite_buffer.as_mut().map(|rb| { + if let Some(rb) = self.rewrite_buffer.as_mut() { let str = str.to_string() + "\n"; rb.push_str(&str); - rb - }); + } } } diff --git a/src/lib.rs b/src/lib.rs index 0b2879e4..fc01400c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -469,9 +469,9 @@ node.propose_conf_change(vec![], cc).unwrap(); This process is a two-phase process, during the midst of it the peer group's leader is managing **two independent, possibly overlapping peer sets**. -\> **Note:** In order to maintain resiliency guarantees (progress while a majority of both peer sets is -active), it is recommended to wait until the entire peer group has exited the transition phase -before taking old, removed peers offline. +> **Note:** In order to maintain resiliency guarantees (progress while a majority of both peer sets is +> active), it is recommended to wait until the entire peer group has exited the transition phase +> before taking old, removed peers offline. */ @@ -569,25 +569,20 @@ pub mod prelude { /// The default logger we fall back to when passed `None` in external facing constructors. /// -/// Currently, this is a `log` adaptor behind a `Once` to ensure there is no clobbering. +/// Currently, this is a `log` adaptor behind a `OnceLock` to ensure there is no clobbering. #[cfg(any(test, feature = "default-logger"))] -#[allow(static_mut_refs)] pub fn default_logger() -> slog::Logger { use slog::{o, Drain}; - use std::sync::{Mutex, Once}; - - static LOGGER_INITIALIZED: Once = Once::new(); - static mut LOGGER: Option = None; - - let logger = unsafe { - LOGGER_INITIALIZED.call_once(|| { - let decorator = slog_term::TermDecorator::new().build(); - let drain = slog_term::CompactFormat::new(decorator).build(); - let drain = slog_envlogger::new(drain); - LOGGER = Some(slog::Logger::root(Mutex::new(drain).fuse(), o!())); - }); - LOGGER.as_ref().unwrap() - }; + use std::sync::{Mutex, OnceLock}; + + static LOGGER_INITIALIZED: OnceLock = OnceLock::new(); + let logger = LOGGER_INITIALIZED.get_or_init(|| { + let decorator = slog_term::TermDecorator::new().build(); + let drain = slog_term::CompactFormat::new(decorator).build(); + let drain = slog_envlogger::new(drain); + slog::Logger::root(Mutex::new(drain).fuse(), o!()) + }); + if let Some(case) = std::thread::current() .name() .and_then(|v| v.split(':').last())