about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-05-24 21:35:53 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2014-05-25 10:23:37 +1000
commit9698221f919a80f2a0810e17c8ee8e80da8cefeb (patch)
tree29b0bb162d7e94d1ebc91d44d6265f211914934b /src/libstd
parent9e244d708461d5028066a59e70866f52517e7b85 (diff)
downloadrust-9698221f919a80f2a0810e17c8ee8e80da8cefeb.tar.gz
rust-9698221f919a80f2a0810e17c8ee8e80da8cefeb.zip
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<Foo> = ...;
    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
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/local_data.rs16
1 files changed, 9 insertions, 7 deletions
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<T: 'static>(key: Key<T>) -> *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<T> {
-    ptr: &'static T,
-    key: Key<T>,
-    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<T>,
+    _index: uint,
+    _nosend: marker::NoSend,
 }
 
 impl<T: 'static> KeyValue<T> {
@@ -233,7 +235,7 @@ impl<T: 'static> KeyValue<T> {
                 let data = data as *Box<LocalData:Send> 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<T: 'static> KeyValue<T> {
 }
 
 impl<T: 'static> Deref<T> for Ref<T> {
-    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<T: 'static> Drop for Ref<T> {
     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;
     }
 }