From 1f4c9224167b1dd1b9232fb75b385a9394a08e19 Mon Sep 17 00:00:00 2001 From: Yunlongs Date: Thu, 25 Apr 2024 18:35:25 +0800 Subject: [PATCH] Fix cargo clippy warnings I found there were clippy warnings introduced in recent rust versions. I fixed the following three types of warnings: 1. creating a mutable reference to mutable static is discouraged https://github.com/rust-lang/rust/issues/114447 2. initializer for `thread_local` value can be made `const` https://rust-lang.github.io/rust-clippy/master/index.html#thread_local_initializer_can_be_made_const 3. unused imported libraries --- hopper-core/src/config.rs | 6 +++--- hopper-core/src/depot/mod.rs | 1 - hopper-core/src/depot/select.rs | 2 +- hopper-core/src/fuzz/flag.rs | 20 ++++++++++---------- hopper-core/src/fuzz/mod.rs | 1 - hopper-core/src/fuzz/stmt/assert.rs | 2 +- hopper-core/src/fuzz/stmt/mod.rs | 1 - hopper-core/src/runtime/object/mod.rs | 1 - 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/hopper-core/src/config.rs b/hopper-core/src/config.rs index 34055ff..64b9699 100644 --- a/hopper-core/src/config.rs +++ b/hopper-core/src/config.rs @@ -151,12 +151,12 @@ pub struct Config { use eyre::Context; use once_cell::sync::OnceCell; -use std::io::BufRead; +use std::{io::BufRead, ptr::{addr_of, addr_of_mut}}; pub static mut CONFIG_INSTANCE: Option = None; pub fn get_config() -> &'static Config { - if let Some(c) = unsafe { &CONFIG_INSTANCE } { + if let Some(Some(c)) = unsafe { addr_of!(CONFIG_INSTANCE).as_ref() } { return c; } unsafe { @@ -166,7 +166,7 @@ pub fn get_config() -> &'static Config { } pub fn get_config_mut() -> &'static mut Config { - if let Some(c) = unsafe { &mut CONFIG_INSTANCE } { + if let Some(Some(c)) = unsafe { addr_of_mut!(CONFIG_INSTANCE).as_mut() } { return c; } unsafe { diff --git a/hopper-core/src/depot/mod.rs b/hopper-core/src/depot/mod.rs index de3c82e..b05ffb0 100644 --- a/hopper-core/src/depot/mod.rs +++ b/hopper-core/src/depot/mod.rs @@ -8,7 +8,6 @@ use self::select::*; use crate::{execute::StatusType, FuzzProgram, FeedbackSummary}; pub use io::*; use priority::PriorityWrap; -pub use priority::*; /// Depot for saving all inputs, hangs, and crashes. pub struct Depot { diff --git a/hopper-core/src/depot/select.rs b/hopper-core/src/depot/select.rs index 760f1b5..f753efb 100644 --- a/hopper-core/src/depot/select.rs +++ b/hopper-core/src/depot/select.rs @@ -45,7 +45,7 @@ const SA_UNIQ_NEW: u64 = 3; const KEY_BONUS: u64 = 2; thread_local! { - static AVG_SCORE: Cell<(f64, u64)> = Cell::new((0_f64, 0_u64)); + static AVG_SCORE: Cell<(f64, u64)> = const { Cell::new((0_f64, 0_u64)) }; } impl Selector for SaSelector { diff --git a/hopper-core/src/fuzz/flag.rs b/hopper-core/src/fuzz/flag.rs index 8eaa46b..0693a9d 100644 --- a/hopper-core/src/fuzz/flag.rs +++ b/hopper-core/src/fuzz/flag.rs @@ -3,25 +3,25 @@ use std::cell::Cell; thread_local! { // Deterministic generation in pilot phase - pub static PILOT_DET: Cell = Cell::new(false); + pub static PILOT_DET: Cell = const { Cell::new(false) }; // Generate only single call - pub static SINGLE_CALL: Cell = Cell::new(true); + pub static SINGLE_CALL: Cell = const { Cell::new(true) }; // Reuse statement in generation - pub static REUSE_STMT: Cell = Cell::new(false); + pub static REUSE_STMT: Cell = const { Cell::new(false) }; // Only mutate argument inputs. - pub static INPUT_ONLY: Cell = Cell::new(false); + pub static INPUT_ONLY: Cell = const { Cell::new(false) }; // Refine successful or not - pub static REFINE_SUC: Cell = Cell::new(false); + pub static REFINE_SUC: Cell = const { Cell::new(false) }; // Mutate pointer or not - pub static MUTATE_PTR: Cell = Cell::new(false); + pub static MUTATE_PTR: Cell = const { Cell::new(false) }; // deterministic mutation for call - pub static CALL_DET: Cell = Cell::new(false); + pub static CALL_DET: Cell = const { Cell::new(false) }; // Generate an incomplete program - pub static INCOMPLETE_GEN: Cell = Cell::new(false); + pub static INCOMPLETE_GEN: Cell = const { Cell::new(false) }; // Running in pilot infer phase - pub static PILOT_INFER: Cell = Cell::new(false); + pub static PILOT_INFER: Cell = const { Cell::new(false) }; // u64 temp value - pub static TMP_U64: Cell = Cell::new(0); + pub static TMP_U64: Cell = const { Cell::new(0) }; } pub fn is_pilot_det() -> bool { diff --git a/hopper-core/src/fuzz/mod.rs b/hopper-core/src/fuzz/mod.rs index 335100d..0ec4a02 100644 --- a/hopper-core/src/fuzz/mod.rs +++ b/hopper-core/src/fuzz/mod.rs @@ -23,7 +23,6 @@ pub use constraints::*; pub use det::*; pub use flag::*; pub use generate::*; -pub use mutate::*; pub use object::*; pub use operator::*; pub use rng::*; diff --git a/hopper-core/src/fuzz/stmt/assert.rs b/hopper-core/src/fuzz/stmt/assert.rs index 62f4185..b5b285a 100644 --- a/hopper-core/src/fuzz/stmt/assert.rs +++ b/hopper-core/src/fuzz/stmt/assert.rs @@ -30,7 +30,7 @@ pub enum ExpectedValue { unsafe impl Sync for ExpectedValue {} thread_local! { - static ASSERTIONS: RefCell> = RefCell::new(vec![]); + static ASSERTIONS: RefCell> = const { RefCell::new(vec![]) }; } pub fn add_assertion(assertion: Assertion) { diff --git a/hopper-core/src/fuzz/stmt/mod.rs b/hopper-core/src/fuzz/stmt/mod.rs index ea4ac06..c551146 100644 --- a/hopper-core/src/fuzz/stmt/mod.rs +++ b/hopper-core/src/fuzz/stmt/mod.rs @@ -1,5 +1,4 @@ use crate::{impl_stmt_match, runtime::*}; -pub use call::*; use super::*; pub trait StmtMutate: WeightedItem { diff --git a/hopper-core/src/runtime/object/mod.rs b/hopper-core/src/runtime/object/mod.rs index 16de4de..969d279 100644 --- a/hopper-core/src/runtime/object/mod.rs +++ b/hopper-core/src/runtime/object/mod.rs @@ -15,7 +15,6 @@ mod bitfield; pub use builder::*; pub use canary::*; pub use layout::*; -pub use pointer::*; pub use state::*; pub use void::*; pub use bitfield::*;