1
Fork 0

Remove strange names created by lack of privacy-conscious name lookup

The fixed issue that allowed this was #12808.
This commit is contained in:
Tobias Bucher 2016-04-05 11:02:49 +02:00
commit 0936b5885d
3 changed files with 74 additions and 86 deletions

View file

@ -184,9 +184,7 @@ struct RcBox<T: ?Sized> {
#[unsafe_no_drop_flag]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Rc<T: ?Sized> {
// FIXME #12808: strange names to try to avoid interfering with field
// accesses of the contained type via Deref
_ptr: Shared<RcBox<T>>,
ptr: Shared<RcBox<T>>,
}
#[stable(feature = "rust1", since = "1.0.0")]
@ -215,7 +213,7 @@ impl<T> Rc<T> {
// pointers, which ensures that the weak destructor never frees
// the allocation while the strong destructor is running, even
// if the weak pointer is stored inside the strong one.
_ptr: Shared::new(Box::into_raw(box RcBox {
ptr: Shared::new(Box::into_raw(box RcBox {
strong: Cell::new(1),
weak: Cell::new(1),
value: value,
@ -254,7 +252,7 @@ impl<T> Rc<T> {
// pointer while also handling drop logic by just crafting a
// fake Weak.
this.dec_strong();
let _weak = Weak { _ptr: this._ptr };
let _weak = Weak { ptr: this.ptr };
forget(this);
Ok(val)
}
@ -287,7 +285,7 @@ impl<T: ?Sized> Rc<T> {
#[stable(feature = "rc_weak", since = "1.4.0")]
pub fn downgrade(this: &Self) -> Weak<T> {
this.inc_weak();
Weak { _ptr: this._ptr }
Weak { ptr: this.ptr }
}
/// Get the number of weak references to this value.
@ -348,7 +346,7 @@ impl<T: ?Sized> Rc<T> {
#[stable(feature = "rc_unique", since = "1.4.0")]
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
if Rc::is_unique(this) {
let inner = unsafe { &mut **this._ptr };
let inner = unsafe { &mut **this.ptr };
Some(&mut inner.value)
} else {
None
@ -390,7 +388,7 @@ impl<T: Clone> Rc<T> {
} else if Rc::weak_count(this) != 0 {
// Can just steal the data, all that's left is Weaks
unsafe {
let mut swap = Rc::new(ptr::read(&(**this._ptr).value));
let mut swap = Rc::new(ptr::read(&(**this.ptr).value));
mem::swap(this, &mut swap);
swap.dec_strong();
// Remove implicit strong-weak ref (no need to craft a fake
@ -404,7 +402,7 @@ impl<T: Clone> Rc<T> {
// reference count is guaranteed to be 1 at this point, and we required
// the `Rc<T>` itself to be `mut`, so we're returning the only possible
// reference to the inner value.
let inner = unsafe { &mut **this._ptr };
let inner = unsafe { &mut **this.ptr };
&mut inner.value
}
}
@ -449,7 +447,7 @@ impl<T: ?Sized> Drop for Rc<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
unsafe {
let ptr = *self._ptr;
let ptr = *self.ptr;
let thin = ptr as *const ();
if thin as usize != mem::POST_DROP_USIZE {
@ -490,7 +488,7 @@ impl<T: ?Sized> Clone for Rc<T> {
#[inline]
fn clone(&self) -> Rc<T> {
self.inc_strong();
Rc { _ptr: self._ptr }
Rc { ptr: self.ptr }
}
}
@ -691,7 +689,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Rc<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> fmt::Pointer for Rc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&*self._ptr, f)
fmt::Pointer::fmt(&*self.ptr, f)
}
}
@ -711,9 +709,7 @@ impl<T> From<T> for Rc<T> {
#[unsafe_no_drop_flag]
#[stable(feature = "rc_weak", since = "1.4.0")]
pub struct Weak<T: ?Sized> {
// FIXME #12808: strange names to try to avoid interfering with
// field accesses of the contained type via Deref
_ptr: Shared<RcBox<T>>,
ptr: Shared<RcBox<T>>,
}
#[stable(feature = "rc_weak", since = "1.4.0")]
@ -749,7 +745,7 @@ impl<T: ?Sized> Weak<T> {
None
} else {
self.inc_strong();
Some(Rc { _ptr: self._ptr })
Some(Rc { ptr: self.ptr })
}
}
}
@ -783,7 +779,7 @@ impl<T: ?Sized> Drop for Weak<T> {
/// ```
fn drop(&mut self) {
unsafe {
let ptr = *self._ptr;
let ptr = *self.ptr;
let thin = ptr as *const ();
if thin as usize != mem::POST_DROP_USIZE {
@ -816,7 +812,7 @@ impl<T: ?Sized> Clone for Weak<T> {
#[inline]
fn clone(&self) -> Weak<T> {
self.inc_weak();
Weak { _ptr: self._ptr }
Weak { ptr: self.ptr }
}
}
@ -848,7 +844,7 @@ impl<T> Weak<T> {
pub fn new() -> Weak<T> {
unsafe {
Weak {
_ptr: Shared::new(Box::into_raw(box RcBox {
ptr: Shared::new(Box::into_raw(box RcBox {
strong: Cell::new(0),
weak: Cell::new(1),
value: uninitialized(),
@ -910,8 +906,8 @@ impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
// the contract anyway.
// This allows the null check to be elided in the destructor if we
// manipulated the reference count in the same function.
assume(!(*(&self._ptr as *const _ as *const *const ())).is_null());
&(**self._ptr)
assume(!(*(&self.ptr as *const _ as *const *const ())).is_null());
&(**self.ptr)
}
}
}
@ -924,8 +920,8 @@ impl<T: ?Sized> RcBoxPtr<T> for Weak<T> {
// the contract anyway.
// This allows the null check to be elided in the destructor if we
// manipulated the reference count in the same function.
assume(!(*(&self._ptr as *const _ as *const *const ())).is_null());
&(**self._ptr)
assume(!(*(&self.ptr as *const _ as *const *const ())).is_null());
&(**self.ptr)
}
}
}