Skip to content

Commit d4bda6c

Browse files
committed
Fix some clippy lints that were 'allow'ed
1 parent f5de59a commit d4bda6c

File tree

12 files changed

+28
-49
lines changed

12 files changed

+28
-49
lines changed

compiler/src/symboltable.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ impl SymbolTableBuilder {
741741
Ok(())
742742
}
743743

744-
#[allow(clippy::single_match)]
745744
fn register_name(&mut self, name: &str, role: SymbolUsage) -> SymbolTableResult {
746745
let scope_depth = self.tables.len();
747746
let table = self.tables.last_mut().unwrap();
@@ -777,13 +776,11 @@ impl SymbolTableBuilder {
777776

778777
// Some more checks:
779778
match role {
780-
SymbolUsage::Nonlocal => {
781-
if scope_depth < 2 {
782-
return Err(SymbolTableError {
783-
error: format!("cannot define nonlocal '{}' at top level.", name),
784-
location,
785-
});
786-
}
779+
SymbolUsage::Nonlocal if scope_depth < 2 => {
780+
return Err(SymbolTableError {
781+
error: format!("cannot define nonlocal '{}' at top level.", name),
782+
location,
783+
})
787784
}
788785
_ => {
789786
// Ok!

parser/src/function.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::error::{LexicalError, LexicalErrorType};
66
type ParameterDefs = (Vec<ast::Parameter>, Vec<ast::Expression>);
77
type ParameterDef = (ast::Parameter, Option<ast::Expression>);
88

9-
#[allow(clippy::collapsible_if)]
109
pub fn parse_params(
1110
params: (Vec<ParameterDef>, Vec<ParameterDef>),
1211
) -> Result<ParameterDefs, LexicalError> {
@@ -16,15 +15,13 @@ pub fn parse_params(
1615
let mut try_default = |name: &ast::Parameter, default| {
1716
if let Some(default) = default {
1817
defaults.push(default);
19-
} else {
20-
if !defaults.is_empty() {
21-
// Once we have started with defaults, all remaining arguments must
22-
// have defaults
23-
return Err(LexicalError {
24-
error: LexicalErrorType::DefaultArgumentError,
25-
location: name.location,
26-
});
27-
}
18+
} else if !defaults.is_empty() {
19+
// Once we have started with defaults, all remaining arguments must
20+
// have defaults
21+
return Err(LexicalError {
22+
error: LexicalErrorType::DefaultArgumentError,
23+
location: name.location,
24+
});
2825
}
2926
Ok(())
3027
};

vm/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
//! - Base objects
77
88
// for methods like vm.to_str(), not the typical use of 'to' as a method prefix
9-
#![allow(
10-
clippy::wrong_self_convention,
11-
clippy::let_and_return,
12-
clippy::implicit_hasher
13-
)]
9+
#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)]
1410
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1511
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
1612

vm/src/obj/objcode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ impl PyValue for PyCode {
4545
#[pyimpl]
4646
impl PyCodeRef {
4747
#[pyslot]
48-
#[allow(clippy::new_ret_no_self)]
49-
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
48+
fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
5049
Err(vm.new_type_error("Cannot directly create code object".to_owned()))
5150
}
5251

vm/src/obj/objint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ impl_try_from_object_int!(
118118
(u64, to_u64),
119119
);
120120

121-
#[allow(clippy::collapsible_if)]
122121
fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
123122
if int2.is_negative() {
124123
let v1 = try_float(int1, vm)?;

vm/src/obj/objproperty.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct PropertyArgs {
7373
}
7474

7575
impl SlotDescriptor for PyProperty {
76-
#[allow(clippy::collapsible_if)]
7776
fn descr_get(
7877
vm: &VirtualMachine,
7978
zelf: PyObjectRef,
@@ -83,12 +82,10 @@ impl SlotDescriptor for PyProperty {
8382
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
8483
if vm.is_none(&obj) {
8584
Ok(zelf.into_object())
85+
} else if let Some(getter) = zelf.getter.as_ref() {
86+
vm.invoke(&getter, obj)
8687
} else {
87-
if let Some(getter) = zelf.getter.as_ref() {
88-
vm.invoke(&getter, obj)
89-
} else {
90-
Err(vm.new_attribute_error("unreadable attribute".to_string()))
91-
}
88+
Err(vm.new_attribute_error("unreadable attribute".to_string()))
9289
}
9390
}
9491
}

vm/src/stdlib/imp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef) {
8686

8787
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
8888
let ctx = &vm.ctx;
89-
let module = py_module!(vm, "_imp", {
89+
py_module!(vm, "_imp", {
9090
"extension_suffixes" => ctx.new_function(imp_extension_suffixes),
9191
"acquire_lock" => ctx.new_function(imp_acquire_lock),
9292
"release_lock" => ctx.new_function(imp_release_lock),
@@ -99,7 +99,5 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
9999
"init_frozen" => ctx.new_function(imp_init_frozen),
100100
"is_frozen_package" => ctx.new_function(imp_is_frozen_package),
101101
"_fix_co_filename" => ctx.new_function(imp_fix_co_filename),
102-
});
103-
104-
module
102+
})
105103
}

vm/src/stdlib/io.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
925925
_ => unimplemented!("'a' mode is not yet implemented"),
926926
};
927927

928-
let io_obj = match typ.chars().next().unwrap() {
928+
match typ.chars().next().unwrap() {
929929
// If the mode is text this buffer type is consumed on construction of
930930
// a TextIOWrapper which is subsequently returned.
931931
't' => {
@@ -937,8 +937,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
937937
// For Buffered class construct "raw" IO class e.g. FileIO and pass this into corresponding field
938938
'b' => buffered,
939939
_ => unreachable!(),
940-
};
941-
io_obj
940+
}
942941
}
943942

944943
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/itertools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ impl PyItertoolsTee {
767767
.into_object())
768768
}
769769

770+
// TODO: make tee() a function, rename this class to itertools._tee and make
771+
// teedata a python class
770772
#[pyslot]
771773
#[allow(clippy::new_ret_no_self)]
772774
fn tp_new(

vm/src/stdlib/warnings.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ fn warnings_warn(args: WarnArgs, vm: &VirtualMachine) -> PyResult<()> {
3434

3535
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
3636
let ctx = &vm.ctx;
37-
let module = py_module!(vm, "_warnings", {
37+
py_module!(vm, "_warnings", {
3838
"warn" => ctx.new_function(warnings_warn),
39-
});
40-
41-
module
39+
})
4240
}

vm/src/version.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ fn get_git_timestamp_datetime() -> DateTime<Local> {
102102
let timestamp = timestamp.parse::<u64>().unwrap_or(0);
103103

104104
let datetime = UNIX_EPOCH + Duration::from_secs(timestamp);
105-
let datetime = DateTime::<Local>::from(datetime);
106105

107-
datetime
106+
datetime.into()
108107
}
109108

110109
pub fn get_git_date() -> String {

vm/src/vm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,7 @@ impl VirtualMachine {
768768
self.trace_event(TraceEvent::Return)?;
769769
result
770770
} else if class.has_attr("__call__") {
771-
let result = self.call_method(&callable, "__call__", args);
772-
result
771+
self.call_method(&callable, "__call__", args)
773772
} else {
774773
Err(self.new_type_error(format!(
775774
"'{}' object is not callable",
@@ -783,8 +782,7 @@ impl VirtualMachine {
783782
where
784783
T: Into<PyFuncArgs>,
785784
{
786-
let res = self._invoke(func_ref, args.into());
787-
res
785+
self._invoke(func_ref, args.into())
788786
}
789787

790788
/// Call registered trace function.

0 commit comments

Comments
 (0)