Skip to content

Commit f5f1144

Browse files
committed
type-alias-enum-variants-priority: elaborate on why this exists.
1 parent 4f66364 commit f5f1144

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/test/ui/type-alias-enum-variants/type-alias-enum-variants-priority.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
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+
121
enum E {
222
V
323
}

src/test/ui/type-alias-enum-variants/type-alias-enum-variants-priority.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: ambiguous associated item
2-
--> $DIR/type-alias-enum-variants-priority.rs:12:15
2+
--> $DIR/type-alias-enum-variants-priority.rs:32:15
33
|
44
LL | fn f() -> Self::V { 0 }
55
| ^^^^^^^ help: use fully-qualified syntax: `<E as Trait>::V`
@@ -8,12 +8,12 @@ LL | fn f() -> Self::V { 0 }
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
1010
note: `V` could refer to variant defined here
11-
--> $DIR/type-alias-enum-variants-priority.rs:2:5
11+
--> $DIR/type-alias-enum-variants-priority.rs:22:5
1212
|
1313
LL | V
1414
| ^
1515
note: `V` could also refer to associated type defined here
16-
--> $DIR/type-alias-enum-variants-priority.rs:6:5
16+
--> $DIR/type-alias-enum-variants-priority.rs:26:5
1717
|
1818
LL | type V;
1919
| ^^^^^^^

0 commit comments

Comments
 (0)