diff options
| author | bors <bors@rust-lang.org> | 2014-05-24 18:56:19 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-24 18:56:19 -0700 |
| commit | bbb70cdd9cd982922cf7390459d53bde409699ae (patch) | |
| tree | 25c39cad9e52bb386f4d9a7cd5bac6fd376cfe3d /src/libstd | |
| parent | 07563be6ebe081c8f6666a7b6eb68d8e32774f2f (diff) | |
| parent | 9698221f919a80f2a0810e17c8ee8e80da8cefeb (diff) | |
| download | rust-bbb70cdd9cd982922cf7390459d53bde409699ae.tar.gz rust-bbb70cdd9cd982922cf7390459d53bde409699ae.zip | |
auto merge of #14402 : huonw/rust/arc-field-rename, r=alexcrichton
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.rs | 16 |
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; } } |
