type-alias-enum-variants-priority: elaborate on why this exists.

This commit is contained in:
Mazdak Farrokhzad 2019-06-09 03:31:36 +02:00
parent 4f66364fd4
commit f5f1144a02
2 changed files with 23 additions and 3 deletions

View File

@ -1,3 +1,23 @@
// Check that a projection `Self::V` in a trait implementation,
// with an associated type named `V`, for an `enum` with a variant named `V`,
// results in triggering the deny-by-default lint `ambiguous_associated_items`.
// The lint suggests that qualified syntax should be used instead.
// That is, the user would write `<Self as Tr>::V`.
//
// The rationale for this is that while `enum` variants do currently
// not exist in the type namespace but solely in the value namespace,
// RFC #2593 "Enum variant types", would add enum variants to the type namespace.
// However, currently `enum` variants are resolved with high priority as
// they are resolved as inherent associated items.
// Should #2953 therefore be implemented, `Self::V` would suddenly switch
// from referring to the associated type `V` instead of the variant `V`.
// The lint exists to keep us forward compatible with #2593.
//
// As a closing note, provided that #2933 was implemented and
// if `enum` variants were given lower priority than associated types,
// it would be impossible to refer to the `enum` variant `V` whereas
// the associated type could be referred to with qualified syntax as seen above.
enum E {
V
}

View File

@ -1,5 +1,5 @@
error: ambiguous associated item
--> $DIR/type-alias-enum-variants-priority.rs:12:15
--> $DIR/type-alias-enum-variants-priority.rs:32:15
|
LL | fn f() -> Self::V { 0 }
| ^^^^^^^ help: use fully-qualified syntax: `<E as Trait>::V`
@ -8,12 +8,12 @@ LL | fn f() -> Self::V { 0 }
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
note: `V` could refer to variant defined here
--> $DIR/type-alias-enum-variants-priority.rs:2:5
--> $DIR/type-alias-enum-variants-priority.rs:22:5
|
LL | V
| ^
note: `V` could also refer to associated type defined here
--> $DIR/type-alias-enum-variants-priority.rs:6:5
--> $DIR/type-alias-enum-variants-priority.rs:26:5
|
LL | type V;
| ^^^^^^^