Use if let instead of match.

https://github.com/rust-lang-nursery/rust-clippy/wiki#single_match
This commit is contained in:
Dan Gohman
2017-08-31 11:57:03 -07:00
parent 574031e4d2
commit 5a8d1a9fda
2 changed files with 31 additions and 53 deletions

View File

@@ -147,15 +147,14 @@ impl<'short, 'long, Variable> InstBuilderBase<'short> for FuncInstBuilder<'short
} }
None => { None => {
// branch_destination() doesn't detect jump_tables // branch_destination() doesn't detect jump_tables
match data {
// If jump table we declare all entries successor // If jump table we declare all entries successor
// TODO: not collect with vector? // TODO: not collect with vector?
InstructionData::BranchTable { table, .. } => { if let InstructionData::BranchTable { table, .. } = data {
// Unlike all other jumps/branches, jump tables are // Unlike all other jumps/branches, jump tables are
// capable of having the same successor appear // capable of having the same successor appear
// multiple times. Use a HashSet to deduplicate. // multiple times. Use a HashSet to deduplicate.
let mut unique = HashSet::new(); let mut unique = HashSet::new();
for dest_ebb in self.builder for dest_ebb in self.builder
.func .func
.jump_tables .jump_tables
.get(table) .get(table)
@@ -166,9 +165,6 @@ impl<'short, 'long, Variable> InstBuilderBase<'short> for FuncInstBuilder<'short
.collect::<Vec<Ebb>>() { .collect::<Vec<Ebb>>() {
self.builder.declare_successor(dest_ebb, inst) self.builder.declare_successor(dest_ebb, inst)
} }
}
// If not we do nothing
_ => {}
} }
} }
} }

View File

@@ -169,13 +169,9 @@ pub fn translate_function_body(
let mut func = Function::new(); let mut func = Function::new();
let args_num: usize = sig.argument_types.len(); let args_num: usize = sig.argument_types.len();
func.signature = sig.clone(); func.signature = sig.clone();
match exports { if let Some(ref exports) = *exports {
&None => (), if let Some(name) = exports.get(&function_index) {
&Some(ref exports) => { func.name = FunctionName::new(name.clone());
match exports.get(&function_index) {
None => (),
Some(name) => func.name = FunctionName::new(name.clone()),
}
} }
} }
let mut func_imports = FunctionImports::new(); let mut func_imports = FunctionImports::new();
@@ -359,11 +355,8 @@ fn translate_operator(
***********************************************************************************/ ***********************************************************************************/
Operator::Block { ty } => { Operator::Block { ty } => {
let next = builder.create_ebb(); let next = builder.create_ebb();
match type_to_type(&ty) { if let Ok(ty_cre) = type_to_type(&ty) {
Ok(ty_cre) => { builder.append_ebb_arg(next, ty_cre);
builder.append_ebb_arg(next, ty_cre);
}
Err(_) => {}
} }
control_stack.push(ControlStackFrame::Block { control_stack.push(ControlStackFrame::Block {
destination: next, destination: next,
@@ -375,11 +368,8 @@ fn translate_operator(
Operator::Loop { ty } => { Operator::Loop { ty } => {
let loop_body = builder.create_ebb(); let loop_body = builder.create_ebb();
let next = builder.create_ebb(); let next = builder.create_ebb();
match type_to_type(&ty) { if let Ok(ty_cre) = type_to_type(&ty) {
Ok(ty_cre) => { builder.append_ebb_arg(next, ty_cre);
builder.append_ebb_arg(next, ty_cre);
}
Err(_) => {}
} }
builder.ins().jump(loop_body, &[]); builder.ins().jump(loop_body, &[]);
control_stack.push(ControlStackFrame::Loop { control_stack.push(ControlStackFrame::Loop {
@@ -401,11 +391,8 @@ fn translate_operator(
// and we add nothing; // and we add nothing;
// - either the If have an Else clause, in that case the destination of this jump // - either the If have an Else clause, in that case the destination of this jump
// instruction will be changed later when we translate the Else operator. // instruction will be changed later when we translate the Else operator.
match type_to_type(&ty) { if let Ok(ty_cre) = type_to_type(&ty) {
Ok(ty_cre) => { builder.append_ebb_arg(if_not, ty_cre);
builder.append_ebb_arg(if_not, ty_cre);
}
Err(_) => {}
} }
control_stack.push(ControlStackFrame::If { control_stack.push(ControlStackFrame::If {
destination: if_not, destination: if_not,
@@ -1320,31 +1307,27 @@ fn find_function_import(
exports: &Option<HashMap<FunctionIndex, String>>, exports: &Option<HashMap<FunctionIndex, String>>,
signatures: &[Signature], signatures: &[Signature],
) -> FuncRef { ) -> FuncRef {
match func_imports.functions.get(&index) { if let Some(local_index) = func_imports.functions.get(&index) {
Some(local_index) => return *local_index, return *local_index;
None => {}
} }
// We have to import the function // We have to import the function
let sig_index = functions[index]; let sig_index = functions[index];
match func_imports.signatures.get(&(sig_index as usize)) { if let Some(local_sig_index) = func_imports.signatures.get(&(sig_index as usize)) {
Some(local_sig_index) => { let local_func_index = builder.import_function(ExtFuncData {
let local_func_index = builder.import_function(ExtFuncData { name: match exports {
name: match exports { &None => FunctionName::new(""),
&None => FunctionName::new(""), &Some(ref exports) => {
&Some(ref exports) => { match exports.get(&index) {
match exports.get(&index) { None => FunctionName::new(""),
None => FunctionName::new(""), Some(name) => FunctionName::new(name.clone()),
Some(name) => FunctionName::new(name.clone()),
}
} }
}, }
signature: *local_sig_index, },
}); signature: *local_sig_index,
func_imports.functions.insert(index, local_func_index); });
return local_func_index; func_imports.functions.insert(index, local_func_index);
} return local_func_index;
None => {} }
};
// We have to import the signature // We have to import the signature
let sig_local_index = builder.import_signature(signatures[sig_index as usize].clone()); let sig_local_index = builder.import_signature(signatures[sig_index as usize].clone());
func_imports.signatures.insert( func_imports.signatures.insert(
@@ -1373,9 +1356,8 @@ fn find_signature_import(
func_imports: &mut FunctionImports, func_imports: &mut FunctionImports,
signatures: &[Signature], signatures: &[Signature],
) -> SigRef { ) -> SigRef {
match func_imports.signatures.get(&(sig_index as usize)) { if let Some(local_sig_index) = func_imports.signatures.get(&(sig_index as usize)) {
Some(local_sig_index) => return *local_sig_index, return *local_sig_index;
None => {}
} }
let sig_local_index = builder.import_signature(signatures[sig_index as usize].clone()); let sig_local_index = builder.import_signature(signatures[sig_index as usize].clone());
func_imports.signatures.insert( func_imports.signatures.insert(