Skip to content

Commit

Permalink
Fix some clippy lints
Browse files Browse the repository at this point in the history
Before:
```
% make lint 2>&1 | grep warnings | sort | uniq
error: could not compile `wasmer-cli` due to previous error; 25 warnings emitted
warning: `compiler-test-derive` (lib) generated 8 warnings
warning: `test-generator` (lib) generated 4 warnings
warning: `wasi-test-generator` (bin "wasi-test-generator") generated 8 warnings
warning: `wasmer-cache` (lib) generated 4 warnings
warning: `wasmer-cli` (lib) generated 25 warnings
warning: `wasmer-compiler-cranelift` (lib) generated 50 warnings
warning: `wasmer-compiler-singlepass` (lib) generated 228 warnings
warning: `wasmer-compiler` (lib) generated 3 warnings
warning: `wasmer-emscripten` (lib) generated 182 warnings
warning: `wasmer-engine-dummy` (lib) generated 6 warnings
warning: `wasmer-engine-dylib` (lib) generated 37 warnings
warning: `wasmer-engine-staticlib` (lib) generated 16 warnings
warning: `wasmer-engine-staticlib` (lib) generated 7 warnings
warning: `wasmer-engine-universal` (lib) generated 11 warnings
warning: `wasmer-engine` (lib) generated 15 warnings
warning: `wasmer-object` (lib) generated 5 warnings
warning: `wasmer-types` (lib) generated 31 warnings
warning: `wasmer-vfs` (lib) generated 4 warnings
warning: `wasmer-vm` (lib) generated 40 warnings
warning: `wasmer-wasi-experimental-io-devices` (lib) generated 11 warnings
warning: `wasmer-wasi-types` (lib) generated 3 warnings
warning: `wasmer-wasi` (lib) generated 13 warnings
warning: `wasmer-wast` (lib) generated 11 warnings
warning: `wasmer` (lib) generated 54 warnings
```

After:
```
warning: `wasmer-cli` (lib) generated 16 warnings
warning: `wasmer-compiler-cranelift` (lib) generated 48 warnings
warning: `wasmer-compiler-singlepass` (lib) generated 213 warnings
warning: `wasmer-emscripten` (lib) generated 170 warnings
warning: `wasmer-engine-dummy` (lib) generated 6 warnings
warning: `wasmer-engine-dylib` (lib) generated 4 warnings
warning: `wasmer-engine-staticlib` (lib) generated 14 warnings
warning: `wasmer-engine-staticlib` (lib) generated 5 warnings
warning: `wasmer-engine-universal` (lib) generated 9 warnings
warning: `wasmer-engine` (lib) generated 12 warnings
warning: `wasmer-object` (lib) generated 3 warnings
warning: `wasmer-types` (lib) generated 7 warnings
warning: `wasmer-vm` (lib) generated 36 warnings
warning: `wasmer-wasi-experimental-io-devices` (lib) generated 6 warnings
warning: `wasmer-wasi-types` (lib) generated 3 warnings
warning: `wasmer-wasi` (lib) generated 9 warnings
warning: `wasmer-wast` (lib) generated 9 warnings
warning: `wasmer` (lib) generated 42 warnings
```
  • Loading branch information
epilys authored and ptitSeb committed Apr 22, 2022
1 parent c12bea5 commit edfd833
Show file tree
Hide file tree
Showing 58 changed files with 245 additions and 269 deletions.
3 changes: 1 addition & 2 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
clippy::float_arithmetic,
clippy::mut_mut,
clippy::nonminimal_bool,
clippy::option_map_unwrap_or,
clippy::option_map_unwrap_or_else,
clippy::map_unwrap_or,
clippy::print_stdout,
clippy::unicode_not_nfc,
clippy::use_self
Expand Down
12 changes: 6 additions & 6 deletions lib/api/src/sys/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Tunables for BaseTunables {
ty: &MemoryType,
style: &MemoryStyle,
) -> Result<Arc<dyn Memory>, MemoryError> {
Ok(Arc::new(LinearMemory::new(&ty, &style)?))
Ok(Arc::new(LinearMemory::new(ty, style)?))
}

