about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-10-29 20:29:59 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-11-05 15:51:18 -0500
commit71acc543ca0858a064c4bed848b507325c383939 (patch)
tree36c5449d3a5f50b7eb3b11e315284e5d2f1cc94b
parent3d1f3f4de087ccf7e30b795fbd73e054b4761c4f (diff)
downloadrust-71acc543ca0858a064c4bed848b507325c383939.tar.gz
rust-71acc543ca0858a064c4bed848b507325c383939.zip
Make TypeContents consider the type `T` to be reachable via `*T` pointers
Fixes #9509
-rw-r--r--src/librustc/middle/ty.rs6
-rw-r--r--src/librustuv/uvio.rs19
-rw-r--r--src/test/compile-fail/kindck-freeze.rs56
-rw-r--r--src/test/compile-fail/kindck-send.rs59
4 files changed, 128 insertions, 12 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 7f9edba2f14..96bb2897e0e 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -2088,7 +2088,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
         let result = match get(ty).sty {
             // Scalar and unique types are sendable, freezable, and durable
             ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
-            ty_bare_fn(_) | ty_ptr(_) | ty::ty_char => {
+            ty_bare_fn(_) | ty::ty_char => {
                 TC::None
             }
 
@@ -2108,6 +2108,10 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
                 object_contents(cx, store, mutbl, bounds)
             }
 
+            ty_ptr(ref mt) => {
+                tc_ty(cx, mt.ty, cache).other_pointer(TC::None)
+            }
+
             ty_rptr(r, ref mt) => {
                 tc_ty(cx, mt.ty, cache).other_pointer(
                     borrowed_contents(r, mt.mutbl))
diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs
index 15d5fe702a5..3f119bc8ccb 100644
--- a/src/librustuv/uvio.rs
+++ b/src/librustuv/uvio.rs
@@ -414,10 +414,10 @@ impl UvIoFactory {
 /// callback in a situation where the task wil be immediately blocked
 /// afterwards. The `FsCallback` yielded must be invoked to reschedule the task
 /// (once the result of the operation is known).
-fn uv_fs_helper<T>(loop_: &mut Loop,
-                   retfn: extern "Rust" fn(&mut FsRequest) -> T,
-                   cb: &fn(&mut FsRequest, &mut Loop, FsCallback))
-        -> Result<T, IoError> {
+fn uv_fs_helper<T:Send>(loop_: &mut Loop,
+                        retfn: extern "Rust" fn(&mut FsRequest) -> T,
+                        cb: &fn(&mut FsRequest, &mut Loop, FsCallback))
+                        -> Result<T, IoError> {
     let result_cell = Cell::new_empty();
     let result_cell_ptr: *Cell<Result<T, IoError>> = &result_cell;
     do task::unkillable { // FIXME(#8674)
@@ -1025,14 +1025,12 @@ fn read_stream(mut watcher: StreamWatcher,
     let result_cell = Cell::new_empty();
     let result_cell_ptr: *Cell<Result<uint, IoError>> = &result_cell;
 
-    let buf_ptr: *&mut [u8] = &buf;
+    let uv_buf = slice_to_uv_buf(buf);
     do scheduler.deschedule_running_task_and_then |_sched, task| {
         let task_cell = Cell::new(task);
         // XXX: We shouldn't reallocate these callbacks every
         // call to read
-        let alloc: AllocCallback = |_| unsafe {
-            slice_to_uv_buf(*buf_ptr)
-        };
+        let alloc: AllocCallback = |_| uv_buf;
         do watcher.read_start(alloc) |mut watcher, nread, _buf, status| {
 
             // Stop reading so that no read callbacks are
@@ -1280,11 +1278,10 @@ impl RtioUdpSocket for UvUdpSocket {
         do self.home_for_io_with_sched |self_, scheduler| {
             let result_cell = Cell::new_empty();
             let result_cell_ptr: *Cell<Result<(uint, SocketAddr), IoError>> = &result_cell;
-
-            let buf_ptr: *&mut [u8] = &buf;
+            let uv_buf = slice_to_uv_buf(buf);
             do scheduler.deschedule_running_task_and_then |_, task| {
                 let task_cell = Cell::new(task);
-                let alloc: AllocCallback = |_| unsafe { slice_to_uv_buf(*buf_ptr) };
+                let alloc: AllocCallback = |_| uv_buf;
                 do self_.watcher.recv_start(alloc) |mut watcher, nread, _buf, addr, flags, status| {
                     let _ = flags; // /XXX add handling for partials?
 
diff --git a/src/test/compile-fail/kindck-freeze.rs b/src/test/compile-fail/kindck-freeze.rs
new file mode 100644
index 00000000000..c83892e2a3b
--- /dev/null
+++ b/src/test/compile-fail/kindck-freeze.rs
@@ -0,0 +1,56 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test which of the builtin types are considered freezeable.
+
+fn assert_freeze<T:Freeze>() { }
+trait Dummy { }
+
+fn test<'a,T,U:Freeze>(_: &'a int) {
+    // lifetime pointers are ok...
+    assert_freeze::<&'static int>();
+    assert_freeze::<&'a int>();
+    assert_freeze::<&'a str>();
+    assert_freeze::<&'a [int]>();
+
+    // ...unless they are mutable
+    assert_freeze::<&'static mut int>(); //~ ERROR does not fulfill `Freeze`
+    assert_freeze::<&'a mut int>(); //~ ERROR does not fulfill `Freeze`
+
+    // ~ pointers are ok
+    assert_freeze::<~int>();
+    assert_freeze::<~str>();
+    assert_freeze::<~[int]>();
+
+    // but not if they own a bad thing
+    assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
+
+    // careful with object types, who knows what they close over...
+    assert_freeze::<&'a Dummy>(); //~ ERROR does not fulfill `Freeze`
+    assert_freeze::<~Dummy>(); //~ ERROR does not fulfill `Freeze`
+
+    // ...unless they are properly bounded
+    assert_freeze::<&'a Dummy:Freeze>();
+    assert_freeze::<&'static Dummy:Freeze>();
+    assert_freeze::<~Dummy:Freeze>();
+
+    // ...but even then the pointer overrides
+    assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
+
+    // closures are like an `&mut` object
+    assert_freeze::<&fn()>(); //~ ERROR does not fulfill `Freeze`
+
+    // unsafe ptrs are ok unless they point at unfreezeable things
+    assert_freeze::<*int>();
+    assert_freeze::<*&'a mut int>(); //~ ERROR does not fulfill `Freeze`
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs
new file mode 100644
index 00000000000..bb5851ac5c8
--- /dev/null
+++ b/src/test/compile-fail/kindck-send.rs
@@ -0,0 +1,59 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test which of the builtin types are considered sendable.
+
+fn assert_send<T:Send>() { }
+trait Dummy { }
+
+fn test<'a,T,U:Send>(_: &'a int) {
+    // lifetime pointers with 'static lifetime are ok
+    assert_send::<&'static int>();
+    assert_send::<&'static str>();
+    assert_send::<&'static [int]>();
+
+    // whether or not they are mutable
+    assert_send::<&'static mut int>();
+
+    // otherwise lifetime pointers are not ok
+    assert_send::<&'a int>(); //~ ERROR does not fulfill `Send`
+    assert_send::<&'a str>(); //~ ERROR does not fulfill `Send`
+    assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send`
+
+    // ~ pointers are ok
+    assert_send::<~int>();
+    assert_send::<~str>();
+    assert_send::<~[int]>();
+
+    // but not if they own a bad thing
+    assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send`
+
+    // careful with object types, who knows what they close over...
+    assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
+    assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
+    assert_send::<&'a Dummy:Send>(); //~ ERROR does not fulfill `Send`
+    assert_send::<~Dummy:>(); //~ ERROR does not fulfill `Send`
+
+    // ...unless they are properly bounded
+    assert_send::<&'static Dummy:Send>();
+    assert_send::<~Dummy:Send>();
+
+    // but closure and object types can have lifetime bounds which make
+    // them not ok (FIXME #5121)
+    // assert_send::<~fn:'a()>(); // ERROR does not fulfill `Send`
+    // assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send`
+
+    // unsafe ptrs are ok unless they point at unsendable things
+    assert_send::<*int>();
+    assert_send::<*&'a int>(); //~ ERROR does not fulfill `Send`
+}
+
+fn main() {
+}