Skip to content

Commit

Permalink
Merge #2062
Browse files Browse the repository at this point in the history
2062: Apply clippy cleanups r=syrusakbary a=nlewycky



Co-authored-by: Nick Lewycky <[email protected]>
  • Loading branch information
bors[bot] and nlewycky authored Jan 27, 2021
2 parents dabc454 + 91d399e commit cfc8f04
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/api/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
Self {
store: other.store,
definition: other.definition,
exported: other.exported.clone(),
exported: other.exported,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/src/translator/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn parse_memory_section(
environ.declare_memory(MemoryType {
minimum: Pages(limits.initial),
maximum: limits.maximum.map(Pages),
shared: shared,
shared,
})?;
}
WPMemoryType::M64 { .. } => unimplemented!("64bit memory not implemented yet"),
Expand Down
3 changes: 1 addition & 2 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,7 @@ pub fn generate_emscripten_env(
// Compatibility with newer versions of Emscripten
let mut to_insert: Vec<(String, _)> = vec![];
for (k, v) in env_ns.iter() {
if k.starts_with('_') {
let k = &k[1..];
if let Some(k) = k.strip_prefix('_') {
if !env_ns.contains(k) {
to_insert.push((k.to_string(), v.clone()));
}
Expand Down
16 changes: 8 additions & 8 deletions lib/engine/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ pub enum Export {
impl From<Export> for VMExport {
fn from(other: Export) -> Self {
match other {
Export::Function(ExportFunction { vm_function, .. }) => VMExport::Function(vm_function),
Export::Memory(ExportMemory { vm_memory }) => VMExport::Memory(vm_memory),
Export::Table(ExportTable { vm_table }) => VMExport::Table(vm_table),
Export::Global(ExportGlobal { vm_global }) => VMExport::Global(vm_global),
Export::Function(ExportFunction { vm_function, .. }) => Self::Function(vm_function),
Export::Memory(ExportMemory { vm_memory }) => Self::Memory(vm_memory),
Export::Table(ExportTable { vm_table }) => Self::Table(vm_table),
Export::Global(ExportGlobal { vm_global }) => Self::Global(vm_global),
}
}
}

impl From<VMExport> for Export {
fn from(other: VMExport) -> Self {
match other {
VMExport::Function(vm_function) => Export::Function(ExportFunction {
VMExport::Function(vm_function) => Self::Function(ExportFunction {
vm_function,
metadata: None,
}),
VMExport::Memory(vm_memory) => Export::Memory(ExportMemory { vm_memory }),
VMExport::Table(vm_table) => Export::Table(ExportTable { vm_table }),
VMExport::Global(vm_global) => Export::Global(ExportGlobal { vm_global }),
VMExport::Memory(vm_memory) => Self::Memory(ExportMemory { vm_memory }),
VMExport::Table(vm_table) => Self::Table(ExportTable { vm_table }),
VMExport::Global(vm_global) => Self::Global(ExportGlobal { vm_global }),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn resolve_imports(
let env = if let Some(ExportFunctionMetadata {
host_env_clone_fn: clone,
..
}) = f.metadata.as_ref().map(|x| &**x)
}) = f.metadata.as_deref()
{
// TODO: maybe start adding asserts in all these
// unsafe blocks to prevent future changes from
Expand Down
8 changes: 3 additions & 5 deletions lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Clone for ImportFunctionEnv {
impl Drop for ImportFunctionEnv {
fn drop(&mut self) {
match self {
ImportFunctionEnv::Env {
Self::Env {
env, destructor, ..
} => {
// # Safety
Expand All @@ -184,7 +184,7 @@ impl Drop for ImportFunctionEnv {
(destructor)(*env);
}
}
ImportFunctionEnv::NoEnv => (),
Self::NoEnv => (),
}
}
}
Expand Down Expand Up @@ -470,9 +470,7 @@ impl Instance {
.memories
.get(memory_index)
.unwrap_or_else(|| panic!("no memory for index {}", memory_index.index()));
let result = mem.grow(delta.into());

result
mem.grow(delta.into())
}

/// Grow imported memory by the specified amount of pages.
Expand Down
4 changes: 2 additions & 2 deletions lib/vm/src/instance/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ impl InstanceRef {

/// Get a reference to the `Instance`.
#[inline]
pub(crate) fn as_ref<'a>(&'a self) -> &'a Instance {
pub(crate) fn as_ref(&self) -> &Instance {
// SAFETY: The pointer is properly aligned, it is
// “dereferencable”, it points to an initialized memory of
// `Instance`, and the reference has the lifetime `'a`.
unsafe { self.instance.as_ref() }
}

#[inline]
pub(super) unsafe fn as_mut<'a>(&'a mut self) -> &'a mut Instance {
pub(super) unsafe fn as_mut(&mut self) -> &mut Instance {
self.instance.as_mut()
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl LinearMemory {
needs_signal_handlers,
vm_memory_definition: if let Some(mem_loc) = vm_memory_location {
{
let mut ptr = mem_loc.clone();
let mut ptr = mem_loc;
let md = ptr.as_mut();
md.base = base_ptr;
md.current_length = mem_length;
Expand All @@ -293,7 +293,7 @@ impl LinearMemory {
/// this function. You can get this by locking the `mmap` mutex.
unsafe fn get_vm_memory_definition(&self) -> NonNull<VMMemoryDefinition> {
match &self.vm_memory_definition {
VMMemoryDefinitionOwnership::VMOwned(ptr) => ptr.clone(),
VMMemoryDefinitionOwnership::VMOwned(ptr) => *ptr,
VMMemoryDefinitionOwnership::HostOwned(boxed_ptr) => {
NonNull::new_unchecked(boxed_ptr.get())
}
Expand Down
4 changes: 2 additions & 2 deletions lib/vm/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl LinearTable {
style: style.clone(),
vm_table_definition: if let Some(table_loc) = vm_table_location {
{
let mut ptr = table_loc.clone();
let mut ptr = table_loc;
let td = ptr.as_mut();
td.base = base as _;
td.current_elements = table_minimum as _;
Expand All @@ -212,7 +212,7 @@ impl LinearTable {
/// this function. You can get this by locking the `vec` mutex.
unsafe fn get_vm_table_definition(&self) -> NonNull<VMTableDefinition> {
match &self.vm_table_definition {
VMTableDefinitionOwnership::VMOwned(ptr) => ptr.clone(),
VMTableDefinitionOwnership::VMOwned(ptr) => *ptr,
VMTableDefinitionOwnership::HostOwned(boxed_ptr) => {
NonNull::new_unchecked(boxed_ptr.get())
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn generate_import_object_from_env(
// fail on Apple Silicon (with Cranelift).
fn get_path_open_for_store(store: &Store, env: WasiEnv) -> Function {
#[cfg(not(all(target_os = "macos", target_arch = "aarch64",)))]
let path_open = Function::new_native_with_env(store, env.clone(), path_open);
let path_open = Function::new_native_with_env(store, env, path_open);
#[cfg(all(target_os = "macos", target_arch = "aarch64",))]
let path_open = Function::new_with_env(
store,
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl WasiStateBuilder {
None => (),
}

if env_value.iter().find(|&&ch| ch == 0).is_some() {
if env_value.iter().any(|&ch| ch == 0) {
return Err(WasiStateCreationError::EnvironmentVariableFormatError(
format!(
"found nul byte in env var value \"{}\" (key=value)",
Expand Down
3 changes: 2 additions & 1 deletion lib/wasi/src/state/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,8 @@ impl WasiFile for Pipe {
self.buffer.len() as u64
}
fn set_len(&mut self, len: u64) -> Result<(), WasiFsError> {
Ok(self.buffer.resize(len as usize, 0))
self.buffer.resize(len as usize, 0);
Ok(())
}
fn unlink(&mut self) -> Result<(), WasiFsError> {
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions lib/wasmer-types/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ impl<T> From<ExternRef> for Value<T> {
// }
// }

const NOT_I32: &'static str = "Value is not of Wasm type i32";
const NOT_I64: &'static str = "Value is not of Wasm type i64";
const NOT_F32: &'static str = "Value is not of Wasm type f32";
const NOT_F64: &'static str = "Value is not of Wasm type f64";
const NOT_I32: &str = "Value is not of Wasm type i32";
const NOT_I64: &str = "Value is not of Wasm type i64";
const NOT_F32: &str = "Value is not of Wasm type f32";
const NOT_F64: &str = "Value is not of Wasm type f64";

impl<T> TryFrom<Value<T>> for i32 {
type Error = &'static str;
Expand Down

0 comments on commit cfc8f04

Please sign in to comment.