Skip to content

Commit

Permalink
chore: Fix clippy lints in API create
Browse files Browse the repository at this point in the history
Fix clippy lints in the API crate.

The fixes are in test code, which is ingored on CI, but the warnings are
annoying when developing.
  • Loading branch information
theduke committed Jan 3, 2024
1 parent 0460050 commit 26e818d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
14 changes: 8 additions & 6 deletions lib/api/src/sys/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ pub struct Instance {
mod send_test {
use super::*;

fn is_send<T: Send>() -> bool {
true
}
// Only here to statically ensure that `Instance` is `Send`.
// Will fail to compile otherwise.
#[allow(dead_code)]
fn instance_is_send(inst: Instance) {
fn is_send(t: impl Send) {
let _ = t;
}

#[test]
fn instance_is_send() {
assert!(is_send::<Instance>());
is_send(inst);
}
}

Expand Down
62 changes: 31 additions & 31 deletions lib/api/tests/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn global_new() -> Result<(), String> {
let mut store = Store::default();
let global = Global::new(&mut store, Value::I32(10));
assert_eq!(
global.ty(&mut store),
global.ty(&store),
GlobalType {
ty: Type::I32,
mutability: Mutability::Const
Expand All @@ -18,7 +18,7 @@ fn global_new() -> Result<(), String> {

let global_mut = Global::new_mut(&mut store, Value::I32(10));
assert_eq!(
global_mut.ty(&mut store),
global_mut.ty(&store),
GlobalType {
ty: Type::I32,
mutability: Mutability::Var
Expand Down Expand Up @@ -86,7 +86,7 @@ fn table_new() -> Result<(), String> {
let f = Function::new_typed(&mut store, || {});
let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f)))
.map_err(|e| format!("{e:?}"))?;
assert_eq!(table.ty(&mut store), table_type);
assert_eq!(table.ty(&store), table_type);

// Anyrefs not yet supported
// let table_type = TableType {
Expand Down Expand Up @@ -170,8 +170,8 @@ fn memory_new() -> Result<(), String> {
maximum: Some(Pages(10)),
};
let memory = Memory::new(&mut store, memory_type).map_err(|e| format!("{e:?}"))?;
assert_eq!(memory.view(&mut store).size(), Pages(0));
assert_eq!(memory.ty(&mut store), memory_type);
assert_eq!(memory.view(&store).size(), Pages(0));
assert_eq!(memory.ty(&store), memory_type);
Ok(())
}

Expand All @@ -180,11 +180,11 @@ fn memory_grow() -> Result<(), String> {
let mut store = Store::default();
let desc = MemoryType::new(Pages(10), Some(Pages(16)), false);
let memory = Memory::new(&mut store, desc).map_err(|e| format!("{e:?}"))?;
assert_eq!(memory.view(&mut store).size(), Pages(10));
assert_eq!(memory.view(&store).size(), Pages(10));

let result = memory.grow(&mut store, Pages(2)).unwrap();
assert_eq!(result, Pages(10));
assert_eq!(memory.view(&mut store).size(), Pages(12));
assert_eq!(memory.view(&store).size(), Pages(12));

let result = memory.grow(&mut store, Pages(10));
assert_eq!(
Expand All @@ -210,25 +210,25 @@ fn memory_grow() -> Result<(), String> {
fn function_new() -> Result<(), String> {
let mut store = Store::default();
let function = Function::new_typed(&mut store, || {});
assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![]));
assert_eq!(function.ty(&store), FunctionType::new(vec![], vec![]));
let function = Function::new_typed(&mut store, |_a: i32| {});
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![Type::I32], vec![])
);
let function = Function::new_typed(&mut store, |_a: i32, _b: i64, _c: f32, _d: f64| {});
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![])
);
let function = Function::new_typed(&mut store, || -> i32 { 1 });
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![], vec![Type::I32])
);
let function = Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) });
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64])
);
Ok(())
Expand All @@ -243,11 +243,11 @@ fn function_new_env() -> Result<(), String> {
let my_env = MyEnv {};
let env = FunctionEnv::new(&mut store, my_env);
let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| {});
assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![]));
assert_eq!(function.ty(&store), FunctionType::new(vec![], vec![]));
let function =
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>, _a: i32| {});
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![Type::I32], vec![])
);
let function = Function::new_typed_with_env(
Expand All @@ -256,13 +256,13 @@ fn function_new_env() -> Result<(), String> {
|_env: FunctionEnvMut<MyEnv>, _a: i32, _b: i64, _c: f32, _d: f64| {},
);
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![])
);
let function =
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| -> i32 { 1 });
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![], vec![Type::I32])
);
let function = Function::new_typed_with_env(
Expand All @@ -271,7 +271,7 @@ fn function_new_env() -> Result<(), String> {
|_env: FunctionEnvMut<MyEnv>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) },
);
assert_eq!(
function.ty(&mut store),
function.ty(&store),
FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64])
);
Ok(())
Expand All @@ -288,35 +288,35 @@ fn function_new_dynamic() -> Result<(), String> {
&function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = Function::new(
&mut store,
&function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = Function::new(
&mut store,
&function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = Function::new(
&mut store,
&function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = Function::new(
&mut store,
&function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);

// Using array signature
let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]);
Expand All @@ -325,9 +325,9 @@ fn function_new_dynamic() -> Result<(), String> {
function_type,
|_values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store).params(), [Type::V128]);
assert_eq!(function.ty(&store).params(), [Type::V128]);
assert_eq!(
function.ty(&mut store).results(),
function.ty(&store).results(),
[Type::I32, Type::F32, Type::F64]
);

Expand All @@ -350,39 +350,39 @@ fn function_new_dynamic_env() -> Result<(), String> {
&function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![Type::I32], vec![]);
let function = Function::new_with_env(
&mut store,
&env,
&function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]);
let function = Function::new_with_env(
&mut store,
&env,
&function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32]);
let function = Function::new_with_env(
&mut store,
&env,
&function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);
let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]);
let function = Function::new_with_env(
&mut store,
&env,
&function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store), function_type);
assert_eq!(function.ty(&store), function_type);

