]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / tests / ui / type-alias-enum-variants / enum-variant-priority-lint-ambiguous_associated_items.rs
1 // Check that a projection `Self::V` in a trait implementation,
2 // with an associated type named `V`, for an `enum` with a variant named `V`,
3 // results in triggering the deny-by-default lint `ambiguous_associated_items`.
4 // The lint suggests that qualified syntax should be used instead.
5 // That is, the user would write `<Self as Tr>::V`.
6 //
7 // The rationale for this is that while `enum` variants do currently
8 // not exist in the type namespace but solely in the value namespace,
9 // RFC #2593 "Enum variant types", would add enum variants to the type namespace.
10 // However, currently `enum` variants are resolved with high priority as
11 // they are resolved as inherent associated items.
12 // Should #2953 therefore be implemented, `Self::V` would suddenly switch
13 // from referring to the associated type `V` instead of the variant `V`.
14 // The lint exists to keep us forward compatible with #2593.
15 //
16 // As a closing note, provided that #2933 was implemented and
17 // if `enum` variants were given lower priority than associated types,
18 // it would be impossible to refer to the `enum` variant `V` whereas
19 // the associated type could be referred to with qualified syntax as seen above.
20
21 enum E {
22     V
23 }
24
25 trait Tr {
26     type V;
27     fn f() -> Self::V;
28 }
29
30 impl Tr for E {
31     type V = u8;
32     fn f() -> Self::V { 0 }
33     //~^ ERROR ambiguous associated item
34     //~| ERROR ambiguous associated item
35     //~| WARN this was previously accepted
36     //~| WARN this was previously accepted
37     //~| HELP use fully-qualified syntax
38     //~| HELP use fully-qualified syntax
39 }
40
41 fn main() {}