Skip to content

Commit

Permalink
Fixed linter warnings/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb authored and epilys committed Jun 15, 2022
1 parent b0709e4 commit 0cd9dfe
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 259 deletions.
8 changes: 4 additions & 4 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ static BASIC_WAT: &str = r#"(module
)"#;

pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Criterion) {
let module = Module::new(&store, BASIC_WAT).unwrap();
let module = Module::new(store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new_native(&store, |a: i32, b: i32| a * b),
"multiply" => Function::new_native(store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();
Expand Down Expand Up @@ -93,10 +93,10 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri
}

pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Criterion) {
let module = Module::new(&store, BASIC_WAT).unwrap();
let module = Module::new(store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new_native(&store, |a: i32, b: i32| a * b),
"multiply" => Function::new_native(store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/sys/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ mod test {
"small" => g.clone()
},
"cat" => {
"small" => g.clone()
"small" => g
}
};

Expand Down
28 changes: 14 additions & 14 deletions lib/api/tests/sys_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ mod sys {

let host_fn = |env: &MemEnv| {
let mem = env.memory_ref().unwrap();
assert_eq!(is_memory_instance_ref_strong(&mem), Some(false));
assert_eq!(is_memory_instance_ref_strong(mem), Some(false));
let mem_clone = mem.clone();
assert_eq!(is_memory_instance_ref_strong(&mem_clone), Some(true));
assert_eq!(is_memory_instance_ref_strong(&mem), Some(false));
assert_eq!(is_memory_instance_ref_strong(mem), Some(false));
};

let f: TypedFunction<(), ()> = {
Expand All @@ -136,7 +136,7 @@ mod sys {

{
let mem = instance.exports.get_memory("memory")?;
assert_eq!(is_memory_instance_ref_strong(&mem), Some(true));
assert_eq!(is_memory_instance_ref_strong(mem), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
Expand All @@ -158,10 +158,10 @@ mod sys {

let host_fn = |env: &GlobalEnv| {
let global = env.global_ref().unwrap();
assert_eq!(is_global_instance_ref_strong(&global), Some(false));
assert_eq!(is_global_instance_ref_strong(global), Some(false));
let global_clone = global.clone();
assert_eq!(is_global_instance_ref_strong(&global_clone), Some(true));
assert_eq!(is_global_instance_ref_strong(&global), Some(false));
assert_eq!(is_global_instance_ref_strong(global), Some(false));
};

let f: TypedFunction<(), ()> = {
Expand All @@ -180,7 +180,7 @@ mod sys {

{
let global = instance.exports.get_global("global")?;
assert_eq!(is_global_instance_ref_strong(&global), Some(true));
assert_eq!(is_global_instance_ref_strong(global), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
Expand All @@ -202,10 +202,10 @@ mod sys {

let host_fn = |env: &TableEnv| {
let table = env.table_ref().unwrap();
assert_eq!(is_table_instance_ref_strong(&table), Some(false));
assert_eq!(is_table_instance_ref_strong(table), Some(false));
let table_clone = table.clone();
assert_eq!(is_table_instance_ref_strong(&table_clone), Some(true));
assert_eq!(is_table_instance_ref_strong(&table), Some(false));
assert_eq!(is_table_instance_ref_strong(table), Some(false));
};

let f: TypedFunction<(), ()> = {
Expand All @@ -224,7 +224,7 @@ mod sys {

{
let table = instance.exports.get_table("table")?;
assert_eq!(is_table_instance_ref_strong(&table), Some(true));
assert_eq!(is_table_instance_ref_strong(table), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
Expand All @@ -246,10 +246,10 @@ mod sys {

let host_fn = |env: &FunctionEnv| {
let function = env.call_host_fn_ref().unwrap();
assert_eq!(is_function_instance_ref_strong(&function), Some(false));
assert_eq!(is_function_instance_ref_strong(function), Some(false));
let function_clone = function.clone();
assert_eq!(is_function_instance_ref_strong(&function_clone), Some(true));
assert_eq!(is_function_instance_ref_strong(&function), Some(false));
assert_eq!(is_function_instance_ref_strong(function), Some(false));
};

let f: TypedFunction<(), ()> = {
Expand All @@ -268,7 +268,7 @@ mod sys {

{
let function = instance.exports.get_function("call_host_fn")?;
assert_eq!(is_function_instance_ref_strong(&function), Some(true));
assert_eq!(is_function_instance_ref_strong(function), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
Expand All @@ -291,7 +291,7 @@ mod sys {
let host_fn = |env: &FunctionEnv| {
let function = env.call_host_fn_ref().unwrap();
assert_eq!(
is_native_function_instance_ref_strong(&function),
is_native_function_instance_ref_strong(function),
Some(false)
);
let function_clone = function.clone();
Expand All @@ -300,7 +300,7 @@ mod sys {
Some(true)
);
assert_eq!(
is_native_function_instance_ref_strong(&function),
is_native_function_instance_ref_strong(function),
Some(false)
);
};
Expand Down
15 changes: 7 additions & 8 deletions lib/api/tests/sys_externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod sys {
maximum: Some(1),
};
let f = Function::new_native(&store, |num: i32| num + 1);
let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?;
let table = Table::new(&store, table_type, Value::FuncRef(Some(f)))?;
assert_eq!(*table.ty(), table_type);
let _elem = table.get(0).unwrap();
// assert_eq!(elem.funcref().unwrap(), f);
Expand Down Expand Up @@ -123,7 +123,7 @@ mod sys {
assert!(old_len.is_err());

// Growing to a bigger maximum should return None
let old_len = table.grow(5, Value::FuncRef(Some(f.clone())))?;
let old_len = table.grow(5, Value::FuncRef(Some(f)))?;
assert_eq!(old_len, 0);

Ok(())
Expand Down Expand Up @@ -238,11 +238,10 @@ mod sys {
function.ty().clone(),
FunctionType::new(vec![], vec![Type::I32])
);
let function = Function::new_native_with_env(
&store,
my_env.clone(),
|_env: &MyEnv| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) },
);
let function =
Function::new_native_with_env(&store, my_env, |_env: &MyEnv| -> (i32, i64, f32, f64) {
(1, 2, 3.0, 4.0)
});
assert_eq!(
function.ty().clone(),
FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64])
Expand Down Expand Up @@ -338,7 +337,7 @@ mod sys {
let function = Function::new_with_env(
&store,
function_type,
my_env.clone(),
my_env,
|_env: &MyEnv, _values: &[Value]| unimplemented!(),
);
assert_eq!(function.ty().params(), [Type::V128]);
Expand Down
2 changes: 1 addition & 1 deletion lib/api/tests/sys_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod sys {

fn imported_fn(env: &Env, args: &[Val]) -> Result<Vec<Val>, RuntimeError> {
let value = env.multiplier * args[0].unwrap_i32() as u32;
return Ok(vec![Val::I32(value as _)]);
Ok(vec![Val::I32(value as _)])
}

let imported_signature = FunctionType::new(vec![Type::I32], vec![Type::I32]);
Expand Down
29 changes: 14 additions & 15 deletions lib/c-api/src/wasm_c_api/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::os::raw::c_char;
use std::slice;
use wasmer_api::{Exportable, Extern};
use wasmer_wasi::{
generate_import_object_from_env, get_wasi_version, WasiEnv, WasiFile, WasiState,
WasiStateBuilder, WasiVersion, Pipe,
generate_import_object_from_env, get_wasi_version, Pipe, WasiEnv, WasiFile, WasiState,
WasiStateBuilder, WasiVersion,
};

#[derive(Debug)]
Expand Down Expand Up @@ -172,15 +172,11 @@ pub struct wasi_env_t {
#[no_mangle]
pub extern "C" fn wasi_env_new(mut config: Box<wasi_config_t>) -> Option<Box<wasi_env_t>> {
if !config.inherit_stdout {
config
.state_builder
.stdout(Box::new(Pipe::new()));
config.state_builder.stdout(Box::new(Pipe::new()));
}

if !config.inherit_stderr {
config
.state_builder
.stderr(Box::new(Pipe::new()));
config.state_builder.stderr(Box::new(Pipe::new()));
}

// TODO: impl capturer for stdin
Expand Down Expand Up @@ -210,11 +206,11 @@ pub unsafe extern "C" fn wasi_env_read_stdout(
read_inner(stdout, inner_buffer)
} else {
update_last_error("could not find a file handle for `stdout`");
return -1;
-1
}
} else {
update_last_error("could not find a file handle for `stdout`");
return -1;
-1
}
}

Expand All @@ -231,20 +227,23 @@ pub unsafe extern "C" fn wasi_env_read_stderr(
read_inner(stderr, inner_buffer)
} else {
update_last_error("could not find a file handle for `stderr`");
return -1;
-1
}
} else {
update_last_error("could not find a file handle for `stderr`");
return -1;
}
-1
}
}

fn read_inner(wasi_file: &mut Box<dyn WasiFile + Send + Sync + 'static>, inner_buffer: &mut [u8]) -> isize {
fn read_inner(
wasi_file: &mut Box<dyn WasiFile + Send + Sync + 'static>,
inner_buffer: &mut [u8],
) -> isize {
match wasi_file.read(inner_buffer) {
Ok(a) => a as isize,
Err(err) => {
update_last_error(format!("failed to read wasi_file: {}", err));
-1
-1
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/benches/bench_filesystem_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn load_cache_universal(c: &mut Criterion) {
fs_cache.store(key, &module).unwrap();

c.bench_function("load universal module in filesystem cache", |b| {
b.iter(|| unsafe { fs_cache.load(&store, key.clone()).unwrap() })
b.iter(|| unsafe { fs_cache.load(&store, key).unwrap() })
});
}

Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn load_cache_native(c: &mut Criterion) {
fs_cache.store(key, &module).unwrap();

c.bench_function("load native module in filesystem cache", |b| {
b.iter(|| unsafe { fs_cache.load(&store, key.clone()).unwrap() })
b.iter(|| unsafe { fs_cache.load(&store, key).unwrap() })
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/cli/src/commands/run/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ impl Wasi {

let mut wasi_env = wasi_state_builder.finalize()?;
wasi_env.state.fs.is_wasix.store(
is_wasix_module(&module),
is_wasix_module(module),
std::sync::atomic::Ordering::Release,
);

let import_object = wasi_env.import_object_for_all_wasi_versions(module)?;
let instance = Instance::new(&module, &import_object)?;
let instance = Instance::new(module, &import_object)?;
Ok(instance)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/middlewares/src/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ mod tests {
fn get_remaining_points_works() {
let metering = Arc::new(Metering::new(10, cost_function));
let mut compiler_config = Cranelift::default();
compiler_config.push_middleware(metering.clone());
compiler_config.push_middleware(metering);
let store = Store::new(&Universal::new(compiler_config).engine());
let module = Module::new(&store, bytecode()).unwrap();

Expand Down Expand Up @@ -427,7 +427,7 @@ mod tests {
fn set_remaining_points_works() {
let metering = Arc::new(Metering::new(10, cost_function));
let mut compiler_config = Cranelift::default();
compiler_config.push_middleware(metering.clone());
compiler_config.push_middleware(metering);
let store = Store::new(&Universal::new(compiler_config).engine());
let module = Module::new(&store, bytecode()).unwrap();

Expand Down
2 changes: 2 additions & 0 deletions lib/types/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl MemoryStyle {
/// Trait for the `Memory32` and `Memory64` marker types.
///
/// This allows code to be generic over 32-bit and 64-bit memories.
/// # Safety
/// Direct memory access is unsafe
pub unsafe trait MemorySize: Copy {
/// Type used to represent an offset into a memory. This is `u32` or `u64`.
type Offset: Default
Expand Down
4 changes: 2 additions & 2 deletions lib/vbus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl SpawnOptionsConfig {
}

pub fn remote_instance(&self) -> Option<&str> {
self.remote_instance.as_ref().map(|a| a.as_str())
self.remote_instance.as_deref()
}

pub fn access_token(&self) -> Option<&str> {
self.access_token.as_ref().map(|a| a.as_str())
self.access_token.as_deref()
}
}

Expand Down
15 changes: 9 additions & 6 deletions lib/vfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl From<u32> for FileDescriptor {
}
}

impl Into<u32> for FileDescriptor {
fn into(self) -> u32 {
self.0 as u32
impl From<FileDescriptor> for u32 {
fn from(a: FileDescriptor) -> u32 {
a.0 as u32
}
}

Expand Down Expand Up @@ -162,7 +162,10 @@ impl OpenOptions {
self
}

pub fn open<P: AsRef<Path>>(&mut self, path: P) -> Result<Box<dyn VirtualFile + Send + Sync + 'static>> {
pub fn open<P: AsRef<Path>>(
&mut self,
path: P,
) -> Result<Box<dyn VirtualFile + Send + Sync + 'static>> {
self.opener.open(path.as_ref(), &self.conf)
}
}
Expand Down Expand Up @@ -198,8 +201,8 @@ pub trait VirtualFile: fmt::Debug + Write + Read + Seek + Upcastable {

/// Returns the number of bytes available. This function must not block
fn bytes_available(&self) -> Result<usize> {
return Ok(self.bytes_available_read()?.unwrap_or(0usize)
+ self.bytes_available_write()?.unwrap_or(0usize));
Ok(self.bytes_available_read()?.unwrap_or(0usize)
+ self.bytes_available_write()?.unwrap_or(0usize))
}

/// Returns the number of bytes available. This function must not block
Expand Down
Loading

0 comments on commit 0cd9dfe

Please sign in to comment.