diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d5aaf6e..2fb5789 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,6 +29,25 @@ jobs: command: fmt args: --all -- --check + clippy: + runs-on: "ubuntu-latest" + steps: + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + + - uses: actions/checkout@v2 + + - name: Cargo clippy + uses: actions-rs/cargo@v1 + with: + toolchain: stable + command: clippy + args: --all-targets --all-features -- -D warnings + test: strategy: matrix: diff --git a/cli/build/main.rs b/cli/build/main.rs index 827487d..81662ec 100644 --- a/cli/build/main.rs +++ b/cli/build/main.rs @@ -130,8 +130,7 @@ fn do_main() -> Result<(), Error> { let mut source_input = source::SourceInput::new(target_dir, wasm_binary); - let source_target_val = - matches.value_of("source_target").unwrap_or_else(|| source::EMSCRIPTEN_TRIPLET); + let source_target_val = matches.value_of("source_target").unwrap_or(source::EMSCRIPTEN_TRIPLET); if source_target_val == source::UNKNOWN_TRIPLET { source_input = source_input.unknown() } else if source_target_val == source::EMSCRIPTEN_TRIPLET { @@ -194,7 +193,7 @@ fn do_main() -> Result<(), Error> { matches.is_present("enforce_stack_adjustment"), matches .value_of("shrink_stack") - .unwrap_or_else(|| "49152") + .unwrap_or("49152") .parse() .expect("New stack size is not valid u32"), matches.is_present("skip_optimization"), diff --git a/src/build.rs b/src/build.rs index 6cdd975..16adcad 100644 --- a/src/build.rs +++ b/src/build.rs @@ -100,8 +100,9 @@ pub fn build( if !skip_optimization { let preserved_exports = match target_runtime { TargetRuntime::PWasm(_) => vec![target_runtime.symbols().create], - TargetRuntime::Substrate(_) => - vec![target_runtime.symbols().call, target_runtime.symbols().create], + TargetRuntime::Substrate(_) => { + vec![target_runtime.symbols().call, target_runtime.symbols().create] + }, }; optimize(&mut ctor_module, preserved_exports)?; } diff --git a/src/gas/validation.rs b/src/gas/validation.rs index 3f7d2f5..7727871 100644 --- a/src/gas/validation.rs +++ b/src/gas/validation.rs @@ -153,8 +153,7 @@ fn build_control_flow_graph( graph.set_first_instr_pos(entry_node_id, 0); - let mut stack = Vec::new(); - stack.push(ControlFrame::new(entry_node_id, terminal_node_id, false)); + let mut stack = vec![ControlFrame::new(entry_node_id, terminal_node_id, false)]; let mut metered_blocks_iter = blocks.iter().peekable(); for (cursor, instruction) in body.code().elements().iter().enumerate() { diff --git a/src/pack.rs b/src/pack.rs index cbed83b..dc6c9cb 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -32,10 +32,12 @@ impl fmt::Display for Error { Error::NoTypeSection => write!(f, "No type section in the module"), Error::NoExportSection => write!(f, "No export section in the module"), Error::NoCodeSection => write!(f, "No code section inthe module"), - Error::InvalidCreateSignature(sym) => - write!(f, "Exported symbol `{}` has invalid signature, should be () -> ()", sym), - Error::InvalidCreateMember(sym) => - write!(f, "Exported symbol `{}` should be a function", sym), + Error::InvalidCreateSignature(sym) => { + write!(f, "Exported symbol `{}` has invalid signature, should be () -> ()", sym) + }, + Error::InvalidCreateMember(sym) => { + write!(f, "Exported symbol `{}` should be a function", sym) + }, Error::NoCreateSymbol(sym) => write!(f, "No exported `{}` symbol", sym), Error::NoImportSection => write!(f, "No import section in the module"), } @@ -285,7 +287,7 @@ mod test { .module("env") .field("memory") .external() - .memory(1 as u32, Some(1 as u32)) + .memory(1, Some(1)) .build() .function() .signature() @@ -336,7 +338,7 @@ mod test { .module("env") .field("memory") .external() - .memory(1 as u32, Some(1 as u32)) + .memory(1, Some(1)) .build() .data() .offset(elements::Instruction::I32Const(16)) diff --git a/src/runtime_type.rs b/src/runtime_type.rs index b274230..f9340f5 100644 --- a/src/runtime_type.rs +++ b/src/runtime_type.rs @@ -46,7 +46,7 @@ mod tests { let mut module = builder::module() .with_global(GlobalEntry::new( GlobalType::new(ValueType::I32, false), - InitExpr::new(vec![Instruction::I32Const(42 as i32)]), + InitExpr::new(vec![Instruction::I32Const(42)]), )) .build(); let mut runtime_type: [u8; 4] = Default::default();