Skip to content

Commit 5681a6c

Browse files
authored
Copy lint settings from Wasmtime (#2156)
* Copy lint settings from Wasmtime Then use `--fix` to apply auto-suggested fixes everywhere. * Fix lint warning * More lint fixes
1 parent 71feb9e commit 5681a6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+219
-262
lines changed

Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ members = [
4646

4747
[workspace.lints.rust]
4848
unsafe_code = "deny"
49+
# Turn on some lints which are otherwise allow-by-default in rustc.
50+
unused_extern_crates = 'warn'
51+
unstable_features = 'warn'
52+
unused_import_braces = 'warn'
53+
unused-lifetimes = 'warn'
54+
unused-macro-rules = 'warn'
55+
56+
# Lints that are part of the `rust-2024-compatibility` group. This group is a
57+
# bit too noisy to enable wholesale but some selective items are ones we want to
58+
# opt-in to.
59+
keyword_idents_2024 = 'warn'
60+
unsafe-attr-outside-unsafe = 'warn'
61+
deprecated-safe-2024 = 'warn'
62+
rust-2024-guarded-string-incompatible-syntax = 'warn'
63+
rust-2024-prelude-collisions = 'warn'
64+
rust-2024-incompatible-pat = 'warn'
65+
missing-unsafe-on-extern = 'warn'
66+
unsafe-op-in-unsafe-fn = 'warn'
4967

5068
[workspace.lints.clippy]
5169
# The default set of lints in Clippy is viewed as "too noisy" right now so
@@ -56,6 +74,11 @@ clone_on_copy = 'warn'
5674
map_clone = 'warn'
5775
unnecessary_to_owned = 'warn'
5876
manual_strip = 'warn'
77+
uninlined_format_args = 'warn'
78+
unnecessary_mut_passed = 'warn'
79+
unnecessary_fallible_conversions = 'warn'
80+
unnecessary_cast = 'warn'
81+
allow_attributes_without_reason = 'warn'
5982

6083
[workspace.package]
6184
edition = '2021'

crates/c-api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum wasm_tools_error {
2626
}
2727
use wasm_tools_error::*;
2828

29-
#[no_mangle]
29+
#[unsafe(no_mangle)]
3030
pub extern "C" fn wasm_tools_byte_vec_delete(bytes: &mut wasm_tools_byte_vec_t) {
3131
unsafe {
3232
Vec::from_raw_parts(bytes.data, bytes.size, bytes.size);
@@ -38,7 +38,7 @@ pub extern "C" fn wasm_tools_byte_vec_delete(bytes: &mut wasm_tools_byte_vec_t)
3838
/// # Safety
3939
///
4040
/// `seed` must be a valid pointer to `seed_len` bytes of memory.
41-
#[no_mangle]
41+
#[unsafe(no_mangle)]
4242
pub unsafe extern "C" fn wasm_smith_create(
4343
seed: *const u8,
4444
seed_len: usize,

crates/fuzz-stats/src/bin/failed-instantiations.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ fn under_10_percent() {
3232
let bad = state.instantiate_trap.load(SeqCst) + state.instantiate_oom.load(SeqCst);
3333
assert!(
3434
bad < total / 10,
35-
"{} modules failed to instantiate out of {}, this failure rate is too high",
36-
bad,
37-
total
35+
"{bad} modules failed to instantiate out of {total}, this failure rate is too high"
3836
);
3937
}
4038

@@ -79,7 +77,7 @@ impl State {
7977
data.resize(cur + extra, 0);
8078
rng.fill_bytes(&mut data[cur..]);
8179
}
82-
Err(e) => panic!("failed to generated module: {}", e),
80+
Err(e) => panic!("failed to generated module: {e}"),
8381
}
8482
}
8583
}
@@ -163,7 +161,7 @@ impl State {
163161
// panic.
164162
} else {
165163
std::fs::write("panic.wasm", &wasm).unwrap();
166-
panic!("unknown: {}", e);
164+
panic!("unknown: {e}");
167165
}
168166
}
169167
}
@@ -179,7 +177,7 @@ impl State {
179177
/// Prints summary statistics of how many modules have been instantiated so
180178
/// far and how many of them have oom'd or trap'd.
181179
fn print(&self, total: usize) {
182-
print!("total: {:8}", total);
180+
print!("total: {total:8}");
183181
let stat = |name: &str, stat: &AtomicUsize| {
184182
let stat = stat.load(SeqCst);
185183
if stat > 0 {

crates/wasm-compose/src/encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'a> TypeEncoder<'a> {
364364
EntityType::Function(idx)
365365
}
366366
wasmparser::types::EntityType::Table(ty) => EntityType::Table(ty.try_into().unwrap()),
367-
wasmparser::types::EntityType::Memory(ty) => EntityType::Memory(ty.try_into().unwrap()),
367+
wasmparser::types::EntityType::Memory(ty) => EntityType::Memory(ty.into()),
368368
wasmparser::types::EntityType::Global(ty) => EntityType::Global(ty.try_into().unwrap()),
369369
wasmparser::types::EntityType::Tag(id) => {
370370
let ty = &self.0.types[id];

crates/wasm-compose/tests/compose.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,21 @@ fn component_composing() -> Result<()> {
8080
}
8181
} else {
8282
let bytes =
83-
r.with_context(|| format!("failed to encode for test case `{}`", test_case))?;
83+
r.with_context(|| format!("failed to encode for test case `{test_case}`"))?;
8484

8585
Validator::new_with_features(WasmFeatures::default() | WasmFeatures::COMPONENT_MODEL)
8686
.validate_all(&bytes)
8787
.with_context(|| {
88-
format!(
89-
"failed to validate component bytes for test case `{}`",
90-
test_case
91-
)
88+
format!("failed to validate component bytes for test case `{test_case}`")
9289
})?;
9390

9491
wit_component::decode(&bytes).with_context(|| {
95-
format!(
96-
"failed to decode WIT from component bytes for test case `{}`",
97-
test_case
98-
)
92+
format!("failed to decode WIT from component bytes for test case `{test_case}`")
9993
})?;
10094

10195
(
10296
wasmprinter::print_bytes(&bytes).with_context(|| {
103-
format!(
104-
"failed to print component bytes for test case `{}`",
105-
test_case
106-
)
97+
format!("failed to print component bytes for test case `{test_case}`")
10798
})?,
10899
&output_path,
109100
)

crates/wasm-metadata/src/dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Display for Dependencies {
7474
// encoded as utf8, even if we internally store it as [u8].
7575
// let data = String::from_utf8(self.0.data.to_vec()).unwrap();
7676
let data = serde_json::to_string(&self.version_info).unwrap();
77-
write!(f, "{}", data)
77+
write!(f, "{data}")
7878
}
7979
}
8080

crates/wasm-mutate-stats/src/bin/wasm-mutate-stats.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ fn parse_optimization_types(s: &str) -> Result<OptLevel, ParsingOptLevelError> {
3838
"O2" => Ok(OptLevel::Speed),
3939
"Os" => Ok(OptLevel::SpeedAndSize),
4040
_ => Err(ParsingOptLevelError::Parsing(format!(
41-
"Invalid optimization type {}",
42-
s
41+
"Invalid optimization type {s}"
4342
))),
4443
}
4544
}
@@ -207,7 +206,7 @@ impl State {
207206
newfolder.display()
208207
)
209208
})?;
210-
println!("Artifacts saved at {:?}", newfolder);
209+
println!("Artifacts saved at {newfolder:?}");
211210
Ok(newfolder)
212211
})
213212
.collect::<anyhow::Result<Vec<_>>>()?;
@@ -260,7 +259,7 @@ impl State {
260259
format!("File name could not be retrieved for {}", name.display())
261260
})?;
262261

