]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/trait-bounds-same-crate-name.rs
fixup! Add negative tests where the diagnostic message would be wrong
[rust.git] / src / test / ui / traits / trait-bounds-same-crate-name.rs
1 // aux-build:crate_a1.rs
2 // aux-build:crate_a2.rs
3
4 // Issue 22750
5 // This tests the extra help message reported when a trait bound
6 // is not met but the struct implements a trait with the same path.
7
8 fn main() {
9     let foo = {
10         extern crate crate_a2 as a;
11         a::Foo
12     };
13
14     let implements_no_traits = {
15         extern crate crate_a2 as a;
16         a::DoesNotImplementTrait
17     };
18
19     let other_variant_implements_mismatched_trait = {
20         extern crate crate_a2 as a;
21         a::ImplementsWrongTraitConditionally { _marker: std::marker::PhantomData::<isize> }
22     };
23
24     let other_variant_implements_correct_trait = {
25         extern crate crate_a1 as a;
26         a::ImplementsTraitForUsize { _marker: std::marker::PhantomData::<isize> }
27     };
28
29     {
30         extern crate crate_a1 as a;
31         a::try_foo(foo);
32         //~^ ERROR E0277
33         //~| trait impl with same name found
34         //~| Perhaps two different versions of crate `crate_a2`
35
36         // We don't want to see the "version mismatch" help message here
37         // because `implements_no_traits` has no impl for `Foo`
38         a::try_foo(implements_no_traits);
39         //~^ ERROR E0277
40
41         // We don't want to see the "version mismatch" help message here
42         // because `other_variant_implements_mismatched_trait`
43         // does not have an impl for its `<isize>` variant,
44         // only for its `<usize>` variant.
45         a::try_foo(other_variant_implements_mismatched_trait);
46         //~^ ERROR E0277
47
48         // We don't want to see the "version mismatch" help message here
49         // because `ImplementsTraitForUsize` only has
50         // impls for the correct trait where the path is not misleading.
51         a::try_foo(other_variant_implements_correct_trait);
52         //~^ ERROR E0277
53         //~| the following implementations were found:
54     }
55 }