Merge pull request #2254 from youknowone/fix-clippy

Fix nightly clippy
This commit is contained in:
Jeong YunWon
2020-10-01 14:34:59 +09:00
committed by GitHub
10 changed files with 26 additions and 64 deletions

View File

@@ -135,10 +135,12 @@ pub fn from_hex(s: &str) -> Option<f64> {
}
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);
}

View File

@@ -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<O: OutputStream> Compiler<O> {
// a list of expressions on the stack, or a list of tuples.
fn gather_elements(&mut self, elements: &[ast::Expression]) -> CompileResult<bool> {
// 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 {

View File

@@ -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)
}
}

View File

@@ -79,9 +79,5 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
}
fn is_starred(exp: &ast::Expression) -> bool {
if let ast::ExpressionType::Starred { .. } = exp.node {
true
} else {
false
}
matches!(exp.node, ast::ExpressionType::Starred { .. })
}

View File

@@ -393,23 +393,11 @@ where
/// Test if a digit is of a certain radix.
fn is_digit_of_radix(c: Option<char>, 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,
},

View File

@@ -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 {

View File

@@ -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<PyIntRef>,
len: usize,
) -> std::ops::Range<usize> {
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 {

View File

@@ -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 {

View File

@@ -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()
};

View File

@@ -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")]