From 9917bebb9986c506ae9b0901e030afead54d939a Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Wed, 15 Aug 2018 12:40:52 +0100 Subject: [PATCH] Remove unnecessary mutability in DictProtocol. --- vm/src/builtins.rs | 2 +- vm/src/pyobject.rs | 8 ++++---- vm/src/sysmodule.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 2dd9c4a60..132e51c0d 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -11,7 +11,7 @@ use super::pyobject::{ use super::vm::VirtualMachine; fn get_locals(vm: &mut VirtualMachine) -> PyObjectRef { - let mut d = vm.new_dict(); + let d = vm.new_dict(); // TODO: implement dict_iter_items? let locals = vm.get_locals(); match locals.borrow().kind { diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 19dd36792..9e0f18b5c 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -270,8 +270,8 @@ impl AttributeProtocol for PyObjectRef { } fn set_attr(&self, attr_name: &String, value: PyObjectRef) { - match self.borrow_mut().kind { - PyObjectKind::Instance { ref mut dict } => dict.set_item(attr_name, value), + match self.borrow().kind { + PyObjectKind::Instance { ref dict } => dict.set_item(attr_name, value), ref kind => unimplemented!("load_attr unimplemented for: {:?}", kind), }; } @@ -280,7 +280,7 @@ impl AttributeProtocol for PyObjectRef { pub trait DictProtocol { fn contains_key(&self, k: &String) -> bool; fn get_item(&self, k: &String) -> PyObjectRef; - fn set_item(&mut self, k: &String, v: PyObjectRef); + fn set_item(&self, k: &String, v: PyObjectRef); } impl DictProtocol for PyObjectRef { @@ -302,7 +302,7 @@ impl DictProtocol for PyObjectRef { } } - fn set_item(&mut self, k: &String, v: PyObjectRef) { + fn set_item(&self, k: &String, v: PyObjectRef) { match self.borrow_mut().kind { PyObjectKind::Dict { elements: ref mut el, diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index da454aca5..5886cb0e4 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -8,9 +8,9 @@ use super::pyobject::{DictProtocol, PyContext, PyObjectRef}; pub fn mk_module(ctx: &PyContext) -> PyObjectRef { let path = ctx.new_list(None); - let mut modules = ctx.new_dict(); + let modules = ctx.new_dict(); let sys_name = "sys".to_string(); - let mut sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None)); + let sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None)); modules.set_item(&sys_name, sys_mod.clone()); sys_mod.set_item(&"modules".to_string(), modules); sys_mod.set_item(&"path".to_string(), path);