Skip to content

Commit 3cd0a11

Browse files
committed
Fix nightly clippy
1 parent 3b2db89 commit 3cd0a11

File tree

10 files changed

+26
-64
lines changed

10 files changed

+26
-64
lines changed

common/src/float_ops.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ pub fn from_hex(s: &str) -> Option<f64> {
135135
}
136136

137137
for (index, ch) in value.chars().enumerate() {
138-
if ch == 'p' && has_dot {
139-
hex.push_str("p");
140-
} else if ch == 'p' && !has_dot {
141-
hex.push_str(".p");
138+
if ch == 'p' {
139+
if has_dot {
140+
hex.push('p');
141+
} else {
142+
hex.push_str(".p");
143+
}
142144
} else if index >= start {
143145
hex.push(ch);
144146
}

compiler/src/compile.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ enum FunctionContext {
6161

6262
impl CompileContext {
6363
fn in_func(self) -> bool {
64-
match self.func {
65-
FunctionContext::NoFunction => false,
66-
_ => true,
67-
}
64+
!matches!(self.func, FunctionContext::NoFunction)
6865
}
6966
}
7067

@@ -2006,13 +2003,9 @@ impl<O: OutputStream> Compiler<O> {
20062003
// a list of expressions on the stack, or a list of tuples.
20072004
fn gather_elements(&mut self, elements: &[ast::Expression]) -> CompileResult<bool> {
20082005
// First determine if we have starred elements:
2009-
let has_stars = elements.iter().any(|e| {
2010-
if let ast::ExpressionType::Starred { .. } = &e.node {
2011-
true
2012-
} else {
2013-
false
2014-
}
2015-
});
2006+
let has_stars = elements
2007+
.iter()
2008+
.any(|e| matches!(e.node, ast::ExpressionType::Starred { .. }));
20162009

20172010
for element in elements {
20182011
if let ast::ExpressionType::Starred { value } = &element.node {

compiler/src/symboltable.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,11 @@ impl Symbol {
136136
}
137137

138138
pub fn is_global(&self) -> bool {
139-
if let SymbolScope::Global = self.scope {
140-
true
141-
} else {
142-
false
143-
}
139+
matches!(self.scope, SymbolScope::Global)
144140
}
145141

146142
pub fn is_local(&self) -> bool {
147-
if let SymbolScope::Local = self.scope {
148-
true
149-
} else {
150-
false
151-
}
143+
matches!(self.scope, SymbolScope::Local)
152144
}
153145
}
154146

parser/src/function.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,5 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
7979
}
8080

8181
fn is_starred(exp: &ast::Expression) -> bool {
82-
if let ast::ExpressionType::Starred { .. } = exp.node {
83-
true
84-
} else {
85-
false
86-
}
82+
matches!(exp.node, ast::ExpressionType::Starred { .. })
8783
}

parser/src/lexer.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -393,34 +393,19 @@ where
393393
/// Test if a digit is of a certain radix.
394394
fn is_digit_of_radix(c: Option<char>, radix: u32) -> bool {
395395
match radix {
396-
2 => match c {
397-
Some('0'..='1') => true,
398-
_ => false,
399-
},
400-
8 => match c {
401-
Some('0'..='7') => true,
402-
_ => false,
403-
},
404-
10 => match c {
405-
Some('0'..='9') => true,
406-
_ => false,
407-
},
408-
16 => match c {
409-
Some('0'..='9') | Some('a'..='f') | Some('A'..='F') => true,
410-
_ => false,
411-
},
412-
x => unimplemented!("Radix not implemented: {}", x),
396+
2 => matches!(c, Some('0'..='1')),
397+
8 => matches!(c, Some('0'..='7')),
398+
10 => matches!(c, Some('0'..='9')),
399+
16 => matches!(c, Some('0'..='9') | Some('a'..='f') | Some('A'..='F')),
400+
other => unimplemented!("Radix not implemented: {}", other),
413401
}
414402
}
415403

416404
/// Test if we face '[eE][-+]?[0-9]+'
417405
fn at_exponent(&self) -> bool {
418406
match self.chr0 {
419407
Some('e') | Some('E') => match self.chr1 {
420-
Some('+') | Some('-') => match self.chr2 {
421-
Some('0'..='9') => true,
422-
_ => false,
423-
},
408+
Some('+') | Some('-') => matches!(self.chr2, Some('0'..='9')),
424409
Some('0'..='9') => true,
425410
_ => false,
426411
},

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
7777
} else {
7878
full_input.push_str(&line);
7979
}
80-
full_input.push_str("\n");
80+
full_input.push('\n');
8181

8282
if continuing {
8383
if stop_continuing {

vm/src/anystr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl StartsEndsWithArgs {
7878
}
7979
}
8080

81-
fn cap_to_isize(py_int: PyIntRef) -> isize {
81+
fn saturate_to_isize(py_int: PyIntRef) -> isize {
8282
let big = py_int.borrow_value();
8383
big.to_isize().unwrap_or_else(|| {
8484
if big.is_negative() {
@@ -95,8 +95,8 @@ pub fn adjust_indices(
9595
end: Option<PyIntRef>,
9696
len: usize,
9797
) -> std::ops::Range<usize> {
98-
let mut start = start.map_or(0, cap_to_isize);
99-
let mut end = end.map_or(len as isize, cap_to_isize);
98+
let mut start = start.map_or(0, saturate_to_isize);
99+
let mut end = end.map_or(len as isize, saturate_to_isize);
100100
if end > len as isize {
101101
end = len as isize;
102102
} else if end < 0 {

vm/src/cformat.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,7 @@ enum CFormatPart {
378378

379379
impl CFormatPart {
380380
fn is_specifier(&self) -> bool {
381-
match self {
382-
CFormatPart::Spec(_) => true,
383-
_ => false,
384-
}
381+
matches!(self, CFormatPart::Spec(_))
385382
}
386383

387384
fn has_key(&self) -> bool {

vm/src/obj/objslice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl PySlice {
146146

147147
// Each end of the array
148148
let lower = if backwards {
149-
-1_i8.to_bigint().unwrap()
149+
(-1_i8).to_bigint().unwrap()
150150
} else {
151151
Zero::zero()
152152
};

vm/src/stdlib/symtable.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ mod decl {
226226

227227
#[pymethod(name = "is_nonlocal")]
228228
fn is_nonlocal(&self) -> bool {
229-
match self.symbol.scope {
230-
symboltable::SymbolScope::Nonlocal => true,
231-
_ => false,
232-
}
229+
matches!(self.symbol.scope, symboltable::SymbolScope::Nonlocal)
233230
}
234231

235232
#[pymethod(name = "is_referenced")]

0 commit comments

Comments
 (0)