Skip to content

Commit

Permalink
Made clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jun 15, 2022
1 parent 4c68cce commit 0a95f26
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 153 deletions.
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
8 changes: 4 additions & 4 deletions lib/c-api/src/wasm_c_api/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,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 @@ -227,11 +227,11 @@ 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
}
}

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
18 changes: 9 additions & 9 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ impl From<u32> for WasiThreadId {
Self(id)
}
}
impl Into<u32> for WasiThreadId {
fn into(self) -> u32 {
self.0 as u32
impl From<WasiThreadId> for u32 {
fn from(t: WasiThreadId) -> u32 {
t.0 as u32
}
}

Expand All @@ -107,9 +107,9 @@ impl From<u32> for WasiBusProcessId {
Self(id)
}
}
impl Into<u32> for WasiBusProcessId {
fn into(self) -> u32 {
self.0 as u32
impl From<WasiBusProcessId> for u32 {
fn from(id: WasiBusProcessId) -> u32 {
id.0 as u32
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ impl WasiEnv {
}

/// Returns a copy of the current runtime implementation for this environment
pub fn runtime<'a>(&'a self) -> &'a (dyn WasiRuntimeImplementation) {
pub fn runtime(&self) -> &(dyn WasiRuntimeImplementation) {
self.runtime.deref()
}

Expand Down Expand Up @@ -321,12 +321,12 @@ impl WasiEnv {
}

/// Accesses the virtual networking implementation
pub fn net<'a>(&'a self) -> &'a (dyn VirtualNetworking) {
pub fn net(&self) -> &(dyn VirtualNetworking) {
self.runtime.networking()
}

/// Accesses the virtual bus implementation
pub fn bus<'a>(&'a self) -> &'a (dyn VirtualBus) {
pub fn bus(&self) -> &(dyn VirtualBus) {
self.runtime.bus()
}
pub(crate) fn get_memory_and_wasi_state(&self, _mem_index: u32) -> (&Memory, &WasiState) {
Expand Down
14 changes: 7 additions & 7 deletions lib/wasi/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub enum WasiThreadError {
MethodNotFound,
}

impl Into<__wasi_errno_t> for WasiThreadError {
fn into(self) -> __wasi_errno_t {
match self {
impl From<WasiThreadError> for __wasi_errno_t {
fn from(a: WasiThreadError) -> __wasi_errno_t {
match a {
WasiThreadError::Unsupported => __WASI_ENOTSUP,
WasiThreadError::MethodNotFound => __WASI_EINVAL,
}
Expand All @@ -46,11 +46,11 @@ pub trait WasiRuntimeImplementation: fmt::Debug + Sync {
/// which allows runtimes to pass serialized messages between each other similar to
/// RPC's. BUS implementation can be implemented that communicate across runtimes
/// thus creating a distributed computing architecture.
fn bus<'a>(&'a self) -> &'a (dyn VirtualBus);
fn bus(&self) -> &(dyn VirtualBus);

/// Provides access to all the networking related functions such as sockets.
/// By default networking is not implemented.
fn networking<'a>(&'a self) -> &'a (dyn VirtualNetworking);
fn networking(&self) -> &(dyn VirtualNetworking);

/// Generates a new thread ID
fn thread_generate_id(&self) -> WasiThreadId;
Expand Down Expand Up @@ -137,11 +137,11 @@ impl Default for PluggableRuntimeImplementation {
}

impl WasiRuntimeImplementation for PluggableRuntimeImplementation {
fn bus<'a>(&'a self) -> &'a (dyn VirtualBus) {
fn bus(&self) -> &(dyn VirtualBus) {
self.bus.deref()
}

fn networking<'a>(&'a self) -> &'a (dyn VirtualNetworking) {
fn networking(&self) -> &(dyn VirtualNetworking) {
self.networking.deref()
}

Expand Down
23 changes: 9 additions & 14 deletions lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,12 @@ impl WasiFs {
path: &str,
follow_symlinks: bool,
) -> Result<Inode, __wasi_errno_t> {
let start_inode;
if path.starts_with("/") == false && self.is_wasix.load(Ordering::Acquire) {
let start_inode = if !path.starts_with('/') && self.is_wasix.load(Ordering::Acquire) {
let (cur_inode, _) = self.get_current_dir(inodes, base)?;
start_inode = cur_inode;
cur_inode
} else {
start_inode = self.get_fd_inode(base)?;
}
self.get_fd_inode(base)?
};

self.get_inode_at_path_inner(inodes, start_inode, path, 0, follow_symlinks)
}
Expand Down Expand Up @@ -1294,7 +1293,7 @@ impl WasiFs {
fd: __wasi_fd_t,
) -> Result<__wasi_filestat_t, __wasi_errno_t> {
let inode = self.get_fd_inode(fd)?;
Ok(inodes.arena[inode].stat.read().unwrap().deref().clone())
Ok(*inodes.arena[inode].stat.read().unwrap().deref())
}

pub fn fdstat(
Expand Down Expand Up @@ -1390,7 +1389,7 @@ impl WasiFs {
.stdout_mut(&self.fd_map)
.map_err(fs_error_into_wasi_err)?
.as_mut()
.and_then(|f| Some(f.flush().map_err(map_io_err)))
.map(|f| f.flush().map_err(map_io_err))
.unwrap_or_else(|| Err(__WASI_EIO))?,
__WASI_STDERR_FILENO => inodes
.stderr_mut(&self.fd_map)
Expand All @@ -1406,13 +1405,9 @@ impl WasiFs {

let mut guard = inodes.arena[fd.inode].write();
match guard.deref_mut() {
Kind::File { handle, .. } => {
if let Some(file) = handle {
file.flush().map_err(|_| __WASI_EIO)?
} else {
return Err(__WASI_EIO);
}
}
Kind::File {
handle: Some(file), ..
} => file.flush().map_err(|_| __WASI_EIO)?,
// TODO: verify this behavior
Kind::Dir { .. } => return Err(__WASI_EISDIR),
Kind::Symlink { .. } => unimplemented!("WasiFs::flush Kind::Symlink"),
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Read for WasiPipe {
let data = rx.recv().map_err(|_| {
io::Error::new(
io::ErrorKind::BrokenPipe,
format!("the wasi pipe is not connected"),
"the wasi pipe is not connected".to_string(),
)
})?;
self.read_buffer.replace(Bytes::from(data));
Expand Down
Loading

0 comments on commit 0a95f26

Please sign in to comment.