Skip to content

Commit

Permalink
CI: enable clippy for workspace tests (#539)
Browse files Browse the repository at this point in the history
* add CI pass to run clippy on the workspace's tests

* apply clippy suggestions (tests)

* apply clippy (nightly) suggestions

* apply more clippy (+nightly) suggestions
  • Loading branch information
Robbepop authored Oct 25, 2022
1 parent 0c65cf4 commit 52c8a0a
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 87 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ jobs:
with:
command: clippy
args: --workspace --no-default-features -- -D warnings
- name: Clippy (tests)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --tests -- -D warnings

coverage:
name: Coverage
Expand Down
2 changes: 1 addition & 1 deletion crates/arena/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl Index for usize {
}
}

const TEST_ENTITIES: &[&'static str] = &["a", "b", "c", "d"];
const TEST_ENTITIES: &[&str] = &["a", "b", "c", "d"];

mod arena {
use super::*;
Expand Down
15 changes: 9 additions & 6 deletions crates/core/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,20 @@ mod tests {

#[test]
fn pages_max() {
assert_eq!(Pages::max(), pages(u16::MAX as u32 + 1));
assert_eq!(Pages::max(), pages(u32::from(u16::MAX) + 1));
}

#[test]
fn pages_new() {
assert_eq!(Pages::new(0), Some(Pages(0)));
assert_eq!(Pages::new(1), Some(Pages(1)));
assert_eq!(Pages::new(1000), Some(Pages(1000)));
assert_eq!(Pages::new(u16::MAX as u32), Some(Pages(u16::MAX as u32)));
assert_eq!(Pages::new(u16::MAX as u32 + 1), Some(Pages::max()));
assert_eq!(Pages::new(u16::MAX as u32 + 2), None);
assert_eq!(
Pages::new(u32::from(u16::MAX)),
Some(Pages(u32::from(u16::MAX)))
);
assert_eq!(Pages::new(u32::from(u16::MAX) + 1), Some(Pages::max()));
assert_eq!(Pages::new(u32::from(u16::MAX) + 2), None);
assert_eq!(Pages::new(u32::MAX), None);
}

Expand Down Expand Up @@ -273,8 +276,8 @@ mod tests {
Some(bytes(n * bytes_per_page))
);
}
assert!(Bytes::new64(Pages(u16::MAX as u32 + 1)).is_some());
assert!(Bytes::new64(Pages(u16::MAX as u32 + 2)).is_none());
assert!(Bytes::new64(Pages(u32::from(u16::MAX) + 1)).is_some());
assert!(Bytes::new64(Pages(u32::from(u16::MAX) + 2)).is_none());
assert!(Bytes::new64(Pages::max()).is_some());
}
}
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/func_builder/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl Display for TranslationError {
match &*self.inner {
TranslationErrorInner::Validate(error) => error.fmt(f),
TranslationErrorInner::UnsupportedBlockType(error) => {
write!(f, "encountered unsupported Wasm block type: {:?}", error)
write!(f, "encountered unsupported Wasm block type: {error:?}")
}
TranslationErrorInner::UnsupportedValueType(error) => {
write!(f, "encountered unsupported Wasm value type: {:?}", error)
write!(f, "encountered unsupported Wasm value type: {error:?}")
}
TranslationErrorInner::DropKeep(error) => error.fmt(f),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/engine/func_builder/locals_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl LocalsRegistry {
}
self.len_registered = self.len_registered.checked_add(amount).unwrap_or_else(|| {
panic!(
"tried to register too many local variables for function: got {}, additional {}",
self.len_registered, amount
"tried to register too many local variables for function: got {}, additional {amount}",
self.len_registered
)
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/func_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<'parser> FuncBuilder<'parser> {
stack_height
.checked_add(len_params_locals)
.and_then(|x| x.checked_sub(local_idx as usize))
.unwrap_or_else(|| panic!("cannot convert local index into local depth: {}", local_idx))
.unwrap_or_else(|| panic!("cannot convert local index into local depth: {local_idx}"))
}

/// Returns the target at the given `depth` together with its [`DropKeep`].
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/func_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ impl FuncTypeRegistry {
let entity_index = self.unwrap_index(func_type.into_inner());
self.func_types
.get(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored function type: {:?}", entity_index))
.unwrap_or_else(|| panic!("failed to resolve stored function type: {entity_index:?}"))
}
}
10 changes: 3 additions & 7 deletions crates/wasmi/src/engine/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn assert_func_body<E>(
(
index,
engine.resolve_inst(func_body, index).unwrap_or_else(|| {
panic!("encountered missing instruction at position {}", index)
panic!("encountered missing instruction at position {index}")
}),
expected,
)
Expand All @@ -57,16 +57,12 @@ fn assert_func_body<E>(
assert_eq!(
actual,
expected,
"encountered instruction mismatch for {} at position {}",
"encountered instruction mismatch for {} at position {index}",
engine.resolve_func_type(func_type, Clone::clone),
index
);
}
if let Some(unexpected) = engine.resolve_inst(func_body, len_expected) {
panic!(
"encountered unexpected instruction at position {}: {:?}",
len_expected, unexpected,
);
panic!("encountered unexpected instruction at position {len_expected}: {unexpected:?}",);
}
}

Expand Down
18 changes: 9 additions & 9 deletions crates/wasmi/src/func_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl Display for FuncType {
write!(f, "fn(")?;
let (params, results) = self.params_results();
if let Some((first, rest)) = params.split_first() {
write!(f, "{}", first)?;
write!(f, "{first}")?;
for param in rest {
write!(f, ", {}", param)?;
write!(f, ", {param}")?;
}
}
write!(f, ")")?;
Expand All @@ -35,9 +35,9 @@ impl Display for FuncType {
if !rest.is_empty() {
write!(f, "(")?;
}
write!(f, "{}", first)?;
write!(f, "{first}")?;
for result in rest {
write!(f, ", {}", result)?;
write!(f, ", {result}")?;
}
if !rest.is_empty() {
write!(f, ")")?;
Expand Down Expand Up @@ -90,13 +90,13 @@ mod tests {
#[test]
fn display_0in_0out() {
let func_type = FuncType::new([], []);
assert_eq!(format!("{}", func_type), String::from("fn()"),);
assert_eq!(format!("{func_type}"), String::from("fn()"),);
}

#[test]
fn display_1in_1out() {
let func_type = FuncType::new([ValueType::I32], [ValueType::I32]);
assert_eq!(format!("{}", func_type), String::from("fn(i32) -> i32"),);
assert_eq!(format!("{func_type}"), String::from("fn(i32) -> i32"),);
}

#[test]
Expand All @@ -111,7 +111,7 @@ mod tests {
[],
);
assert_eq!(
format!("{}", func_type),
format!("{func_type}"),
String::from("fn(i32, i64, f32, f64)"),
);
}
Expand All @@ -128,7 +128,7 @@ mod tests {
],
);
assert_eq!(
format!("{}", func_type),
format!("{func_type}"),
String::from("fn() -> (i32, i64, f32, f64)"),
);
}
Expand All @@ -150,7 +150,7 @@ mod tests {
],
);
assert_eq!(
format!("{}", func_type),
format!("{func_type}"),
String::from("fn(i32, i64, f32, f64) -> (i32, i64, f32, f64)"),
);
}
Expand Down
1 change: 0 additions & 1 deletion crates/wasmi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
clippy::type_repetition_in_bounds,
clippy::inconsistent_struct_constructor,
clippy::default_trait_access,
clippy::map_unwrap_or,
clippy::items_after_statements
)]
#![recursion_limit = "550"]
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmi/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ impl<T> Linker<T> {
fn insert(&mut self, key: ImportKey, item: Extern) -> Result<(), LinkerError> {
match self.definitions.entry(key) {
Entry::Occupied(_) => {
let (module_name, field_name) = self.resolve_import_key(key).unwrap_or_else(|| {
panic!("encountered missing import names for key {:?}", key)
});
let (module_name, field_name) = self
.resolve_import_key(key)
.unwrap_or_else(|| panic!("encountered missing import names for key {key:?}"));
let import_name = ImportName::new(module_name, field_name);
return Err(LinkerError::DuplicateDefinition {
import_name,
Expand Down
8 changes: 2 additions & 6 deletions crates/wasmi/src/module/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum ModuleError {
impl ModuleError {
pub(crate) fn unsupported(definition: impl Debug) -> Self {
Self::Unsupported {
message: format!("{:?}", definition).into(),
message: format!("{definition:?}").into(),
}
}
}
Expand All @@ -34,11 +34,7 @@ impl Display for ModuleError {
ModuleError::Parser(error) => Display::fmt(error, f),
ModuleError::Translation(error) => Display::fmt(error, f),
ModuleError::Unsupported { message } => {
write!(
f,
"encountered unsupported Wasm proposal item: {:?}",
message
)
write!(f, "encountered unsupported Wasm proposal item: {message:?}",)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmi/src/module/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ impl Display for ImportName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let module_name = &*self.module;
if let Some(field_name) = self.field.as_deref() {
write!(f, "{}::{}", module_name, field_name)
write!(f, "{module_name}::{field_name}")
} else {
write!(f, "{}", module_name)
write!(f, "{module_name}")
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions crates/wasmi/src/module/instantiate/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ impl Display for InstantiationError {
),
Self::ImportsExternalsMismatch { expected, actual } => write!(
f,
"expected {:?} external for import but found {:?}",
expected, actual
"expected {expected:?} external for import but found {actual:?}",
),
Self::SignatureMismatch { expected, actual } => {
write!(
f,
"expected {:?} function signature but found {:?}",
expected, actual
"expected {expected:?} function signature but found {actual:?}",
)
}
Self::ElementSegmentDoesNotFit {
Expand All @@ -79,11 +77,10 @@ impl Display for InstantiationError {
amount,
} => write!(
f,
"table {:?} does not fit {} elements starting from offset {}",
table, offset, amount,
"table {table:?} does not fit {offset} elements starting from offset {amount}",
),
Self::FoundStartFn { index } => {
write!(f, "found an unexpected start function with index {}", index)
write!(f, "found an unexpected start function with index {index}")
}
Self::Table(error) => Display::fmt(error, f),
Self::Memory(error) => Display::fmt(error, f),
Expand Down
8 changes: 4 additions & 4 deletions crates/wasmi/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,25 @@ impl<'a> Iterator for ModuleImportsIter<'a> {
Some(imported) => match imported {
Imported::Func(name) => {
let func_type = self.funcs.next().unwrap_or_else(|| {
panic!("unexpected missing imported function for {:?}", name)
panic!("unexpected missing imported function for {name:?}")
});
ModuleImport::new(name, *func_type)
}
Imported::Table(name) => {
let table_type = self.tables.next().unwrap_or_else(|| {
panic!("unexpected missing imported table for {:?}", name)
panic!("unexpected missing imported table for {name:?}")
});
ModuleImport::new(name, *table_type)
}
Imported::Memory(name) => {
let memory_type = self.memories.next().unwrap_or_else(|| {
panic!("unexpected missing imported linear memory for {:?}", name)
panic!("unexpected missing imported linear memory for {name:?}")
});
ModuleImport::new(name, *memory_type)
}
Imported::Global(name) => {
let global_type = self.globals.next().unwrap_or_else(|| {
panic!("unexpected missing imported global variable for {:?}", name)
panic!("unexpected missing imported global variable for {name:?}")
});
ModuleImport::new(name, *global_type)
}
Expand Down
15 changes: 8 additions & 7 deletions crates/wasmi/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<T> Store<T> {
let entity_index = self.unwrap_index(table.into_inner());
self.tables
.get(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored table: {:?}", entity_index))
.unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}"))
}

/// Returns an exclusive reference to the associated entity of the table.
Expand All @@ -269,7 +269,7 @@ impl<T> Store<T> {
let entity_index = self.unwrap_index(table.into_inner());
self.tables
.get_mut(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored table: {:?}", entity_index))
.unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}"))
}

/// Returns a shared reference to the associated entity of the linear memory.
Expand All @@ -282,7 +282,7 @@ impl<T> Store<T> {
let entity_index = self.unwrap_index(memory.into_inner());
self.memories
.get(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored linear memory: {:?}", entity_index))
.unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}"))
}

/// Returns an exclusive reference to the associated entity of the linear memory.
Expand All @@ -295,7 +295,7 @@ impl<T> Store<T> {
let entity_index = self.unwrap_index(memory.into_inner());
self.memories
.get_mut(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored linear memory: {:?}", entity_index))
.unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}"))
}

/// Returns an exclusive reference to the associated entity of the linear memory and an
Expand All @@ -310,9 +310,10 @@ impl<T> Store<T> {
memory: Memory,
) -> (&mut MemoryEntity, &mut T) {
let entity_index = self.unwrap_index(memory.into_inner());
let memory_entity = self.memories.get_mut(entity_index).unwrap_or_else(|| {
panic!("failed to resolve stored linear memory: {:?}", entity_index)
});
let memory_entity = self
.memories
.get_mut(entity_index)
.unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}"));
(memory_entity, &mut self.user_state)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/tests/e2e/v1/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn static_many_params_works() {
fn setup_many_results() -> (Store<()>, Func) {
let mut store = test_setup();
// Function taking 16 arguments (maximum) and doing nothing.
let func = Func::wrap(&mut store, || ascending_tuple());
let func = Func::wrap(&mut store, ascending_tuple);
(store, func)
}

Expand Down
Loading

0 comments on commit 52c8a0a

Please sign in to comment.