Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
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
rust-lang/rust#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
  • Loading branch information
Yunlongs committed Apr 25, 2024
1 parent f7fb62a commit 1f4c922
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 19 deletions.
6 changes: 3 additions & 3 deletions hopper-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> = 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 {
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion hopper-core/src/depot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion hopper-core/src/depot/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions hopper-core/src/fuzz/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ use std::cell::Cell;

thread_local! {
// Deterministic generation in pilot phase
pub static PILOT_DET: Cell<bool> = Cell::new(false);
pub static PILOT_DET: Cell<bool> = const { Cell::new(false) };
// Generate only single call
pub static SINGLE_CALL: Cell<bool> = Cell::new(true);
pub static SINGLE_CALL: Cell<bool> = const { Cell::new(true) };
// Reuse statement in generation
pub static REUSE_STMT: Cell<bool> = Cell::new(false);
pub static REUSE_STMT: Cell<bool> = const { Cell::new(false) };
// Only mutate argument inputs.
pub static INPUT_ONLY: Cell<bool> = Cell::new(false);
pub static INPUT_ONLY: Cell<bool> = const { Cell::new(false) };
// Refine successful or not
pub static REFINE_SUC: Cell<bool> = Cell::new(false);
pub static REFINE_SUC: Cell<bool> = const { Cell::new(false) };
// Mutate pointer or not
pub static MUTATE_PTR: Cell<bool> = Cell::new(false);
pub static MUTATE_PTR: Cell<bool> = const { Cell::new(false) };
// deterministic mutation for call
pub static CALL_DET: Cell<bool> = Cell::new(false);
pub static CALL_DET: Cell<bool> = const { Cell::new(false) };
// Generate an incomplete program
pub static INCOMPLETE_GEN: Cell<bool> = Cell::new(false);
pub static INCOMPLETE_GEN: Cell<bool> = const { Cell::new(false) };
// Running in pilot infer phase
pub static PILOT_INFER: Cell<bool> = Cell::new(false);
pub static PILOT_INFER: Cell<bool> = const { Cell::new(false) };
// u64 temp value
pub static TMP_U64: Cell<u64> = Cell::new(0);
pub static TMP_U64: Cell<u64> = const { Cell::new(0) };
}

pub fn is_pilot_det() -> bool {
Expand Down
1 change: 0 additions & 1 deletion hopper-core/src/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion hopper-core/src/fuzz/stmt/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum ExpectedValue {
unsafe impl Sync for ExpectedValue {}

thread_local! {
static ASSERTIONS: RefCell<Vec<Assertion>> = RefCell::new(vec![]);
static ASSERTIONS: RefCell<Vec<Assertion>> = const { RefCell::new(vec![]) };
}

pub fn add_assertion(assertion: Assertion) {
Expand Down
1 change: 0 additions & 1 deletion hopper-core/src/fuzz/stmt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{impl_stmt_match, runtime::*};
pub use call::*;
use super::*;

pub trait StmtMutate: WeightedItem {
Expand Down
1 change: 0 additions & 1 deletion hopper-core/src/runtime/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit 1f4c922

Please sign in to comment.