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 similarity index 100% rename from src/test/compile-fail/issue-21659-show-relevant-trait-impls.rs rename to 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 000000000000..07a7c98dd7ff --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(&self, a: A) -> A { + a + } +} + +trait NotRelevant { + fn nr(&self, a: A) -> A { + a + } +} + +struct Bar; + +impl Foo for Bar {} +impl Foo for Bar {} +impl Foo for Bar {} + +impl Foo for Bar {} +impl Foo for Bar {} +impl Foo for Bar {} + +impl NotRelevant for Bar {} + +fn main() { + let f1 = Bar; + + f1.foo(1usize); + //~^ error: the trait `Foo` is not implemented for the type `Bar` + // | help: the following implementations were found: + // | help: Foo + // | help: Foo + // | help: Foo + // | help: Foo + // | 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 000000000000..0bb944edb9d8 --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(&self, a: A) -> A { + a + } +} + +trait NotRelevant { + fn nr(&self, a: A) -> A { + a + } +} + +struct Bar; + +impl NotRelevant 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` +}