about summary refs log tree commit diff
path: root/src/libstd/local_data.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-05-05 18:56:44 -0700
committerPatrick Walton <pcwalton@mimiga.net>2014-05-06 23:12:54 -0700
commit090040bf4037a094e50b03d79e4baf5cd89c912b (patch)
tree27fa91d623889d59260d3db167abdfa8c4288849 /src/libstd/local_data.rs
parent24f6f26e633e50b5b59f9d0f6cca0b1e49e215d9 (diff)
downloadrust-090040bf4037a094e50b03d79e4baf5cd89c912b.tar.gz
rust-090040bf4037a094e50b03d79e4baf5cd89c912b.zip
librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except
for `~str`/`~[]`.

Note that `~self` still remains, since I forgot to add support for
`Box<self>` before the snapshot.

How to update your code:

* Instead of `~EXPR`, you should write `box EXPR`.

* Instead of `~TYPE`, you should write `Box<Type>`.

* Instead of `~PATTERN`, you should write `box PATTERN`.

[breaking-change]
Diffstat (limited to 'src/libstd/local_data.rs')
-rw-r--r--src/libstd/local_data.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs
index e5c7ba4aa54..8855dabe353 100644
--- a/src/libstd/local_data.rs
+++ b/src/libstd/local_data.rs
@@ -45,6 +45,7 @@ use iter::{Iterator};
 use kinds::Send;
 use mem::replace;
 use option::{None, Option, Some};
+use owned::Box;
 use rt::task::{Task, LocalStorage};
 use slice::{ImmutableVector, MutableVector};
 use vec::Vec;
@@ -91,7 +92,7 @@ impl<T: 'static> LocalData for T {}
 //      a proper map.
 #[doc(hidden)]
 pub type Map = Vec<Option<(*u8, TLSValue, LoanState)>>;
-type TLSValue = ~LocalData:Send;
+type TLSValue = Box<LocalData:Send>;
 
 // Gets the map from the runtime. Lazily initialises if not done so already.
 unsafe fn get_local_map() -> &mut Map {
@@ -161,7 +162,7 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> {
 
                 // Move `data` into transmute to get out the memory that it
                 // owns, we must free it manually later.
-                let (_vtable, alloc): (uint, ~T) = unsafe {
+                let (_vtable, alloc): (uint, Box<T>) = unsafe {
                     cast::transmute(data)
                 };
 
@@ -252,11 +253,12 @@ fn get_with<T:'static,
                                   want.describe(), cur.describe());
                         }
                     }
-                    // data was created with `~T as ~LocalData`, so we extract
-                    // pointer part of the trait, (as ~T), and then use
-                    // compiler coercions to achieve a '&' pointer.
+                    // data was created with `box T as Box<LocalData>`, so we
+                    // extract pointer part of the trait, (as Box<T>), and
+                    // then use compiler coercions to achieve a '&' pointer.
                     unsafe {
-                        match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){
+                        match *cast::transmute::<&TLSValue,
+                                                 &(uint, Box<T>)>(data){
                             (_vtable, ref alloc) => {
                                 let value: &T = *alloc;
                                 ret = f(Some(value));
@@ -297,12 +299,12 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
     let keyval = key_to_key_value(key);
 
     // When the task-local map is destroyed, all the data needs to be cleaned
-    // up. For this reason we can't do some clever tricks to store '~T' as a
-    // '*c_void' or something like that. To solve the problem, we cast
+    // up. For this reason we can't do some clever tricks to store 'Box<T>' as
+    // a '*c_void' or something like that. To solve the problem, we cast
     // everything to a trait (LocalData) which is then stored inside the map.
     // Upon destruction of the map, all the objects will be destroyed and the
     // traits have enough information about them to destroy themselves.
-    let data = box data as ~LocalData:;
+    let data = box data as Box<LocalData:>;
 
     fn insertion_position(map: &mut Map,
                           key: *u8) -> Option<uint> {
@@ -330,7 +332,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
     // transmute here to add the Send bound back on. This doesn't actually
     // matter because TLS will always own the data (until its moved out) and
     // we're not actually sending it to other schedulers or anything.
-    let data: ~LocalData:Send = unsafe { cast::transmute(data) };
+    let data: Box<LocalData:Send> = unsafe { cast::transmute(data) };
     match insertion_position(map, keyval) {
         Some(i) => { *map.get_mut(i) = Some((keyval, data, NoLoan)); }
         None => { map.push(Some((keyval, data, NoLoan))); }
@@ -353,6 +355,7 @@ pub fn modify<T: 'static>(key: Key<T>, f: |Option<T>| -> Option<T>) {
 mod tests {
     use prelude::*;
     use super::*;
+    use owned::Box;
     use task;
     use str::StrSlice;
 
@@ -485,7 +488,7 @@ mod tests {
 
     #[test]
     fn test_owned() {
-        static key: Key<~int> = &Key;
+        static key: Key<Box<int>> = &Key;
         set(key, box 1);
 
         get(key, |v| {