about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2015-11-28 11:42:25 +0100
committerFlorian Hahn <flo@fhahn.com>2016-01-02 19:46:31 +0100
commit6093ea8039d4bf48ef2b34ca0ec1397016bb2b52 (patch)
treef549da118a945538fa2d66c71e7947aef3ba0650 /src/test
parent2c52cb424a3fdad4888dd7b73eb2c19dbd75fc2d (diff)
downloadrust-6093ea8039d4bf48ef2b34ca0ec1397016bb2b52.tar.gz
rust-6093ea8039d4bf48ef2b34ca0ec1397016bb2b52.zip
Add more tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs (renamed from src/test/compile-fail/issue-21659-show-relevant-trait-impls.rs)0
-rw-r--r--src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs46
-rw-r--r--src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs34
3 files changed, 80 insertions, 0 deletions
diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls.rs b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs
index 416eef4ad25..416eef4ad25 100644
--- a/src/test/compile-fail/issue-21659-show-relevant-trait-impls.rs
+++ b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs
diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs
new file mode 100644
index 00000000000..07a7c98dd7f
--- /dev/null
+++ b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs
@@ -0,0 +1,46 @@
+// 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.
+
+trait Foo<A> {
+    fn foo(&self, a: A) -> A {
+        a
+    }
+}
+
+trait NotRelevant<A> {
+    fn nr(&self, a: A) -> A {
+        a
+    }
+}
+
+struct Bar;
+
+impl Foo<i8> for Bar {}
+impl Foo<i16> for Bar {}
+impl Foo<i32> for Bar {}
+
+impl Foo<u8> for Bar {}
+impl Foo<u16> for Bar {}
+impl Foo<u32> for Bar {}
+
+impl NotRelevant<usize> for Bar {}
+
+fn main() {
+    let f1 = Bar;
+
+    f1.foo(1usize);
+    //~^ error: the trait `Foo<usize>` is not implemented for the type `Bar`
+    // | help: the following implementations were found:
+    // | help:   Foo<i8>
+    // | help:   Foo<i16>
+    // | help:   Foo<i32>
+    // | help:   Foo<u8>
+    // | help: and 2 others
+}
diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs
new file mode 100644
index 00000000000..0bb944edb9d
--- /dev/null
+++ b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs
@@ -0,0 +1,34 @@
+// 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.
+
+trait Foo<A> {
+    fn foo(&self, a: A) -> A {
+        a
+    }
+}
+
+trait NotRelevant<A> {
+    fn nr(&self, a: A) -> A {
+        a
+    }
+}
+
+struct Bar;
+
+impl NotRelevant<usize> for Bar {}
+
+fn main() {
+    let f1 = Bar;
+
+    f1.foo(1usize);
+    //~^ error: method named `foo` found for type `Bar` in the current scope
+    //~| help: items from traits can only be used if the trait is implemented and in scope
+    //~| help: candidate #1: `Foo`
+}