Skip to content

Commit 9d5a953

Browse files
Merge pull request RustPython#337 from ZapAnton/fix_unneeded_field_pattern
Fixed the 'unneeded_field_pattern' clippy warnings
2 parents 276b51c + d445e30 commit 9d5a953

File tree

7 files changed

+58
-114
lines changed

7 files changed

+58
-114
lines changed

vm/src/frame.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl Frame {
522522

523523
bytecode::Instruction::Break => {
524524
let block = self.unwind_loop(vm);
525-
if let Block::Loop { start: _, end } = block {
525+
if let Block::Loop { end, .. } = block {
526526
self.jump(end);
527527
}
528528
Ok(None)
@@ -533,7 +533,7 @@ impl Frame {
533533
}
534534
bytecode::Instruction::Continue => {
535535
let block = self.unwind_loop(vm);
536-
if let Block::Loop { start, end: _ } = block {
536+
if let Block::Loop { start, .. } = block {
537537
self.jump(start);
538538
} else {
539539
assert!(false);
@@ -708,8 +708,7 @@ impl Frame {
708708
// TODO: execute finally handler
709709
}
710710
Some(Block::With {
711-
end: _,
712-
context_manager,
711+
context_manager, ..
713712
}) => {
714713
match self.with_exit(vm, &context_manager, None) {
715714
Ok(..) => {}
@@ -728,13 +727,12 @@ impl Frame {
728727
loop {
729728
let block = self.pop_block();
730729
match block {
731-
Some(Block::Loop { start: _, end: __ }) => break block.unwrap(),
730+
Some(Block::Loop { .. }) => break block.unwrap(),
732731
Some(Block::TryExcept { .. }) => {
733732
// TODO: execute finally handler
734733
}
735734
Some(Block::With {
736-
end: _,
737-
context_manager,
735+
context_manager, ..
738736
}) => match self.with_exit(vm, &context_manager, None) {
739737
Ok(..) => {}
740738
Err(exc) => {

vm/src/obj/objsequence.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,10 @@ pub fn get_item(
9090
Err(vm.new_index_error("cannot fit 'int' into an index-sized integer".to_string()))
9191
}
9292
},
93-
PyObjectPayload::Slice {
94-
start: _,
95-
stop: _,
96-
step: _,
97-
} => Ok(PyObject::new(
93+
94+
PyObjectPayload::Slice { .. } => Ok(PyObject::new(
9895
match &(sequence.borrow()).payload {
99-
PyObjectPayload::Sequence { elements: _ } => PyObjectPayload::Sequence {
96+
PyObjectPayload::Sequence { .. } => PyObjectPayload::Sequence {
10097
elements: elements.to_vec().get_slice_items(&subscript),
10198
},
10299
ref payload => panic!("sequence get_item called for non-sequence: {:?}", payload),

vm/src/obj/objstr.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,9 @@ pub fn subscript(vm: &mut VirtualMachine, value: &str, b: PyObjectRef) -> PyResu
10301030
}
10311031
} else {
10321032
match &(*b.borrow()).payload {
1033-
&PyObjectPayload::Slice {
1034-
start: _,
1035-
stop: _,
1036-
step: _,
1037-
} => Ok(vm.new_str(value.to_string().get_slice_items(&b).to_string())),
1033+
&PyObjectPayload::Slice { .. } => {
1034+
Ok(vm.new_str(value.to_string().get_slice_items(&b).to_string()))
1035+
}
10381036
_ => panic!(
10391037
"TypeError: indexing type {:?} with index {:?} is not supported (yet?)",
10401038
value, b

vm/src/obj/objtype.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ pub fn issubclass(typ: &PyObjectRef, cls: &PyObjectRef) -> bool {
8989
}
9090

9191
pub fn get_type_name(typ: &PyObjectRef) -> String {
92-
if let PyObjectPayload::Class {
93-
name,
94-
dict: _,
95-
mro: _,
96-
} = &typ.borrow().payload
97-
{
92+
if let PyObjectPayload::Class { name, .. } = &typ.borrow().payload {
9893
name.clone()
9994
} else {
10095
panic!("Cannot get type_name of non-type type {:?}", typ);
@@ -219,12 +214,7 @@ pub fn get_attributes(obj: &PyObjectRef) -> HashMap<String, PyObjectRef> {
219214
let mut base_classes = objtype::base_classes(obj);
220215
base_classes.reverse();
221216
for bc in base_classes {
222-
if let PyObjectPayload::Class {
223-
name: _,
224-
dict,
225-
mro: _,
226-
} = &bc.borrow().payload
227-
{
217+
if let PyObjectPayload::Class { dict, .. } = &bc.borrow().payload {
228218
let elements = objdict::get_key_value_pairs(dict);
229219
for (name, value) in elements.iter() {
230220
let name = objstr::get_value(name);

vm/src/pyobject.rs

Lines changed: 41 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,11 @@ impl PyContext {
436436
}
437437

438438
pub fn new_tuple(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {
439-
PyObject::new(
440-
PyObjectPayload::Sequence { elements: elements },
441-
self.tuple_type(),
442-
)
439+
PyObject::new(PyObjectPayload::Sequence { elements }, self.tuple_type())
443440
}
444441

445442
pub fn new_list(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {
446-
PyObject::new(
447-
PyObjectPayload::Sequence { elements: elements },
448-
self.list_type(),
449-
)
443+
PyObject::new(PyObjectPayload::Sequence { elements }, self.list_type())
450444
}
451445

452446
pub fn new_set(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {
@@ -469,12 +463,11 @@ impl PyContext {
469463

470464
pub fn new_scope(&self, parent: Option<PyObjectRef>) -> PyObjectRef {
471465
let locals = self.new_dict();
472-
let scope = Scope {
473-
locals: locals,
474-
parent: parent,
475-
};
466+
467+
let scope = Scope { locals, parent };
468+
476469
PyObject {
477-
payload: PyObjectPayload::Scope { scope: scope },
470+
payload: PyObjectPayload::Scope { scope },
478471
typ: None,
479472
}
480473
.into_ref()
@@ -553,10 +546,7 @@ impl PyContext {
553546

554547
pub fn new_bound_method(&self, function: PyObjectRef, object: PyObjectRef) -> PyObjectRef {
555548
PyObject::new(
556-
PyObjectPayload::BoundMethod {
557-
function: function,
558-
object: object,
559-
},
549+
PyObjectPayload::BoundMethod { function, object },
560550
self.bound_method_type(),
561551
)
562552
}
@@ -581,10 +571,7 @@ impl PyContext {
581571
let key = self.new_str(key.to_string());
582572
objdict::set_item_in_content(elements, &key, &v);
583573
}
584-
PyObjectPayload::Module {
585-
name: _,
586-
ref mut dict,
587-
} => self.set_item(dict, key, v),
574+
PyObjectPayload::Module { ref mut dict, .. } => self.set_item(dict, key, v),
588575
PyObjectPayload::Scope { ref mut scope } => {
589576
self.set_item(&scope.locals, key, v);
590577
}
@@ -601,13 +588,9 @@ impl PyContext {
601588

602589
pub fn set_attr(&self, obj: &PyObjectRef, attr_name: &str, value: PyObjectRef) {
603590
match obj.borrow().payload {
604-
PyObjectPayload::Module { name: _, ref dict } => self.set_item(dict, attr_name, value),
591+
PyObjectPayload::Module { ref dict, .. } => self.set_item(dict, attr_name, value),
605592
PyObjectPayload::Instance { ref dict } => self.set_item(dict, attr_name, value),
606-
PyObjectPayload::Class {
607-
name: _,
608-
ref dict,
609-
mro: _,
610-
} => self.set_item(dict, attr_name, value),
593+
PyObjectPayload::Class { ref dict, .. } => self.set_item(dict, attr_name, value),
611594
ref payload => unimplemented!("set_attr unimplemented for: {:?}", payload),
612595
};
613596
}
@@ -732,7 +715,7 @@ impl AttributeProtocol for PyObjectRef {
732715
fn has_attr(&self, attr_name: &str) -> bool {
733716
let obj = self.borrow();
734717
match obj.payload {
735-
PyObjectPayload::Module { name: _, ref dict } => dict.contains_key(attr_name),
718+
PyObjectPayload::Module { ref dict, .. } => dict.contains_key(attr_name),
736719
PyObjectPayload::Class { ref mro, .. } => {
737720
class_has_item(self, attr_name)
738721
|| mro.into_iter().any(|d| class_has_item(d, attr_name))
@@ -755,7 +738,7 @@ impl DictProtocol for PyObjectRef {
755738
PyObjectPayload::Dict { ref elements } => {
756739
objdict::content_contains_key_str(elements, k)
757740
}
758-
PyObjectPayload::Module { name: _, ref dict } => dict.contains_key(k),
741+
PyObjectPayload::Module { ref dict, .. } => dict.contains_key(k),
759742
PyObjectPayload::Scope { ref scope } => scope.locals.contains_key(k),
760743
ref payload => unimplemented!("TODO {:?}", payload),
761744
}
@@ -764,16 +747,16 @@ impl DictProtocol for PyObjectRef {
764747
fn get_item(&self, k: &str) -> Option<PyObjectRef> {
765748
match self.borrow().payload {
766749
PyObjectPayload::Dict { ref elements } => objdict::content_get_key_str(elements, k),
767-
PyObjectPayload::Module { name: _, ref dict } => dict.get_item(k),
750+
PyObjectPayload::Module { ref dict, .. } => dict.get_item(k),
768751
PyObjectPayload::Scope { ref scope } => scope.locals.get_item(k),
769752
_ => panic!("TODO"),
770753
}
771754
}
772755

773756
fn get_key_value_pairs(&self) -> Vec<(PyObjectRef, PyObjectRef)> {
774757
match self.borrow().payload {
775-
PyObjectPayload::Dict { elements: _ } => objdict::get_key_value_pairs(self),
776-
PyObjectPayload::Module { name: _, ref dict } => dict.get_key_value_pairs(),
758+
PyObjectPayload::Dict { .. } => objdict::get_key_value_pairs(self),
759+
PyObjectPayload::Module { ref dict, .. } => dict.get_key_value_pairs(),
777760
PyObjectPayload::Scope { ref scope } => scope.locals.get_key_value_pairs(),
778761
_ => panic!("TODO"),
779762
}
@@ -815,10 +798,7 @@ impl PyFuncArgs {
815798
for name in kwarg_names.iter().rev() {
816799
kwargs.push((name.clone(), args.pop().unwrap()));
817800
}
818-
PyFuncArgs {
819-
args: args,
820-
kwargs: kwargs,
821-
}
801+
PyFuncArgs { args, kwargs }
822802
}
823803

824804
pub fn insert(&self, item: PyObjectRef) -> PyFuncArgs {
@@ -948,37 +928,26 @@ impl fmt::Debug for PyObjectPayload {
948928
PyObjectPayload::Complex { ref value } => write!(f, "complex {}", value),
949929
PyObjectPayload::Bytes { ref value } => write!(f, "bytes/bytearray {:?}", value),
950930
PyObjectPayload::MemoryView { ref obj } => write!(f, "bytes/bytearray {:?}", obj),
951-
PyObjectPayload::Sequence { elements: _ } => write!(f, "list or tuple"),
952-
PyObjectPayload::Dict { elements: _ } => write!(f, "dict"),
953-
PyObjectPayload::Set { elements: _ } => write!(f, "set"),
931+
PyObjectPayload::Sequence { .. } => write!(f, "list or tuple"),
932+
PyObjectPayload::Dict { .. } => write!(f, "dict"),
933+
PyObjectPayload::Set { .. } => write!(f, "set"),
954934
PyObjectPayload::WeakRef { .. } => write!(f, "weakref"),
955-
PyObjectPayload::Iterator {
956-
position: _,
957-
iterated_obj: _,
958-
} => write!(f, "iterator"),
959-
PyObjectPayload::Slice {
960-
start: _,
961-
stop: _,
962-
step: _,
963-
} => write!(f, "slice"),
964-
&PyObjectPayload::Range { range: _ } => write!(f, "range"),
965-
&PyObjectPayload::Code { ref code } => write!(f, "code: {:?}", code),
966-
&PyObjectPayload::Function { .. } => write!(f, "function"),
967-
&PyObjectPayload::Generator { .. } => write!(f, "generator"),
968-
&PyObjectPayload::BoundMethod {
935+
PyObjectPayload::Range { .. } => write!(f, "range"),
936+
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
937+
PyObjectPayload::Slice { .. } => write!(f, "slice"),
938+
PyObjectPayload::Code { ref code } => write!(f, "code: {:?}", code),
939+
PyObjectPayload::Function { .. } => write!(f, "function"),
940+
PyObjectPayload::Generator { .. } => write!(f, "generator"),
941+
PyObjectPayload::BoundMethod {
969942
ref function,
970943
ref object,
971944
} => write!(f, "bound-method: {:?} of {:?}", function, object),
972-
PyObjectPayload::Module { name: _, dict: _ } => write!(f, "module"),
973-
PyObjectPayload::Scope { scope: _ } => write!(f, "scope"),
945+
PyObjectPayload::Module { .. } => write!(f, "module"),
946+
PyObjectPayload::Scope { .. } => write!(f, "scope"),
974947
PyObjectPayload::None => write!(f, "None"),
975-
PyObjectPayload::Class {
976-
ref name,
977-
dict: _,
978-
mro: _,
979-
} => write!(f, "class {:?}", name),
980-
PyObjectPayload::Instance { dict: _ } => write!(f, "instance"),
981-
PyObjectPayload::RustFunction { function: _ } => write!(f, "rust function"),
948+
PyObjectPayload::Class { ref name, .. } => write!(f, "class {:?}", name),
949+
PyObjectPayload::Instance { .. } => write!(f, "instance"),
950+
PyObjectPayload::RustFunction { .. } => write!(f, "rust function"),
982951
PyObjectPayload::Frame { .. } => write!(f, "frame"),
983952
}
984953
}
@@ -1035,16 +1004,17 @@ impl PyObject {
10351004
PyObjectPayload::Class {
10361005
ref name,
10371006
dict: ref _dict,
1038-
mro: _,
1007+
..
10391008
} => format!("<class '{}'>", name),
1040-
PyObjectPayload::Instance { dict: _ } => format!("<instance>"),
1041-
PyObjectPayload::Code { code: _ } => format!("<code>"),
1042-
PyObjectPayload::Function { .. } => format!("<func>"),
1043-
PyObjectPayload::Generator { .. } => format!("<generator>"),
1044-
PyObjectPayload::Frame { .. } => format!("<frame>"),
1045-
PyObjectPayload::BoundMethod { .. } => format!("<bound-method>"),
1046-
PyObjectPayload::RustFunction { function: _ } => format!("<rustfunc>"),
1047-
PyObjectPayload::Module { ref name, dict: _ } => format!("<module '{}'>", name),
1009+
1010+
PyObjectPayload::Instance { .. } => "<instance>".to_string(),
1011+
PyObjectPayload::Code { .. } => "<code>".to_string(),
1012+
PyObjectPayload::Function { .. } => "<func>".to_string(),
1013+
PyObjectPayload::Generator { .. } => "<generator>".to_string(),
1014+
PyObjectPayload::Frame { .. } => "<frame>".to_string(),
1015+
PyObjectPayload::BoundMethod { .. } => "<bound-method>".to_string(),
1016+
PyObjectPayload::RustFunction { .. } => "<rustfunc>".to_string(),
1017+
PyObjectPayload::Module { ref name, .. } => format!("<module '{}'>", name),
10481018
PyObjectPayload::Scope { ref scope } => format!("<scope '{:?}'>", scope),
10491019
PyObjectPayload::Slice {
10501020
ref start,

vm/src/stdlib/ast.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
6464
ast::Statement::ClassDef {
6565
name,
6666
body,
67-
bases: _,
68-
keywords: _,
6967
decorator_list,
68+
..
7069
} => {
7170
let node = create_node(ctx, "ClassDef");
7271

@@ -249,11 +248,7 @@ fn expressions_to_ast(ctx: &PyContext, expressions: &Vec<ast::Expression>) -> Py
249248

250249
fn expression_to_ast(ctx: &PyContext, expression: &ast::Expression) -> PyObjectRef {
251250
let node = match &expression {
252-
ast::Expression::Call {
253-
function,
254-
args,
255-
keywords: _,
256-
} => {
251+
ast::Expression::Call { function, args, .. } => {
257252
let node = create_node(ctx, "Call");
258253

259254
let py_func_ast = expression_to_ast(ctx, function);

vm/src/vm.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl VirtualMachine {
164164
pub fn get_builtin_scope(&mut self) -> PyObjectRef {
165165
let a2 = &*self.builtins.borrow();
166166
match a2.payload {
167-
PyObjectPayload::Module { name: _, ref dict } => dict.clone(),
167+
PyObjectPayload::Module { ref dict, .. } => dict.clone(),
168168
_ => {
169169
panic!("OMG");
170170
}
@@ -250,11 +250,7 @@ impl VirtualMachine {
250250
ref scope,
251251
ref defaults,
252252
} => self.invoke_python_function(code, scope, defaults, args),
253-
PyObjectPayload::Class {
254-
name: _,
255-
dict: _,
256-
mro: _,
257-
} => self.call_method_pyargs(&func_ref, "__call__", args),
253+
PyObjectPayload::Class { .. } => self.call_method_pyargs(&func_ref, "__call__", args),
258254
PyObjectPayload::BoundMethod {
259255
ref function,
260256
ref object,

0 commit comments

Comments
 (0)