Address all clippy lints

These changes do not change the behaviour of the
code and should be non-controversial.
This commit is contained in:
Alexander Theißen
2020-10-13 13:44:05 +02:00
parent f59eb121e5
commit c09a924a81
18 changed files with 249 additions and 256 deletions
+10 -10
View File
@@ -157,7 +157,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
.get(func_idx as usize)
.ok_or_else(|| Error("Function is not found in func section".into()))?
.type_ref();
let Type::Function(ref func_signature) = *type_section
let Type::Function(func_signature) = type_section
.types()
.get(func_sig_idx as usize)
.ok_or_else(|| Error("Function is not found in func section".into()))?;
@@ -200,10 +200,10 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
let opcode = &instructions.elements()[pc];
trace!(target: "max_height", "{:?}", opcode);
match *opcode {
match opcode {
Nop => {}
Block(ty) | Loop(ty) | If(ty) => {
let end_arity = if ty == BlockType::NoResult { 0 } else { 1 };
let end_arity = if *ty == BlockType::NoResult { 0 } else { 1 };
let branch_arity = if let Loop(_) = *opcode { 0 } else { end_arity };
let height = stack.height();
stack.push_frame(Frame {
@@ -227,7 +227,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
}
Br(target) => {
// Pop values for the destination block result.
let target_arity = stack.frame(target)?.branch_arity;
let target_arity = stack.frame(*target)?.branch_arity;
stack.pop_values(target_arity)?;
// This instruction unconditionally transfers control to the specified block,
@@ -236,7 +236,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
}
BrIf(target) => {
// Pop values for the destination block result.
let target_arity = stack.frame(target)?.branch_arity;
let target_arity = stack.frame(*target)?.branch_arity;
stack.pop_values(target_arity)?;
// Pop condition value.
@@ -245,7 +245,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
// Push values back.
stack.push_values(target_arity)?;
}
BrTable(ref br_table_data) => {
BrTable(br_table_data) => {
let arity_of_default = stack.frame(br_table_data.default)?.branch_arity;
// Check that all jump targets have an equal arities.
@@ -273,7 +273,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
stack.mark_unreachable()?;
}
Call(idx) => {
let ty = resolve_func_type(idx, module)?;
let ty = resolve_func_type(*idx, module)?;
// Pop values for arguments of the function.
stack.pop_values(ty.params().len() as u32)?;
@@ -283,9 +283,9 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
stack.push_values(callee_arity)?;
}
CallIndirect(x, _) => {
let Type::Function(ref ty) = *type_section
let Type::Function(ty) = type_section
.types()
.get(x as usize)
.get(*x as usize)
.ok_or_else(|| Error("Type not found".into()))?;
// Pop the offset into the function table.
@@ -496,7 +496,7 @@ mod tests {
#[test]
fn yet_another_test() {
const SOURCE: &'static str = r#"
const SOURCE: &str = r#"
(module
(memory 0)
(func
+7 -7
View File
@@ -149,7 +149,7 @@ fn generate_stack_height_global(module: &mut elements::Module) -> u32 {
// Try to find an existing global section.
for section in module.sections_mut() {
if let elements::Section::Global(ref mut gs) = *section {
if let elements::Section::Global(gs) = section {
gs.entries_mut().push(global_entry);
return (gs.entries().len() as u32) - 1;
}
@@ -212,7 +212,7 @@ fn compute_stack_cost(func_idx: u32, module: &elements::Module) -> Result<u32, E
fn instrument_functions(ctx: &mut Context, module: &mut elements::Module) -> Result<(), Error> {
for section in module.sections_mut() {
if let elements::Section::Code(ref mut code_section) = *section {
if let elements::Section::Code(code_section) = section {
for func_body in code_section.bodies_mut() {
let opcodes = func_body.code_mut();
instrument_function(ctx, opcodes)?;
@@ -270,8 +270,8 @@ fn instrument_function(
let action: Action = {
let instruction = &instructions.elements()[cursor];
match *instruction {
Call(ref callee_idx) => {
match instruction {
Call(callee_idx) => {
let callee_stack_cost = ctx
.stack_cost(*callee_idx)
.ok_or_else(||
@@ -347,8 +347,8 @@ fn resolve_func_type(
.expect("function import count is not zero; import section must exists; qed")
.entries()
.iter()
.filter_map(|entry| match *entry.external() {
elements::External::Function(ref idx) => Some(*idx),
.filter_map(|entry| match entry.external() {
elements::External::Function(idx) => Some(*idx),
_ => None,
})
.nth(func_idx as usize)
@@ -363,7 +363,7 @@ fn resolve_func_type(
.ok_or_else(|| Error(format!("Function at index {} is not defined", func_idx)))?
.type_ref()
};
let Type::Function(ref ty) = *types.get(sig_idx as usize).ok_or_else(|| {
let Type::Function(ty) = types.get(sig_idx as usize).ok_or_else(|| {
Error(format!(
"Signature {} (specified by func {}) isn't defined",
sig_idx, func_idx
+8 -8
View File
@@ -34,8 +34,8 @@ pub(crate) fn generate_thunks(
let start_func_idx = module
.start_section();
let exported_func_indices = exports.iter().filter_map(|entry| match *entry.internal() {
Internal::Function(ref function_idx) => Some(*function_idx),
let exported_func_indices = exports.iter().filter_map(|entry| match entry.internal() {
Internal::Function(function_idx) => Some(*function_idx),
_ => None,
});
let table_func_indices = elem_segments
@@ -119,7 +119,7 @@ pub(crate) fn generate_thunks(
let fixup = |function_idx: &mut u32| {
// Check whether this function is in replacement_map, since
// we can skip thunk generation (e.g. if stack_cost of function is 0).
if let Some(ref thunk) = replacement_map.get(function_idx) {
if let Some(thunk) = replacement_map.get(function_idx) {
*function_idx = thunk
.idx
.expect("At this point an index must be assigned to each thunk");
@@ -127,22 +127,22 @@ pub(crate) fn generate_thunks(
};
for section in module.sections_mut() {
match *section {
elements::Section::Export(ref mut export_section) => {
match section {
elements::Section::Export(export_section) => {
for entry in export_section.entries_mut() {
if let Internal::Function(ref mut function_idx) = *entry.internal_mut() {
if let Internal::Function(function_idx) = entry.internal_mut() {
fixup(function_idx)
}
}
}
elements::Section::Element(ref mut elem_section) => {
elements::Section::Element(elem_section) => {
for segment in elem_section.entries_mut() {
for function_idx in segment.members_mut() {
fixup(function_idx)
}
}
}
elements::Section::Start(ref mut start_idx) => {
elements::Section::Start(start_idx) => {
fixup(start_idx)
}
_ => {}