about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2018-06-08 17:00:26 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2018-06-08 17:00:26 +0100
commit87f63ca258416e55d89879ea7f89a8ca1064b665 (patch)
tree7830ac4e29b77588f1dfb23f4f4ae43857bc3efa /src/test
parentba35e8053499b694498184905f1be11b727cdf72 (diff)
downloadrust-87f63ca258416e55d89879ea7f89a8ca1064b665.tar.gz
rust-87f63ca258416e55d89879ea7f89a8ca1064b665.zip
Add tests for associated types and inconsistent bounds
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/trivial-bounds-inconsistent-projection-error.rs33
-rw-r--r--src/test/ui/trivial-bounds-inconsistent-projection-error.stderr12
-rw-r--r--src/test/ui/trivial-bounds-inconsistent-projection.rs64
-rw-r--r--src/test/ui/trivial-bounds-inconsistent-projection.stderr57
4 files changed, 166 insertions, 0 deletions
diff --git a/src/test/ui/trivial-bounds-inconsistent-projection-error.rs b/src/test/ui/trivial-bounds-inconsistent-projection-error.rs
new file mode 100644
index 00000000000..1a3bd3a8cd7
--- /dev/null
+++ b/src/test/ui/trivial-bounds-inconsistent-projection-error.rs
@@ -0,0 +1,33 @@
+// Copyright 2018 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.
+
+#![feature(trivial_bounds)]
+#![allow(unused)]
+
+struct B;
+
+trait A {
+    type X;
+    fn get_x() -> Self::X;
+}
+
+impl A for B {
+    type X = u8;
+    fn get_x() -> u8 { 0 }
+}
+
+fn global_bound_is_hidden() -> u8
+where
+    B: A<X = i32>
+{
+    B::get_x() //~ ERROR
+}
+
+fn main () {}
diff --git a/src/test/ui/trivial-bounds-inconsistent-projection-error.stderr b/src/test/ui/trivial-bounds-inconsistent-projection-error.stderr
new file mode 100644
index 00000000000..0f720bee2b4
--- /dev/null
+++ b/src/test/ui/trivial-bounds-inconsistent-projection-error.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/trivial-bounds-inconsistent-projection-error.rs:30:5
+   |
+LL | fn global_bound_is_hidden() -> u8
+   |                                -- expected `u8` because of return type
+...
+LL |     B::get_x() //~ ERROR
+   |     ^^^^^^^^^^ expected u8, found i32
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/trivial-bounds-inconsistent-projection.rs b/src/test/ui/trivial-bounds-inconsistent-projection.rs
new file mode 100644
index 00000000000..8de6f06bf5f
--- /dev/null
+++ b/src/test/ui/trivial-bounds-inconsistent-projection.rs
@@ -0,0 +1,64 @@
+// Copyright 2018 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.
+
+// run-pass
+// Check that global bounds result in the expected choice of associated type
+
+#![feature(trivial_bounds)]
+#![allow(unused)]
+
+struct B;
+
+trait A {
+    type X;
+    fn get_x() -> Self::X;
+}
+
+impl A for B {
+    type X = u8;
+    fn get_x() -> u8 { 0 }
+}
+
+fn underspecified_bound() -> u8
+where
+    B: A
+{
+    B::get_x()
+}
+
+fn inconsistent_bound() -> i32
+where
+    B: A<X = i32>
+{
+    B::get_x()
+}
+
+fn redundant_bound() -> u8
+where
+    B: A<X = u8>
+{
+    B::get_x()
+}
+
+fn inconsistent_dup_bound() -> i32
+where
+    B: A<X = i32> + A
+{
+    B::get_x()
+}
+
+fn redundant_dup_bound() -> u8
+where
+    B: A<X = u8> + A
+{
+    B::get_x()
+}
+
+fn main () {}
diff --git a/src/test/ui/trivial-bounds-inconsistent-projection.stderr b/src/test/ui/trivial-bounds-inconsistent-projection.stderr
new file mode 100644
index 00000000000..201a041830f
--- /dev/null
+++ b/src/test/ui/trivial-bounds-inconsistent-projection.stderr
@@ -0,0 +1,57 @@
+warning: Trait bound B: A does not depend on any type or lifetime parameters
+  --> $DIR/trivial-bounds-inconsistent-projection.rs:29:1
+   |
+LL | / fn underspecified_bound() -> u8
+LL | | where
+LL | |     B: A
+LL | | {
+LL | |     B::get_x()
+LL | | }
+   | |_^
+   |
+   = note: #[warn(trivial_bounds)] on by default
+
+warning: Trait bound B: A does not depend on any type or lifetime parameters
+  --> $DIR/trivial-bounds-inconsistent-projection.rs:36:1
+   |
+LL | / fn inconsistent_bound() -> i32
+LL | | where
+LL | |     B: A<X = i32>
+LL | | {
+LL | |     B::get_x()
+LL | | }
+   | |_^
+
+warning: Trait bound B: A does not depend on any type or lifetime parameters
+  --> $DIR/trivial-bounds-inconsistent-projection.rs:43:1
+   |
+LL | / fn redundant_bound() -> u8
+LL | | where
+LL | |     B: A<X = u8>
+LL | | {
+LL | |     B::get_x()
+LL | | }
+   | |_^
+
+warning: Trait bound B: A does not depend on any type or lifetime parameters
+  --> $DIR/trivial-bounds-inconsistent-projection.rs:50:1
+   |
+LL | / fn inconsistent_dup_bound() -> i32
+LL | | where
+LL | |     B: A<X = i32> + A
+LL | | {
+LL | |     B::get_x()
+LL | | }
+   | |_^
+
+warning: Trait bound B: A does not depend on any type or lifetime parameters
+  --> $DIR/trivial-bounds-inconsistent-projection.rs:57:1
+   |
+LL | / fn redundant_dup_bound() -> u8
+LL | | where
+LL | |     B: A<X = u8> + A
+LL | | {
+LL | |     B::get_x()
+LL | | }
+   | |_^
+