Remove unnecessary mutability in DictProtocol.

This commit is contained in:
Adam Kelly
2018-08-15 12:40:52 +01:00
parent 8eee2cec74
commit 9917bebb99
3 changed files with 7 additions and 7 deletions

View File

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

View File

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

View File

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