diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index 75bbcb3e1..e27ac7118 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -135,10 +135,12 @@ pub fn from_hex(s: &str) -> Option { } for (index, ch) in value.chars().enumerate() { - if ch == 'p' && has_dot { - hex.push_str("p"); - } else if ch == 'p' && !has_dot { - hex.push_str(".p"); + if ch == 'p' { + if has_dot { + hex.push('p'); + } else { + hex.push_str(".p"); + } } else if index >= start { hex.push(ch); } diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index 05d077273..2c04ecc9f 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -61,10 +61,7 @@ enum FunctionContext { impl CompileContext { fn in_func(self) -> bool { - match self.func { - FunctionContext::NoFunction => false, - _ => true, - } + !matches!(self.func, FunctionContext::NoFunction) } } @@ -2006,13 +2003,9 @@ impl Compiler { // a list of expressions on the stack, or a list of tuples. fn gather_elements(&mut self, elements: &[ast::Expression]) -> CompileResult { // First determine if we have starred elements: - let has_stars = elements.iter().any(|e| { - if let ast::ExpressionType::Starred { .. } = &e.node { - true - } else { - false - } - }); + let has_stars = elements + .iter() + .any(|e| matches!(e.node, ast::ExpressionType::Starred { .. })); for element in elements { if let ast::ExpressionType::Starred { value } = &element.node { diff --git a/compiler/src/symboltable.rs b/compiler/src/symboltable.rs index 7d35f7896..4d759f9a0 100644 --- a/compiler/src/symboltable.rs +++ b/compiler/src/symboltable.rs @@ -136,19 +136,11 @@ impl Symbol { } pub fn is_global(&self) -> bool { - if let SymbolScope::Global = self.scope { - true - } else { - false - } + matches!(self.scope, SymbolScope::Global) } pub fn is_local(&self) -> bool { - if let SymbolScope::Local = self.scope { - true - } else { - false - } + matches!(self.scope, SymbolScope::Local) } } diff --git a/parser/src/function.rs b/parser/src/function.rs index d62ea28a2..c47fb10d7 100644 --- a/parser/src/function.rs +++ b/parser/src/function.rs @@ -79,9 +79,5 @@ pub fn parse_args(func_args: Vec) -> Result bool { - if let ast::ExpressionType::Starred { .. } = exp.node { - true - } else { - false - } + matches!(exp.node, ast::ExpressionType::Starred { .. }) } diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 0467a01d3..e5c5c68de 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -393,23 +393,11 @@ where /// Test if a digit is of a certain radix. fn is_digit_of_radix(c: Option, radix: u32) -> bool { match radix { - 2 => match c { - Some('0'..='1') => true, - _ => false, - }, - 8 => match c { - Some('0'..='7') => true, - _ => false, - }, - 10 => match c { - Some('0'..='9') => true, - _ => false, - }, - 16 => match c { - Some('0'..='9') | Some('a'..='f') | Some('A'..='F') => true, - _ => false, - }, - x => unimplemented!("Radix not implemented: {}", x), + 2 => matches!(c, Some('0'..='1')), + 8 => matches!(c, Some('0'..='7')), + 10 => matches!(c, Some('0'..='9')), + 16 => matches!(c, Some('0'..='9') | Some('a'..='f') | Some('A'..='F')), + other => unimplemented!("Radix not implemented: {}", other), } } @@ -417,10 +405,7 @@ where fn at_exponent(&self) -> bool { match self.chr0 { Some('e') | Some('E') => match self.chr1 { - Some('+') | Some('-') => match self.chr2 { - Some('0'..='9') => true, - _ => false, - }, + Some('+') | Some('-') => matches!(self.chr2, Some('0'..='9')), Some('0'..='9') => true, _ => false, }, diff --git a/src/shell.rs b/src/shell.rs index 88f84de0c..06dcdf21f 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -77,7 +77,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> { } else { full_input.push_str(&line); } - full_input.push_str("\n"); + full_input.push('\n'); if continuing { if stop_continuing { diff --git a/vm/src/anystr.rs b/vm/src/anystr.rs index 1e1ecdf4d..15083f9c2 100644 --- a/vm/src/anystr.rs +++ b/vm/src/anystr.rs @@ -78,7 +78,7 @@ impl StartsEndsWithArgs { } } -fn cap_to_isize(py_int: PyIntRef) -> isize { +fn saturate_to_isize(py_int: PyIntRef) -> isize { let big = py_int.borrow_value(); big.to_isize().unwrap_or_else(|| { if big.is_negative() { @@ -95,8 +95,8 @@ pub fn adjust_indices( end: Option, len: usize, ) -> std::ops::Range { - let mut start = start.map_or(0, cap_to_isize); - let mut end = end.map_or(len as isize, cap_to_isize); + let mut start = start.map_or(0, saturate_to_isize); + let mut end = end.map_or(len as isize, saturate_to_isize); if end > len as isize { end = len as isize; } else if end < 0 { diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index ec79b7728..8ed82c3d9 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -378,10 +378,7 @@ enum CFormatPart { impl CFormatPart { fn is_specifier(&self) -> bool { - match self { - CFormatPart::Spec(_) => true, - _ => false, - } + matches!(self, CFormatPart::Spec(_)) } fn has_key(&self) -> bool { diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index 8a9419137..0d319d021 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -146,7 +146,7 @@ impl PySlice { // Each end of the array let lower = if backwards { - -1_i8.to_bigint().unwrap() + (-1_i8).to_bigint().unwrap() } else { Zero::zero() }; diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 311184cca..0826603de 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -226,10 +226,7 @@ mod decl { #[pymethod(name = "is_nonlocal")] fn is_nonlocal(&self) -> bool { - match self.symbol.scope { - symboltable::SymbolScope::Nonlocal => true, - _ => false, - } + matches!(self.symbol.scope, symboltable::SymbolScope::Nonlocal) } #[pymethod(name = "is_referenced")]