Replaced cluttered match statements with if let
@@ -77,20 +77,17 @@ fn _run_string(vm: &mut VirtualMachine, source: &str, source_path: String) -> Py
}
fn handle_exception(vm: &mut VirtualMachine, result: PyResult) {
- match result {
- Ok(_value) => {}
- Err(err) => {
+ if let Err(err) = result {
print_exception(vm, &err);
std::process::exit(1);
}
}
-}
fn run_command(vm: &mut VirtualMachine, mut source: String) -> PyResult {
debug!("Running command {}", source);
// This works around https://github.com/RustPython/RustPython/issues/17
- source.push_str("\n");
+ source.push('\n');
_run_string(vm, &source, "<stdin>".to_string())
}
@@ -116,15 +113,10 @@ fn run_script(vm: &mut VirtualMachine, script_file: &str) -> PyResult {
fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool {
match compile::compile(vm, source, &compile::Mode::Single, "<stdin>".to_string()) {
Ok(code) => {
- match vm.run_code_obj(code, scope) {
- Ok(_value) => {
- // Printed already.
- }
- Err(err) => {
+ if let Err(err) = vm.run_code_obj(code, scope) {
print_exception(vm, &err);
}
}
- }
Err(err) => {
// Enum rather than special string here.
let name = vm.new_str("msg".to_string());
