summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/bound/same-crate-name.rs
blob: 8d646a414599c1264922f3b951128d22ff7f5725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// aux-build:crate_a1.rs
// aux-build:crate_a2.rs

// Issue 22750
// This tests the extra help message reported when a trait bound
// is not met but the struct implements a trait with the same path.

fn main() {
    let foo = {
        extern crate crate_a2 as a;
        a::Foo
    };

    let implements_no_traits = {
        extern crate crate_a2 as a;
        a::DoesNotImplementTrait
    };

    let other_variant_implements_mismatched_trait = {
        extern crate crate_a2 as a;
        a::ImplementsWrongTraitConditionally { _marker: std::marker::PhantomData::<isize> }
    };

    let other_variant_implements_correct_trait = {
        extern crate crate_a1 as a;
        a::ImplementsTraitForUsize { _marker: std::marker::PhantomData::<isize> }
    };

    {
        extern crate crate_a1 as a;
        a::try_foo(foo);
        //~^ ERROR E0277
        //~| trait impl with same name found
        //~| perhaps two different versions of crate `crate_a2`

        // We don't want to see the "version mismatch" help message here
        // because `implements_no_traits` has no impl for `Foo`
        a::try_foo(implements_no_traits);
        //~^ ERROR E0277

        // We don't want to see the "version mismatch" help message here
        // because `other_variant_implements_mismatched_trait`
        // does not have an impl for its `<isize>` variant,
        // only for its `<usize>` variant.
        a::try_foo(other_variant_implements_mismatched_trait);
        //~^ ERROR E0277

        // We don't want to see the "version mismatch" help message here
        // because `ImplementsTraitForUsize` only has
        // impls for the correct trait where the path is not misleading.
        a::try_foo(other_variant_implements_correct_trait);
        //~^ ERROR E0277
        //~| the trait `main::a::Bar` is implemented for `ImplementsTraitForUsize<usize>`
    }
}