/// Create a memory owned by the VM given a [`MemoryType`] and a [`MemoryStyle`].
Expand All @@ -114,8 +114,8 @@ impl Tunables for BaseTunables {
vm_definition_location: NonNull<VMMemoryDefinition>,
) -> Result<Arc<dyn Memory>, MemoryError> {
Ok(Arc::new(LinearMemory::from_definition(
&ty,
&style,
ty,
style,
vm_definition_location,
)?))
}
Expand All @@ -126,7 +126,7 @@ impl Tunables for BaseTunables {
ty: &TableType,
style: &TableStyle,
) -> Result<Arc<dyn Table>, String> {
Ok(Arc::new(LinearTable::new(&ty, &style)?))
Ok(Arc::new(LinearTable::new(ty, style)?))
}

/// Create a table owned by the VM given a [`TableType`] and a [`TableStyle`].
Expand All @@ -141,8 +141,8 @@ impl Tunables for BaseTunables {
vm_definition_location: NonNull<VMTableDefinition>,
) -> Result<Arc<dyn Table>, String> {
Ok(Arc::new(LinearTable::from_definition(
&ty,
&style,
ty,
style,
vm_definition_location,
)?))
}
Expand Down
6 changes: 2 additions & 4 deletions lib/api/src/sys/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ impl ValFuncRef for Val {
}
Ok(match self {
// TODO(reftypes): review this clone
Self::ExternRef(extern_ref) => {
wasmer_vm::TableElement::ExternRef(extern_ref.clone().into())
}
Self::ExternRef(extern_ref) => wasmer_vm::TableElement::ExternRef(extern_ref.clone()),
Self::FuncRef(None) => wasmer_vm::TableElement::FuncRef(VMFuncRef::null()),
Self::FuncRef(Some(f)) => wasmer_vm::TableElement::FuncRef(f.vm_funcref()),
_ => return Err(RuntimeError::new("val is not reference")),
Expand All @@ -108,7 +106,7 @@ impl ValFuncRef for Val {
fn from_table_reference(item: wasmer_vm::TableElement, store: &Store) -> Self {
match item {
wasmer_vm::TableElement::FuncRef(f) => Self::from_vm_funcref(f, store),
wasmer_vm::TableElement::ExternRef(extern_ref) => Self::ExternRef(extern_ref.into()),
wasmer_vm::TableElement::ExternRef(extern_ref) => Self::ExternRef(extern_ref),
}
}
}
26 changes: 12 additions & 14 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
path::{Path, PathBuf},
};

const PRE_HEADER: &'static str = r#"
const PRE_HEADER: &str = r#"
// Define the `ARCH_X86_X64` constant.
#if defined(MSVC) && defined(_M_AMD64)
# define ARCH_X86_64
Expand All @@ -38,19 +38,19 @@ const PRE_HEADER: &'static str = r#"
"#;

#[allow(unused)]
const UNIVERSAL_FEATURE_AS_C_DEFINE: &'static str = "WASMER_UNIVERSAL_ENABLED";
const UNIVERSAL_FEATURE_AS_C_DEFINE: &str = "WASMER_UNIVERSAL_ENABLED";

#[allow(unused)]
const COMPILER_FEATURE_AS_C_DEFINE: &'static str = "WASMER_COMPILER_ENABLED";
const COMPILER_FEATURE_AS_C_DEFINE: &str = "WASMER_COMPILER_ENABLED";

#[allow(unused)]
const WASI_FEATURE_AS_C_DEFINE: &'static str = "WASMER_WASI_ENABLED";
const WASI_FEATURE_AS_C_DEFINE: &str = "WASMER_WASI_ENABLED";

#[allow(unused)]
const MIDDLEWARES_FEATURE_AS_C_DEFINE: &'static str = "WASMER_MIDDLEWARES_ENABLED";
const MIDDLEWARES_FEATURE_AS_C_DEFINE: &str = "WASMER_MIDDLEWARES_ENABLED";

#[allow(unused)]
const EMSCRIPTEN_FEATURE_AS_C_DEFINE: &'static str = "WASMER_EMSCRIPTEN_ENABLED";
const EMSCRIPTEN_FEATURE_AS_C_DEFINE: &str = "WASMER_EMSCRIPTEN_ENABLED";

macro_rules! map_feature_as_c_define {
($feature:expr, $c_define:ident, $accumulator:ident) => {
Expand Down Expand Up @@ -203,7 +203,7 @@ fn add_wasmer_version(pre_header: &mut String) {

/// Create a fresh new `Builder`, already pre-configured.
fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header: &str) -> Builder {
let builder = Builder::new()
Builder::new()
.with_config(cbindgen::Config {
sort_by: cbindgen::SortKey::Name,
cpp_compat: true,
Expand All @@ -219,9 +219,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header:
.with_define("feature", "universal", UNIVERSAL_FEATURE_AS_C_DEFINE)
.with_define("feature", "compiler", COMPILER_FEATURE_AS_C_DEFINE)
.with_define("feature", "wasi", WASI_FEATURE_AS_C_DEFINE)
.with_define("feature", "emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE);

builder
.with_define("feature", "emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE)
}

fn build_inline_c_env_vars() {
Expand Down Expand Up @@ -285,11 +283,11 @@ fn build_cdylib_link_arg() {

match (os.as_str(), env.as_str()) {
("android", _) => {
lines.push(format!("-Wl,-soname,libwasmer.so"));
lines.push("-Wl,-soname,libwasmer.so".to_string());
}

("linux", _) | ("freebsd", _) | ("dragonfly", _) | ("netbsd", _) if env != "musl" => {
lines.push(format!("-Wl,-soname,libwasmer.so"));
lines.push("-Wl,-soname,libwasmer.so".to_string());
}

("macos", _) | ("ios", _) => {
Expand All @@ -305,11 +303,11 @@ fn build_cdylib_link_arg() {
// This is only set up to work on GNU toolchain versions of Rust
lines.push(format!(
"-Wl,--out-implib,{}",
shared_object_dir.join(format!("wasmer.dll.a")).display()
shared_object_dir.join("wasmer.dll.a".to_string()).display()
));
lines.push(format!(
"-Wl,--output-def,{}",
shared_object_dir.join(format!("wasmer.def")).display()
shared_object_dir.join("wasmer.def".to_string()).display()
));
}

Expand Down
4 changes: 0 additions & 4 deletions lib/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ wasmer-engine-dylib = { path = "../engine-dylib", version = "=2.2.1" }
default = ["wasmer/js-serializable-module", "filesystem"]
filesystem = []
blake3-pure = ["blake3/pure"]

[[bench]]
name = "bench_filesystem_cache"
harness = false
2 changes: 1 addition & 1 deletion lib/cache/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Cache for FileSystemCache {
key.to_string()
};
let path = self.path.join(filename);
Module::deserialize_from_file(&store, path)
Module::deserialize_from_file(store, path)
}

fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> {
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Hash {
Self::new(hash.into())
}

pub(crate) fn to_array(&self) -> [u8; 32] {
pub(crate) fn to_array(self) -> [u8; 32] {
self.0
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
clippy::float_arithmetic,
clippy::mut_mut,
clippy::nonminimal_bool,
clippy::option_map_unwrap_or,
clippy::option_map_unwrap_or_else,
clippy::map_unwrap_or,
clippy::print_stdout,
clippy::unicode_not_nfc,
clippy::use_self
Expand Down
46 changes: 27 additions & 19 deletions lib/cli/src/c_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ impl CType {
w.push(' ');
w.push_str("(*)");
w.push('(');
if arguments.len() > 1 {
for arg in &arguments[..arguments.len() - 1] {
arg.generate_c(w);
w.push_str(", ");
match arguments.len() {
l if l > 1 => {
for arg in &arguments[..arguments.len() - 1] {
arg.generate_c(w);
w.push_str(", ");
}
arguments.last().unwrap().generate_c(w);
}
arguments.last().unwrap().generate_c(w);
} else if arguments.len() == 1 {
arguments[0].generate_c(w);
1 => {
arguments[0].generate_c(w);
}
_ => {}
}
w.push(')');
}
Expand All @@ -146,7 +150,7 @@ impl CType {
w.push_str("[]");
}
Self::TypeDef(inner) => {
w.push_str(&inner);
w.push_str(inner);
}
}
}
Expand Down Expand Up @@ -181,23 +185,27 @@ impl CType {
.unwrap_or_default();
ret.generate_c(w);
w.push(' ');
w.push_str(&name);
w.push_str(name);
w.push('(');
if arguments.len() > 1 {
for arg in &arguments[..arguments.len() - 1] {
arg.generate_c(w);
w.push_str(", ");
match arguments.len() {
l if l > 1 => {
for arg in &arguments[..arguments.len() - 1] {
arg.generate_c(w);
w.push_str(", ");
}
arguments.last().unwrap().generate_c(w);
}
arguments.last().unwrap().generate_c(w);
} else if arguments.len() == 1 {
arguments[0].generate_c(w);
1 => {
arguments[0].generate_c(w);
}
_ => {}
}
w.push(')');
}
Self::Array { inner } => {
inner.generate_c(w);
w.push(' ');
w.push_str(&name);
w.push_str(name);
w.push_str("[]");
}
}
Expand Down Expand Up @@ -299,7 +307,7 @@ impl CStatement {
w.push('}');
}
Self::LiteralConstant { value } => {
w.push_str(&value);
w.push_str(value);
}
Self::Cast {
target_type,
Expand All @@ -322,7 +330,7 @@ impl CStatement {
} else {
source_type.generate_c(w);
w.push(' ');
w.push_str(&new_name);
w.push_str(new_name);
}
w.push(';');
w.push('\n');
Expand Down
49 changes: 25 additions & 24 deletions lib/cli/src/c_gen/staticlib_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,32 @@ pub fn generate_header_file(
symbol_registry: &dyn SymbolRegistry,
metadata_length: usize,
) -> String {
let mut c_statements = vec![];
c_statements.push(CStatement::LiteralConstant {
value: "#include <stdlib.h>\n#include <string.h>\n\n".to_string(),
});
c_statements.push(CStatement::LiteralConstant {
value: "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n".to_string(),
});
c_statements.push(CStatement::Declaration {
name: "module_bytes_len".to_string(),
is_extern: false,
is_const: true,
ctype: CType::U32,
definition: Some(Box::new(CStatement::LiteralConstant {
value: metadata_length.to_string(),
})),
});
c_statements.push(CStatement::Declaration {
name: "WASMER_METADATA".to_string(),
is_extern: true,
is_const: true,
ctype: CType::Array {
inner: Box::new(CType::U8),
let mut c_statements = vec![
CStatement::LiteralConstant {
value: "#include <stdlib.h>\n#include <string.h>\n\n".to_string(),
},
definition: None,
});
CStatement::LiteralConstant {
value: "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n".to_string(),
},
CStatement::Declaration {
name: "module_bytes_len".to_string(),
is_extern: false,
is_const: true,
ctype: CType::U32,
definition: Some(Box::new(CStatement::LiteralConstant {
value: metadata_length.to_string(),
})),
},
CStatement::Declaration {
name: "WASMER_METADATA".to_string(),
is_extern: true,
is_const: true,
ctype: CType::Array {
inner: Box::new(CType::U8),
},
definition: None,
},
];
let function_declarations = module_info
.functions
.iter()
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl CreateExe {
.context("Failed to open C source code file")?;
c_src_file.write_all(WASMER_MAIN_C_SOURCE)?;
}
run_c_compile(&c_src_path, &c_src_obj, self.target_triple.clone())
run_c_compile(c_src_path, &c_src_obj, self.target_triple.clone())
.context("Failed to compile C source code")?;
LinkCode {
object_paths: vec![c_src_obj, wasm_object_path],
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Common module with common used structures across different
//! commands.
use crate::common::WasmFeatures;
use anyhow::Result;

#[allow(unused_imports)]
use crate::common::WasmFeatures;
#[allow(unused_imports)]
use std::path::PathBuf;
use std::string::ToString;
#[allow(unused_imports)]
Expand Down
3 changes: 1 addition & 2 deletions lib/compiler-cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
clippy::float_arithmetic,
clippy::mut_mut,
clippy::nonminimal_bool,
clippy::option_map_unwrap_or,
clippy::option_map_unwrap_or_else,
clippy::map_unwrap_or,
clippy::print_stdout,
clippy::unicode_not_nfc,
clippy::use_self
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler-singlepass/src/arm64_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl ArgumentRegisterAllocator {
) -> Option<ARM64Register> {
match calling_convention {
CallingConvention::SystemV | CallingConvention::AppleAarch64 => {
static GPR_SEQ: &'static [GPR] = &[
static GPR_SEQ: &[GPR] = &[
GPR::X0,
GPR::X1,
GPR::X2,
Expand All @@ -266,7 +266,7 @@ impl ArgumentRegisterAllocator {
GPR::X6,
GPR::X7,
];
static NEON_SEQ: &'static [NEON] = &[
static NEON_SEQ: &[NEON] = &[
NEON::V0,
NEON::V1,
NEON::V2,
Expand Down
Loading

0 comments on commit edfd833

Please sign in to comment.