about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-03 02:40:59 +0000
committerbors <bors@rust-lang.org>2014-09-03 02:40:59 +0000
commitf7ec95efbb96f8e9bcb8b5e71b5d13803e840dc9 (patch)
tree7a86e9affd42434d280540f8208e710b78482e98 /src/test
parent2e385817926f6f914fbff482aab3a8b627e7feee (diff)
parent7f72884f1366ee9a46cd2b231c09c5c0e44f7ba3 (diff)
downloadrust-f7ec95efbb96f8e9bcb8b5e71b5d13803e840dc9.tar.gz
rust-f7ec95efbb96f8e9bcb8b5e71b5d13803e840dc9.zip
auto merge of #16917 : nick29581/rust/cross-trait, r=pcwalton
Closes #15349

r? @pcwalton (or anyone else)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/cross-borrow-trait.rs22
-rw-r--r--src/test/compile-fail/regions-close-object-into-object.rs8
-rw-r--r--src/test/run-pass/cleanup-auto-borrow-obj.rs2
-rw-r--r--src/test/run-pass/issue-3794.rs2
-rw-r--r--src/test/run-pass/new-box.rs2
-rw-r--r--src/test/run-pass/regions-early-bound-trait-param.rs4
6 files changed, 31 insertions, 9 deletions
diff --git a/src/test/compile-fail/cross-borrow-trait.rs b/src/test/compile-fail/cross-borrow-trait.rs
new file mode 100644
index 00000000000..1ccd5290fef
--- /dev/null
+++ b/src/test/compile-fail/cross-borrow-trait.rs
@@ -0,0 +1,22 @@
+// Copyright 2012-2013-2014 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 that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
+// forbidden when `T` is a trait.
+
+struct Foo;
+trait Trait {}
+impl Trait for Foo {}
+
+pub fn main() {
+    let x: Box<Trait> = box Foo;
+    let _y: &Trait = x; //~ ERROR mismatched types: expected `&Trait`, found `Box<Trait>`
+}
+
diff --git a/src/test/compile-fail/regions-close-object-into-object.rs b/src/test/compile-fail/regions-close-object-into-object.rs
index a45c8e1db54..835c55c9bd1 100644
--- a/src/test/compile-fail/regions-close-object-into-object.rs
+++ b/src/test/compile-fail/regions-close-object-into-object.rs
@@ -16,19 +16,19 @@ trait X {}
 impl<'a, T> X for B<'a, T> {}
 
 fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
-    box B(v) as Box<X>
+    box B(&*v) as Box<X>
 }
 
 fn g<'a, T: 'static>(v: Box<A<T>>) -> Box<X+'static> {
-    box B(v) as Box<X> //~ ERROR cannot infer
+    box B(&*v) as Box<X> //~ ERROR cannot infer
 }
 
 fn h<'a, T, U>(v: Box<A<U>+'static>) -> Box<X+'static> {
-    box B(v) as Box<X>
+    box B(&*v) as Box<X>
 }
 
 fn i<'a, T, U>(v: Box<A<U>>) -> Box<X+'static> {
-    box B(v) as Box<X> //~ ERROR cannot infer
+    box B(&*v) as Box<X> //~ ERROR cannot infer
 }
 
 fn main() {}
diff --git a/src/test/run-pass/cleanup-auto-borrow-obj.rs b/src/test/run-pass/cleanup-auto-borrow-obj.rs
index 23142082a8c..5d7dbbe5a29 100644
--- a/src/test/run-pass/cleanup-auto-borrow-obj.rs
+++ b/src/test/run-pass/cleanup-auto-borrow-obj.rs
@@ -29,7 +29,7 @@ impl Trait for Foo {}
 
 pub fn main() {
     {
-        let _x: &Trait = box Foo as Box<Trait>;
+        let _x: &Trait = &*(box Foo as Box<Trait>);
     }
     unsafe {
         assert!(DROP_RAN);
diff --git a/src/test/run-pass/issue-3794.rs b/src/test/run-pass/issue-3794.rs
index 9414a6f2302..54225bbe01e 100644
--- a/src/test/run-pass/issue-3794.rs
+++ b/src/test/run-pass/issue-3794.rs
@@ -36,5 +36,5 @@ pub fn main() {
     let s: Box<S> = box S { s: 5 };
     print_s(&*s);
     let t: Box<T> = s as Box<T>;
-    print_t(t);
+    print_t(&*t);
 }
diff --git a/src/test/run-pass/new-box.rs b/src/test/run-pass/new-box.rs
index 38f552e9a98..8531fd5f975 100644
--- a/src/test/run-pass/new-box.rs
+++ b/src/test/run-pass/new-box.rs
@@ -29,7 +29,7 @@ impl Trait for Struct {
 
 fn g(x: Box<Trait>) {
     x.printme();
-    let y: &Trait = x;
+    let y: &Trait = &*x;
     y.printme();
 }
 
diff --git a/src/test/run-pass/regions-early-bound-trait-param.rs b/src/test/run-pass/regions-early-bound-trait-param.rs
index 27ef90d7376..c732d20a156 100644
--- a/src/test/run-pass/regions-early-bound-trait-param.rs
+++ b/src/test/run-pass/regions-early-bound-trait-param.rs
@@ -120,8 +120,8 @@ pub fn main() {
     assert_eq!(field_invoke2(&s2), 3);
 
     let m : Box<Trait> = make_val();
-    assert_eq!(object_invoke1(m), (4,5));
-    assert_eq!(object_invoke2(m), 5);
+    assert_eq!(object_invoke1(&*m), (4,5));
+    assert_eq!(object_invoke2(&*m), 5);
 
     // The RefMakerTrait above is pretty strange (i.e. it is strange
     // to consume a value of type T and return a &T).  Easiest thing