// Using array signature
let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]);
Expand All @@ -392,9 +392,9 @@ fn function_new_dynamic_env() -> Result<(), String> {
function_type,
|_env: FunctionEnvMut<MyEnv>, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty(&mut store).params(), [Type::V128]);
assert_eq!(function.ty(&store).params(), [Type::V128]);
assert_eq!(
function.ty(&mut store).results(),
function.ty(&store).results(),
[Type::I32, Type::F32, Type::F64]
);

Expand Down
2 changes: 1 addition & 1 deletion lib/api/tests/function_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn data_and_store_mut() -> Result<(), String> {
let (mut data, mut storemut) = envmut.data_and_store_mut();

assert_eq!(
data.global.ty(&mut storemut),
data.global.ty(&storemut),
GlobalType {
ty: Type::I32,
mutability: Mutability::Var
Expand Down
5 changes: 2 additions & 3 deletions lib/api/tests/import_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ fn calling_function_exports() -> Result<()> {
};
let instance = Instance::new(&mut store, &module, &imports)?;

let add: TypedFunction<(i32, i32), i32> =
instance.exports.get_typed_function(&mut store, "add")?;
let add: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?;

let result = add.call(&mut store, 10, 20)?;
assert_eq!(result, 30);
Expand Down Expand Up @@ -145,7 +144,7 @@ fn back_and_forth_with_imports() -> Result<()> {
let instance = Instance::new(&mut store, &module, &import_object)?;

let add_one: TypedFunction<i32, i32> =
instance.exports.get_typed_function(&mut store, "add_one")?;
instance.exports.get_typed_function(&store, "add_one")?;
add_one.call(&mut store, 1)?;

Ok(())
Expand Down
16 changes: 8 additions & 8 deletions lib/api/tests/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,35 +233,35 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> {

let f1: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func1")
.get_typed_function(&store, "call_host_func1")
.map_err(|e| format!("{e:?}"))?;
let f2: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func2")
.get_typed_function(&store, "call_host_func2")
.map_err(|e| format!("{e:?}"))?;
let f3: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func3")
.get_typed_function(&store, "call_host_func3")
.map_err(|e| format!("{e:?}"))?;
let f4: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func4")
.get_typed_function(&store, "call_host_func4")
.map_err(|e| format!("{e:?}"))?;
let f5: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func5")
.get_typed_function(&store, "call_host_func5")
.map_err(|e| format!("{e:?}"))?;
let f6: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func6")
.get_typed_function(&store, "call_host_func6")
.map_err(|e| format!("{e:?}"))?;
let f7: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func7")
.get_typed_function(&store, "call_host_func7")
.map_err(|e| format!("{e:?}"))?;
let f8: TypedFunction<(), ()> = instance
.exports
.get_typed_function(&mut store, "call_host_func8")
.get_typed_function(&store, "call_host_func8")
.map_err(|e| format!("{e:?}"))?;

f1.call(&mut store).map_err(|e| format!("{e:?}"))?;
Expand Down
Loading

0 comments on commit 26e818d

Please sign in to comment.