From 5e28f7cdf6f25a3ce427ee0977c00ade5627de7e Mon Sep 17 00:00:00 2001 From: kngwyu Date: Tue, 18 Feb 2020 12:52:41 +0900 Subject: [PATCH] Rename unchecked_refmut -> unchecked_mut --- src/pycell.rs | 32 ++++++++++++++++---------------- src/type_object.rs | 2 +- src/types/any.rs | 2 +- src/types/mod.rs | 2 +- tests/test_gc.rs | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/pycell.rs b/src/pycell.rs index 8a4212fe9f0..1937d58619e 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -26,7 +26,7 @@ where unsafe fn unchecked_ref(&self) -> &T { &*((&self) as *const &Self as *const _) } - unsafe fn unchecked_refmut(&self) -> &mut T { + unsafe fn unchecked_mut(&self) -> &mut T { &mut *((&self) as *const &Self as *const _ as *mut _) } } @@ -64,7 +64,7 @@ unsafe impl PyObjectLayout for PyCellInner { unsafe fn unchecked_ref(&self) -> &T { &*self.value.get() } - unsafe fn unchecked_refmut(&self) -> &mut T { + unsafe fn unchecked_mut(&self) -> &mut T { &mut *self.value.get() } unsafe fn py_init(&mut self, value: T) { @@ -202,8 +202,8 @@ unsafe impl PyObjectLayout for PyCell { unsafe fn unchecked_ref(&self) -> &T { self.inner.unchecked_ref() } - unsafe fn unchecked_refmut(&self) -> &mut T { - self.inner.unchecked_refmut() + unsafe fn unchecked_mut(&self) -> &mut T { + self.inner.unchecked_mut() } unsafe fn py_init(&mut self, value: T) { self.inner.value = ManuallyDrop::new(UnsafeCell::new(value)); @@ -273,11 +273,11 @@ where U: PyClass, { pub fn into_super(self) -> PyRef<'p, U> { - let res = PyRef { - inner: &self.inner.ob_base, - }; - std::mem::forget(self); // Avoid drop - res + let PyRef { inner } = self; + std::mem::forget(self); + PyRef { + inner: &inner.ob_base, + } } } @@ -331,7 +331,7 @@ impl<'p, T: PyClass> PyRefMut<'p, T> { unsafe { self.inner.ob_base.unchecked_ref() } } pub fn as_super_mut(&'p mut self) -> &'p mut T::BaseType { - unsafe { self.inner.ob_base.unchecked_refmut() } + unsafe { self.inner.ob_base.unchecked_mut() } } } @@ -341,11 +341,11 @@ where U: PyClass, { pub fn into_super(self) -> PyRefMut<'p, U> { - let res = PyRefMut { - inner: &self.inner.ob_base, - }; - std::mem::forget(self); // Avoid drop - res + let PyRefMut { inner } = self; + std::mem::forget(self); + PyRefMut { + inner: &inner.ob_base, + } } } @@ -361,7 +361,7 @@ impl<'p, T: PyClass> Deref for PyRefMut<'p, T> { impl<'p, T: PyClass> DerefMut for PyRefMut<'p, T> { #[inline] fn deref_mut(&mut self) -> &mut T { - unsafe { self.inner.unchecked_refmut() } + unsafe { self.inner.unchecked_mut() } } } diff --git a/src/type_object.rs b/src/type_object.rs index 90df093d06d..e694f3635d0 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -22,7 +22,7 @@ pub unsafe trait PyObjectLayout { unsafe fn py_init(&mut self, _value: T) {} unsafe fn py_drop(&mut self, _py: Python) {} unsafe fn unchecked_ref(&self) -> &T; - unsafe fn unchecked_refmut(&self) -> &mut T; + unsafe fn unchecked_mut(&self) -> &mut T; } /// `T: PyObjectSizedLayout` represents `T` is not a instance of diff --git a/src/types/any.rs b/src/types/any.rs index cdda72fdd14..9a1cd113277 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -27,7 +27,7 @@ unsafe impl crate::type_object::PyObjectLayout for ffi::PyObject { unsafe fn unchecked_ref(&self) -> &PyAny { &*((&self) as *const &Self as *const _) } - unsafe fn unchecked_refmut(&self) -> &mut PyAny { + unsafe fn unchecked_mut(&self) -> &mut PyAny { &mut *((&self) as *const &Self as *const _ as *mut _) } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 5e82f85a616..1e7c247df35 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -62,7 +62,7 @@ macro_rules! impl_layout { unsafe fn unchecked_ref(&self) -> &$name { &*((&self) as *const &Self as *const _) } - unsafe fn unchecked_refmut(&self) -> &mut $name { + unsafe fn unchecked_mut(&self) -> &mut $name { &mut *((&self) as *const &Self as *const _ as *mut _) } } diff --git a/tests/test_gc.rs b/tests/test_gc.rs index 6a86d3e2ec0..313555d3390 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -268,7 +268,7 @@ fn inheritance_with_new_methods_with_drop() { let obj: &PyCell = inst.try_into().unwrap(); let mut obj_ref_mut = obj.borrow_mut(); obj_ref_mut.data = Some(Arc::clone(&drop_called1)); - let super_ = obj_ref_mut.get_super_mut(); + let mut super_ = obj_ref_mut.into_super(); super_.data = Some(Arc::clone(&drop_called2)); }