From 17448dab49d133c873dcfe4e7cf8087d2fe9b7c2 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 4 Jan 2024 13:55:32 +0100 Subject: [PATCH 1/4] Use check --all-targets for test in helper --- crates/api-desc/CHANGELOG.md | 1 + crates/api-desc/src/id.rs | 2 +- scripts/test-helper.sh | 15 +++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/api-desc/CHANGELOG.md b/crates/api-desc/CHANGELOG.md index 79249658..12f58f4f 100644 --- a/crates/api-desc/CHANGELOG.md +++ b/crates/api-desc/CHANGELOG.md @@ -19,6 +19,7 @@ ### Patch +- Fix clippy lint - Make sure enum values don't skip any value, essentially mapping to `0..N` - Use `*const void` instead of `*const u8` for opaque data - Update dependencies diff --git a/crates/api-desc/src/id.rs b/crates/api-desc/src/id.rs index 5627563a..768af7af 100644 --- a/crates/api-desc/src/id.rs +++ b/crates/api-desc/src/id.rs @@ -136,7 +136,7 @@ mod tests { fn name_new() { #[track_caller] fn test(expected: Option<&[u8; 6]>, name: &str) { - let expected = expected.map(|x| *x); + let expected = expected.copied(); let actual = Name::new(name).map(|x| x.0); assert_eq!(actual, expected); } diff --git a/scripts/test-helper.sh b/scripts/test-helper.sh index d0449e68..d6983c91 100644 --- a/scripts/test-helper.sh +++ b/scripts/test-helper.sh @@ -37,12 +37,12 @@ ensure_submodule() { } test_helper() { - _test_desc_raw | grep -v -e '^$' -e '^#' -e 'cargo \(check\|test\)' \ + _test_desc | grep -v -e '^$' -e '^#' -e 'cargo \(check\|test\)' \ && e 'Invalid description (invalid commands are listed above).' - _test_desc '\(check\|test\)' check - _test_desc test test + _test_desc | _test_check | grep 'cargo check' | sh -ex + _test_desc | grep 'cargo test' | sh -ex x cargo fmt -- --check - _test_desc '\(check\|test\)' clippy ' -- --deny=warnings' + _test_desc | _test_check | _test_clippy | grep 'cargo clippy' | sh -ex if [ -e src/lib.rs -a "$(package_publish)" = true ]; then features=$(package_doc_features | tr -d '[]" ') [ -n "$features" ] && features="--features=$features" @@ -54,10 +54,9 @@ test_helper() { exit } -_test_desc_raw() { +_test_desc() { sed '0,/^test_helper$/d;:a;/\\$/{N;s/\\\n//;ta};s/ \+/ /g' "$SELF" } -_test_desc() { - _test_desc_raw | sed -n "s/cargo $1/cargo $2/p" | sed "s/\$/$3/" | sh -ex -} +_test_check() { sed 's/cargo test/cargo check --all-targets/'; } +_test_clippy() { sed 's/cargo check/cargo clippy/;s/$/ -- --deny=warnings/'; } From b5f0b2daf61b547841b715665191c27039663d9a Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 4 Jan 2024 14:00:28 +0100 Subject: [PATCH 2/4] Fix lint --- crates/interpreter/tests/spec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/interpreter/tests/spec.rs b/crates/interpreter/tests/spec.rs index 36e89646..2c6336dc 100644 --- a/crates/interpreter/tests/spec.rs +++ b/crates/interpreter/tests/spec.rs @@ -25,7 +25,7 @@ use wast::{parser, QuoteWat, Wast, WastArg, WastDirective, WastExecute, WastInvo fn test(name: &str) { let path = format!("../../third_party/WebAssembly/spec/test/core/{}.wast", name); - let content = std::fs::read_to_string(&path).unwrap(); + let content = std::fs::read_to_string(path).unwrap(); let mut lexer = Lexer::new(&content); lexer.allow_confusing_unicode(true); let buffer = parser::ParseBuffer::new_with_lexer(lexer).unwrap(); @@ -33,7 +33,7 @@ fn test(name: &str) { let layout = std::alloc::Layout::from_size_align(pool_size(name), MEMORY_ALIGN).unwrap(); let pool = unsafe { std::slice::from_raw_parts_mut(std::alloc::alloc(layout), layout.size()) }; let mut env = Env::new(pool); - env.instantiate("spectest", &*SPECTEST); + env.instantiate("spectest", &SPECTEST); env.register_name("spectest", None); assert!(env.inst.is_ok()); for directive in wast.directives { @@ -173,6 +173,7 @@ lazy_static! { static ref SPECTEST: Vec = spectest(); } +#[allow(clippy::vec_init_then_push)] fn spectest() -> Vec { let leb128 = |wasm: &mut Vec, mut x: usize| { assert!(x <= u32::MAX as usize); From 21e928d683dc7695f8d626ff72f1b51f18ddfba6 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 4 Jan 2024 14:12:25 +0100 Subject: [PATCH 3/4] Fix lint --- crates/store/fuzz/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/store/fuzz/src/lib.rs b/crates/store/fuzz/src/lib.rs index 4e5a7e54..eca6d2c1 100644 --- a/crates/store/fuzz/src/lib.rs +++ b/crates/store/fuzz/src/lib.rs @@ -179,6 +179,7 @@ fn read_bits_ok() { assert_eq!(entropy.read_bits(2), 0b10); } +#[allow(clippy::identity_op)] #[test] fn read_range_ok() { let mut entropy = Entropy::new(&[0b00101011]); From 2e7edf974245f25308c3c5d7f0272908da5099a4 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Thu, 4 Jan 2024 14:21:01 +0100 Subject: [PATCH 4/4] Fix lint --- crates/store/CHANGELOG.md | 1 + crates/store/src/file.rs | 10 ++++------ crates/store/tests/store.rs | 14 +++----------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/crates/store/CHANGELOG.md b/crates/store/CHANGELOG.md index c94ed0d1..31c86e42 100644 --- a/crates/store/CHANGELOG.md +++ b/crates/store/CHANGELOG.md @@ -8,6 +8,7 @@ ### Patch +- Fix lints - Fix lints - Update dependencies diff --git a/crates/store/src/file.rs b/crates/store/src/file.rs index 375acbaf..1400fa8c 100644 --- a/crates/store/src/file.rs +++ b/crates/store/src/file.rs @@ -146,14 +146,12 @@ mod tests { tmp_dir.into_path() } - fn remove_tmp_dir(tmp_dir: PathBuf) { + fn remove_tmp_dir(tmp_dir: &Path) { std::fs::remove_dir_all(tmp_dir).unwrap(); } - fn temp_storage(tmp_dir: &PathBuf) -> FileStorage { - let mut tmp_file = tmp_dir.clone(); - tmp_file.push(FILE_NAME); - FileStorage::new(&tmp_file, OPTIONS).unwrap() + fn temp_storage(tmp_dir: &Path) -> FileStorage { + FileStorage::new(&tmp_dir.join(FILE_NAME), OPTIONS).unwrap() } #[test] @@ -175,6 +173,6 @@ mod tests { assert_eq!(file_storage.read_slice(index, 4).unwrap(), DATA_WORD); assert_eq!(file_storage.read_slice(next_index, 4).unwrap(), BLANK_WORD); } - remove_tmp_dir(tmp_dir); + remove_tmp_dir(&tmp_dir); } } diff --git a/crates/store/tests/store.rs b/crates/store/tests/store.rs index 5d5f4cea..5a5f4292 100644 --- a/crates/store/tests/store.rs +++ b/crates/store/tests/store.rs @@ -59,10 +59,7 @@ fn interrupted_overflowing_compaction() { .partial_apply(StoreOperation::Prepare { length: 1 }, StoreInterruption::pure(1)) { Ok((None, d)) => driver = d.power_on().unwrap(), - _ => { - assert!(false); - return; - } + _ => panic!(), } } } @@ -103,15 +100,13 @@ fn full_compaction_with_max_prefix() { // We fill the store with non-deleted entries making sure the last entry always overlaps the // next page with m words for the first 3 pages. - let mut k = 0; - for _ in 0 .. c { + for k in 0 .. c { let tail = get_tail(&driver); if tail % q == q - 1 && tail < 4 * q { driver.insert(k, &vec![0; max_value_len]).unwrap(); } else { driver.insert(k, &[]).unwrap(); } - k += 1; } // We lost 1 word of lifetime because of compacting the first page. check_lifetime(&driver, c + 1); @@ -129,10 +124,7 @@ fn full_compaction_with_max_prefix() { .partial_apply(StoreOperation::Clear { min_key: max_key }, StoreInterruption::pure(1)) { Ok((None, d)) => driver = d.power_on().unwrap(), - _ => { - assert!(false); - return; - } + _ => panic!(), } } check_lifetime(&mut driver, c + n - 1);