Fix clippy warnings

This commit is contained in:
Jeong YunWon committed 2019-12-21 18:49:48 +09:00
1 parent f3b073a53d
commit c1306726c4
19 files changed
+58 -66

No files matched your search

+2 -4
View File
@@ -1083,9 +1083,7 @@ impl<O: OutputStream> Compiler<O> {
// Doc string value:
self.emit(Instruction::LoadConst {
value: match doc_str {
Some(doc) => bytecode::Constant::String {
value: doc.to_string(),
},
Some(doc) => bytecode::Constant::String { value: doc },
None => bytecode::Constant::None, // set docstring None if not declared
},
});
@@ -2199,7 +2197,7 @@ fn get_doc(body: &[ast::Statement]) -> (&[ast::Statement], Option<String>) {
if let ast::StatementType::Expression { ref expression } = val.node {
if let ast::ExpressionType::String { value } = &expression.node {
if let Some(value) = try_get_constant_string(value) {
return (body_rest, Some(value.to_string()));
return (body_rest, Some(value));
}
}
}
+2 -2
View File
@@ -66,7 +66,7 @@ impl CompilationSource {
})?;
hashmap! {
module_name.clone() => FrozenModule {
code: self.compile_string(&source, mode, module_name.clone())?,
code: self.compile_string(&source, mode, module_name)?,
package: false,
},
}
@@ -74,7 +74,7 @@ impl CompilationSource {
CompilationSourceKind::SourceCode(code) => {
hashmap! {
module_name.clone() => FrozenModule {
code: self.compile_string(code, mode, module_name.clone())?,
code: self.compile_string(code, mode, module_name)?,
package: false,
},
}
+3 -3
View File
@@ -20,7 +20,7 @@ pub fn parse_params(params: Vec<ParameterDef>) -> Result<ParameterDefs, LexicalE
// have defaults
return Err(LexicalError {
error: LexicalErrorType::DefaultArgumentError,
location: name.location.clone(),
location: name.location,
});
}
}
@@ -44,7 +44,7 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
if keyword_names.contains(&keyword_name) {
return Err(LexicalError {
error: LexicalErrorType::DuplicateKeywordArgumentError,
location: value.location.clone(),
location: value.location,
});
}
@@ -58,7 +58,7 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
if !keywords.is_empty() && !is_starred(&value) {
return Err(LexicalError {
error: LexicalErrorType::PositionalArgumentError,
location: value.location.clone(),
location: value.location,
});
}
+20 -18
View File
@@ -33,26 +33,28 @@ impl IndentationLevel {
// We only know for sure that we're smaller or bigger if tabs
// and spaces both differ in the same direction. Otherwise we're
// dependent on the size of tabs.
if self.tabs < other.tabs {
if self.spaces <= other.spaces {
Ok(Ordering::Less)
} else {
Err(LexicalError {
location,
error: LexicalErrorType::TabError,
})
match self.tabs.cmp(&other.tabs) {
Ordering::Less => {
if self.spaces <= other.spaces {
Ok(Ordering::Less)
} else {
Err(LexicalError {
location,
error: LexicalErrorType::TabError,
})
}
}
} else if self.tabs > other.tabs {
if self.spaces >= other.spaces {
Ok(Ordering::Greater)
} else {
Err(LexicalError {
location,
error: LexicalErrorType::TabError,
})
Ordering::Greater => {
if self.spaces >= other.spaces {
Ok(Ordering::Greater)
} else {
Err(LexicalError {
location,
error: LexicalErrorType::TabError,
})
}
}
} else {
Ok(self.spaces.cmp(&other.spaces))
Ordering::Equal => Ok(self.spaces.cmp(&other.spaces)),
}
}
}
+14 -14
View File
@@ -396,13 +396,13 @@ fn builtin_locals(vm: &VirtualMachine) -> PyDictRef {
}
fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
let candidates = if args.args.len() > 1 {
args.args.clone()
} else if args.args.len() == 1 {
vm.extract_elements(&args.args[0])?
} else {
// zero arguments means type error:
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
let candidates = match args.args.len().cmp(&1) {
std::cmp::Ordering::Greater => args.args.clone(),
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
std::cmp::Ordering::Less => {
// zero arguments means type error:
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
}
};
if candidates.is_empty() {
@@ -442,13 +442,13 @@ fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
}
fn builtin_min(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
let candidates = if args.args.len() > 1 {
args.args.clone()
} else if args.args.len() == 1 {
vm.extract_elements(&args.args[0])?
} else {
// zero arguments means type error:
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
let candidates = match args.args.len().cmp(&1) {
std::cmp::Ordering::Greater => args.args.clone(),
std::cmp::Ordering::Equal => vm.extract_elements(&args.args[0])?,
std::cmp::Ordering::Less => {
// zero arguments means type error:
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
}
};
if candidates.is_empty() {
+2 -6
View File
@@ -379,11 +379,7 @@ fn parse_literal(text: &str) -> Result<(CFormatPart, &str, usize), ParsingError>
}
Err(err) => {
if !result_string.is_empty() {
return Ok((
CFormatPart::Literal(result_string.to_string()),
cur_text,
consumed,
));
return Ok((CFormatPart::Literal(result_string), cur_text, consumed));
} else {
return Err((err, consumed));
}
@@ -391,7 +387,7 @@ fn parse_literal(text: &str) -> Result<(CFormatPart, &str, usize), ParsingError>
}
}
Ok((
CFormatPart::Literal(result_string.to_string()),
CFormatPart::Literal(result_string),
"",
text.chars().count(),
))
+1 -1
View File
@@ -500,7 +500,7 @@ impl FormatString {
}
Err(err) => {
if !result_string.is_empty() {
return Ok((FormatPart::Literal(result_string.to_string()), cur_text));
return Ok((FormatPart::Literal(result_string), cur_text));
} else {
return Err(err);
}
+1 -1
View File
@@ -736,7 +736,7 @@ impl Frame {
BlockType::Finally { handler } => {
self.pop_block();
self.push_block(BlockType::FinallyHandler {
reason: Some(reason.clone()),
reason: Some(reason),
});
self.jump(handler);
return Ok(None);
+1 -1
View File
@@ -260,7 +260,7 @@ impl ByteInnerSplitOptions {
-1
};
Ok((sep.clone(), maxsplit))
Ok((sep, maxsplit))
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ impl PyEnumerate {
let iterator = objiter::get_iter(vm, &iterable)?;
PyEnumerate {
counter: RefCell::new(counter.clone()),
counter: RefCell::new(counter),
iterator,
}
.into_ref_with_type(vm, cls)
+1 -1
View File
@@ -85,7 +85,7 @@ impl PyMethod {
}
fn getattribute(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult {
vm.get_attribute(self.function.clone(), name.clone())
vm.get_attribute(self.function.clone(), name)
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ impl PyMap {
mapper: function.clone(),
iterators,
}
.into_ref_with_type(vm, cls.clone())
.into_ref_with_type(vm, cls)
}
#[pymethod(name = "__next__")]
+1 -1
View File
@@ -134,7 +134,7 @@ pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyList> {
)?;
}
let attributes: Vec<_> = dict.into_iter().map(|(k, _v)| k.clone()).collect();
let attributes: Vec<_> = dict.into_iter().map(|(k, _v)| k).collect();
Ok(PyList::from(attributes))
}
+1 -1
View File
@@ -133,7 +133,7 @@ impl PyRange {
fn new(cls: PyClassRef, stop: PyIntRef, vm: &VirtualMachine) -> PyResult<PyRangeRef> {
PyRange {
start: PyInt::new(BigInt::zero()).into_ref(vm),
stop: stop.clone(),
stop,
step: PyInt::new(BigInt::one()).into_ref(vm),
}
.into_ref_with_type(vm, cls)
+3 -7
View File
@@ -221,11 +221,7 @@ impl PySlice {
// Calculate Stop
let mut stop: BigInt;
if vm.is_none(&self.stop(vm)) {
stop = if backwards {
lower.clone()
} else {
upper.clone()
};
stop = if backwards { lower } else { upper };
} else {
let this_stop: PyRef<PyInt> = self.stop(vm).try_into_ref(vm)?;
stop = this_stop.as_bigint().clone();
@@ -234,10 +230,10 @@ impl PySlice {
// From end of array
stop += length;
if stop < lower {
stop = lower.clone();
stop = lower;
}
} else if stop > upper {
stop = upper.clone();
stop = upper;
}
}
+1 -1
View File
@@ -85,7 +85,7 @@ impl PySuper {
) -> PyResult<PySuperRef> {
// Get the type:
let py_type = if let OptionalArg::Present(ty) = py_type {
ty.clone()
ty
} else {
match vm.current_scope().load_cell(vm, "__class__") {
Some(obj) => PyClassRef::try_from_object(vm, obj)?,
+1 -1
View File
@@ -323,7 +323,7 @@ fn type_new_slot(metatype: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) ->
let attributes = dict.to_attributes();
let mut winner = metatype.clone();
let mut winner = metatype;
for base in &bases {
let base_type = base.class();
if issubclass(&winner, &base_type) {
+1 -1
View File
@@ -23,7 +23,7 @@ fn dis_compiler_flag_names(vm: &VirtualMachine) -> PyObjectRef {
for (name, flag) in CodeFlags::NAME_MAPPING {
dict.set_item(
&vm.ctx.new_int(flag.bits()),
vm.ctx.new_str(name.to_string()),
vm.ctx.new_str((*name).to_string()),
vm,
)
.unwrap();
+1 -1
View File
@@ -450,7 +450,7 @@ impl VirtualMachine {
}
pub fn get_locals(&self) -> PyDictRef {
self.current_scope().get_locals().clone()
self.current_scope().get_locals()
}
pub fn context(&self) -> &PyContext {