Skip to content

Commit c0ffee8

Browse files
chore: clippy and min refactors
1 parent c0ffee1 commit c0ffee8

9 files changed

+107
-334
lines changed

crates/forge/src/mutation/mod.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ mod visitor;
55
// Generate mutants then run tests (reuse the whole unit test flow for now, including compilation to
66
// select mutants) Use Solar:
77
use solar_parse::{
8-
ast::{
9-
interface::{source_map::FileName, Session},
10-
ContractKind, ItemKind,
11-
},
8+
ast::interface::{source_map::FileName, Session},
129
Parser,
1310
};
1411
use std::sync::Arc;
@@ -35,8 +32,8 @@ impl MutationHandler {
3532
pub fn new(
3633
contract_to_mutate: PathBuf,
3734
config: Arc<foundry_config::Config>,
38-
) -> MutationHandler {
39-
MutationHandler {
35+
) -> Self {
36+
Self {
4037
contract_to_mutate,
4138
src: Arc::default(),
4239
mutations: vec![],
@@ -109,7 +106,7 @@ impl MutationHandler {
109106
let src_path = &self.contract_to_mutate;
110107

111108
self.mutations.iter().for_each(|mutant| {
112-
self.generate_mutant(&mutant, src_path);
109+
self.generate_mutant(mutant, src_path);
113110
});
114111

115112
self.mutations
@@ -125,7 +122,7 @@ impl MutationHandler {
125122
}
126123

127124
/// Copy the src, cache, out and test folders to one of the mutant temp folder
128-
fn copy_origin(path: &PathBuf, src_contract_path: &PathBuf, config: Arc<Config>) {
125+
fn copy_origin(path: &Path, src_contract_path: &Path, config: Arc<Config>) {
129126
let cache_src = &config.cache_path;
130127
let out_src = &config.out;
131128
let contract_src = &config.src;
@@ -141,13 +138,13 @@ impl MutationHandler {
141138
std::fs::create_dir_all(&contract_dest).expect("Failed to create temp src directory");
142139
std::fs::create_dir_all(&test_dest).expect("Failed to create temp src directory");
143140

144-
Self::copy_dir_except(&cache_src, &cache_dest, src_contract_path)
141+
Self::copy_dir_except(cache_src, cache_dest, src_contract_path)
145142
.expect("Failed to copy in temp cache");
146-
Self::copy_dir_except(&out_src, &out_dest, src_contract_path)
143+
Self::copy_dir_except(out_src, out_dest, src_contract_path)
147144
.expect("Failed to copy in temp out directory");
148-
Self::copy_dir_except(&contract_src, &contract_dest, src_contract_path)
145+
Self::copy_dir_except(contract_src, contract_dest, src_contract_path)
149146
.expect("Failed to copy in temp src directory");
150-
Self::copy_dir_except(&test_src, &test_dest, src_contract_path)
147+
Self::copy_dir_except(test_src, test_dest, src_contract_path)
151148
.expect("Failed to copy in temp src directory");
152149
}
153150

@@ -156,7 +153,7 @@ impl MutationHandler {
156153
fn copy_dir_except(
157154
src: impl AsRef<Path>,
158155
dst: impl AsRef<Path>,
159-
except: &PathBuf,
156+
except: &Path,
160157
) -> std::io::Result<()> {
161158
std::fs::create_dir_all(&dst)?;
162159

@@ -166,24 +163,22 @@ impl MutationHandler {
166163

167164
if ty.is_dir() {
168165
Self::copy_dir_except(
169-
&entry.path(),
170-
&dst.as_ref().join(entry.file_name()),
166+
entry.path(),
167+
dst.as_ref().join(entry.file_name()),
171168
except,
172169
)?;
173-
} else {
174-
if entry.file_name() != except.file_name().unwrap_or_default() {
170+
} else if entry.file_name() != except.file_name().unwrap_or_default() {
175171
// std::os::unix::fs::symlink(entry.path(),
176172
// &dst.as_ref().join(entry.file_name()))?; // and for windows, would be
177173
// std::os::windows::fs::symlink_file
178-
std::fs::copy(entry.path(), &dst.as_ref().join(entry.file_name()))?;
179-
}
174+
std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
180175
}
181176
}
182177
Ok(())
183178
}
184179

185180
/// Based on a given mutation, emit the corresponding mutated solidity code and write it to disk
186-
fn generate_mutant(&self, mutation: &Mutant, src_contract_path: &PathBuf) {
181+
fn generate_mutant(&self, mutation: &Mutant, src_contract_path: &Path) {
187182
let temp_dir_path = &mutation.path;
188183

189184
let span = mutation.span;
@@ -214,7 +209,7 @@ impl MutationHandler {
214209
dbg!(&new_content);
215210

216211
std::fs::write(&target_path, new_content)
217-
.expect(&format!("Failed to write to target file {:?}", &target_path));
212+
.unwrap_or_else(|_| panic!("Failed to write to target file {:?}", &target_path));
218213
}
219214

220215
/// Compile a directory and get the compilation output

0 commit comments

Comments
 (0)