about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-08 09:58:05 +0000
committerbors <bors@rust-lang.org>2015-04-08 09:58:05 +0000
commit926f38e588bb99aff1902fa94ab82b1db89cbbce (patch)
treec1551948b685c3a8797592727c01b921a118beac /src/test
parent3a66c7f6263ca390436a6faa9b8cbd0ef66c1e6c (diff)
parent63b36ea7c211406a76c34cba5ac9b7218e003757 (diff)
downloadrust-926f38e588bb99aff1902fa94ab82b1db89cbbce.tar.gz
rust-926f38e588bb99aff1902fa94ab82b1db89cbbce.zip
Auto merge of #23998 - nrc:impl-self, r=nikomatsakis
Closes #23909

r? @nikomatsakis (or anyone else, really)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/self-impl.rs40
-rw-r--r--src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs2
-rw-r--r--src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs2
-rw-r--r--src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs2
-rw-r--r--src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs2
-rw-r--r--src/test/run-pass/self-impl.rs40
6 files changed, 79 insertions, 9 deletions
diff --git a/src/test/compile-fail/self-impl.rs b/src/test/compile-fail/self-impl.rs
new file mode 100644
index 00000000000..d058c6a5a3b
--- /dev/null
+++ b/src/test/compile-fail/self-impl.rs
@@ -0,0 +1,40 @@
+// Copyright 2015 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 unsupported uses of `Self` in impls don't crash
+
+struct Bar;
+
+trait Foo {
+    type Baz;
+}
+
+trait SuperFoo {
+    type SuperBaz;
+}
+
+impl Foo for Bar {
+    type Baz = bool;
+}
+
+impl SuperFoo for Bar {
+    type SuperBaz = bool;
+}
+
+impl Bar {
+    fn f() {
+        let _: <Self>::Baz = true;
+//~^ERROR: ambiguous associated type; specify the type using the syntax `<Bar as Trait>::Baz`
+        let _: Self::Baz = true;
+//~^ERROR: ambiguous associated type; specify the type using the syntax `<Bar as Trait>::Baz`
+    }
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs
index c9837da58e7..bb7e02d0d8b 100644
--- a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs
+++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs
@@ -12,7 +12,7 @@
 
 trait One<A> { fn foo(&self) -> A; }
 
-fn foo(_: &One()) //~ ERROR no associated type `Output` defined in `One<()>`
+fn foo(_: &One()) //~ ERROR associated type `Output` not found for `One<()>`
 {}
 
 fn main() { }
diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs
index 9f0682df3fe..20fdd52b82a 100644
--- a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs
+++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs
@@ -14,7 +14,7 @@ trait Three<A,B,C> { fn dummy(&self) -> (A,B,C); }
 
 fn foo(_: &Three())
 //~^ ERROR wrong number of type arguments
-//~| ERROR no associated type `Output`
+//~| ERROR associated type `Output` not found
 {}
 
 fn main() { }
diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs
index 40635cf3ddd..027fa6b0fe3 100644
--- a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs
+++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs
@@ -14,7 +14,7 @@ trait Zero { fn dummy(&self); }
 
 fn foo(_: Zero())
     //~^ ERROR wrong number of type arguments
-    //~| ERROR no associated type `Output` defined in `Zero`
+    //~| ERROR associated type `Output` not found for `Zero`
 {}
 
 fn main() { }
diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
index e6e18d996b9..04bbfc445ed 100644
--- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
+++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
@@ -14,6 +14,6 @@ trait Trait {}
 
 fn f<F:Trait(isize) -> isize>(x: F) {}
 //~^ ERROR wrong number of type arguments: expected 0, found 1
-//~| ERROR no associated type `Output`
+//~| ERROR associated type `Output` not found
 
 fn main() {}
diff --git a/src/test/run-pass/self-impl.rs b/src/test/run-pass/self-impl.rs
index c32773aa88c..688b66a0a87 100644
--- a/src/test/run-pass/self-impl.rs
+++ b/src/test/run-pass/self-impl.rs
@@ -22,6 +22,17 @@ impl Foo {
     fn foo(_x: Self, _y: &Self, _z: Box<Self>) -> Self {
         Foo
     }
+
+    fn baz() {
+        // Test that Self cannot be shadowed.
+        type Foo = i32;
+        // There is no empty method on i32.
+        Self::empty();
+
+        let _: Self = Foo;
+    }
+
+    fn empty() {}
 }
 
 // Test uses when implementing a trait and with a type parameter.
@@ -29,13 +40,31 @@ pub struct Baz<X> {
     pub f: X,
 }
 
-trait Bar<X> {
-    fn bar(x: Self, y: &Self, z: Box<Self>) -> Self;
+trait SuperBar {
+    type SuperQux;
+}
+
+trait Bar<X>: SuperBar {
+    type Qux;
+
+    fn bar(x: Self, y: &Self, z: Box<Self>, _: Self::SuperQux) -> Self;
     fn dummy(&self, x: X) { }
 }
 
+impl SuperBar for Box<Baz<isize>> {
+    type SuperQux = bool;
+}
+
 impl Bar<isize> for Box<Baz<isize>> {
-    fn bar(_x: Self, _y: &Self, _z: Box<Self>) -> Self {
+    type Qux = i32;
+
+    fn bar(_x: Self, _y: &Self, _z: Box<Self>, _: Self::SuperQux) -> Self {
+        let _: Self::Qux = 42;
+        let _: <Self as Bar<isize>>::Qux = 42;
+
+        let _: Self::SuperQux = true;
+        let _: <Self as SuperBar>::SuperQux = true;
+
         box Baz { f: 42 }
     }
 }
@@ -43,6 +72,7 @@ impl Bar<isize> for Box<Baz<isize>> {
 fn main() {
     let _: Foo = Foo::foo(Foo, &Foo, box Foo);
     let _: Box<Baz<isize>> = Bar::bar(box Baz { f: 42 },
-                                    &box Baz { f: 42 },
-                                    box box Baz { f: 42 });
+                                      &box Baz { f: 42 },
+                                      box box Baz { f: 42 },
+                                      true);
 }