From 9698221f919a80f2a0810e17c8ee8e80da8cefeb Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 24 May 2014 21:35:53 +1000 Subject: Paper over privacy issues with Deref by changing field names. Types that implement Deref can cause weird error messages due to their private fields conflicting with a field of the type they deref to, e.g., previously struct Foo { x: int } let a: Arc = ...; println!("{}", a.x); would complain the the `x` field of `Arc` was private (since Arc has a private field called `x`) rather than just ignoring it. This patch doesn't fix that issue, but does mean one would have to write `a._ptr` to hit the same error message, which seems far less common. (This patch `_`-prefixes all private fields of `Deref`-implementing types.) cc #12808 --- src/libstd/local_data.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 8798c035fca..2c7e16cf18b 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -127,10 +127,12 @@ fn key_to_key_value(key: Key) -> *u8 { /// The task-local data can be accessed through this value, and when this /// structure is dropped it will return the borrow on the data. pub struct Ref { - ptr: &'static T, - key: Key, - index: uint, - nosend: marker::NoSend, + // FIXME #12808: strange names to try to avoid interfering with + // field accesses of the contained type via Deref + _ptr: &'static T, + _key: Key, + _index: uint, + _nosend: marker::NoSend, } impl KeyValue { @@ -233,7 +235,7 @@ impl KeyValue { let data = data as *Box as *raw::TraitObject; &mut *((*data).data as *mut T) }; - Ref { ptr: ptr, index: pos, nosend: marker::NoSend, key: self } + Ref { _ptr: ptr, _index: pos, _nosend: marker::NoSend, _key: self } }) } @@ -252,7 +254,7 @@ impl KeyValue { } impl Deref for Ref { - fn deref<'a>(&'a self) -> &'a T { self.ptr } + fn deref<'a>(&'a self) -> &'a T { self._ptr } } #[unsafe_destructor] @@ -260,7 +262,7 @@ impl Drop for Ref { fn drop(&mut self) { let map = unsafe { get_local_map() }; - let (_, _, ref mut loan) = *map.get_mut(self.index).get_mut_ref(); + let (_, _, ref mut loan) = *map.get_mut(self._index).get_mut_ref(); *loan -= 1; } } -- cgit 1.4.1-3-g733a5