263-
println!("Input wasm \"{:?}\"", filename);
262+
println!("Input wasm \"{filename:?}\"");
264263
let artifacts_folder = self
265264
.get_parent_folders(name.clone())?
266265
.join("artifacts")
@@ -358,7 +357,7 @@ impl State {
358357
) -> anyhow::Result<()> {
359358
let mut hashes = HashMap::new();
360359
//let low_hashes = HashMap::new();
361-
let objfolder = artifact_folder.join("obj").join(format!("{:?}", optlevel));
360+
let objfolder = artifact_folder.join("obj").join(format!("{optlevel:?}"));
362361
let entries = std::fs::read_dir(&objfolder)
363362
.with_context(|| format!("failed to read dir {}", objfolder.display()))?;
364363

@@ -393,7 +392,7 @@ impl State {
393392

394393
fn compile_and_save(&self, worklist: &[PathBuf], artifact_folder: &Path) -> anyhow::Result<()> {
395394
for (_, config) in &self.engines {
396-
let newfolder = artifact_folder.join("obj").join(format!("{:?}", config));
395+
let newfolder = artifact_folder.join("obj").join(format!("{config:?}"));
397396
std::fs::create_dir_all(&newfolder).with_context(|| {
398397
format!(
399398
"Artifacts folder {} could not be created",
@@ -423,8 +422,8 @@ impl State {
423422

424423
let filename = artifact_folder
425424
.join("obj")
426-
.join(format!("{:?}", optlevel))
427-
.join(format!("{}.obj", entryidx));
425+
.join(format!("{optlevel:?}"))
426+
.join(format!("{entryidx}.obj"));
428427
std::fs::write(&filename, &obj)
429428
.context("Aot file could be written to filesystem")?;
430429
}
@@ -456,15 +455,15 @@ impl State {
456455
while !finish_writing_wrap_clone.load(Relaxed) {
457456
// pop from worklist
458457
if let Some(wasm) = to_write_clone.lock().unwrap().pop() {
459-
let filename = artifact_folder_cp.join(format!("mutated.{}.wasm", counter));
458+
let filename = artifact_folder_cp.join(format!("mutated.{counter}.wasm"));
460459
std::fs::write(filename, &wasm).context("Failed to write mutated wasm")?;
461460
counter += 1;
462461
}
463462
}
464463
eprintln!("Writing down pending mutated binaries!");
465464
// Then write pending wasms
466465
while let Some(wasm) = to_write_clone.lock().unwrap().pop() {
467-
let filename = artifact_folder_cp.join(format!("mutated.{}.wasm", counter));
466+
let filename = artifact_folder_cp.join(format!("mutated.{counter}.wasm"));
468467

469468
std::fs::write(filename, &wasm).context("Failed to write mutated wasm")?;
470469
counter += 1;
@@ -493,12 +492,12 @@ impl State {
493492
let data_clone = wasm.clone();
494493
panic::set_hook(Box::new(move |panic_info| {
495494
// invoke the default handler and exit the process
496-
println!("Internal unhandled panic:\n{:?}!", panic_info);
495+
println!("Internal unhandled panic:\n{panic_info:?}!");
497496
// stop generator
498497
finish_writing_wrap_clone2.store(true, SeqCst);
499498
// report current crash
500499
if let Err(e) = self_clone.save_crash(&data_clone, None, seed, &artifact_clone) {
501-
eprintln!("Failed to save crash: {}", e);
500+
eprintln!("Failed to save crash: {e}");
502501
}
503502
process::exit(1);
504503
}));
@@ -578,14 +577,14 @@ impl State {
578577
format!("Crash folder could not be created {}", newfolder.display())
579578
})?;
580579

581-
let newfile = newfolder.join(format!("{}.original.wasm", seed));
580+
let newfile = newfolder.join(format!("{seed}.original.wasm"));
582581

583582
std::fs::write(&newfile, wasm)?;
584583

585584
// Saving the mutation if one
586585

587586
if let Some(mutated) = mutated {
588-
let newfile = newfolder.join(format!("{}.mutated.wasm", seed));
587+
let newfile = newfolder.join(format!("{seed}.mutated.wasm"));
589588
std::fs::write(newfile, mutated)?;
590589
}
591590

crates/wasm-mutate/src/info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a> ModuleInfo<'a> {
6868
loop {
6969
let (payload, consumed) = match parser.parse(wasm, true)? {
7070
Chunk::NeedMoreData(hint) => {
71-
panic!("Invalid Wasm module {:?}", hint);
71+
panic!("Invalid Wasm module {hint:?}");
7272
}
7373
Chunk::Parsed { consumed, payload } => (payload, consumed),
7474
};

crates/wasm-mutate/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,5 @@ pub(crate) fn validate(bytes: &[u8]) {
334334
drop(std::fs::write("test.wat", &text));
335335
}
336336

337-
panic!("wasm failed to validate: {} (written to test.wasm)", err);
337+
panic!("wasm failed to validate: {err} (written to test.wasm)");
338338
}

crates/wasm-mutate/src/mutators.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl WasmMutate<'_> {
149149
Ok(Some(mutation)) => mutation.unwrap(),
150150
Ok(None) => continue,
151151
Err(e) if matches!(e.kind(), ErrorKind::NoMutationsApplicable) => continue,
152-
Err(e) => panic!("mutation error: {}", e),
152+
Err(e) => panic!("mutation error: {e}"),
153153
};
154154

155155
let mutation_bytes = mutation.finish();
@@ -169,16 +169,12 @@ impl WasmMutate<'_> {
169169
match last_mutation {
170170
Some(mutation) => {
171171
panic!(
172-
"after {} attempts the last mutation:\n{:?}\n\n\
173-
did not match the expected mutation\n{:?}",
174-
attempts, mutation, expected_text
172+
"after {attempts} attempts the last mutation:\n{mutation:?}\n\n\
173+
did not match the expected mutation\n{expected_text:?}"
175174
);
176175
}
177176
None => {
178-
panic!(
179-
"never found any applicable mutations after {} attempts",
180-
attempts
181-
);
177+
panic!("never found any applicable mutations after {attempts} attempts");
182178
}
183179
}
184180
}

0 commit comments

Comments
 (0)