rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.36k stars 12.72k forks source link

Tracking issue for future-incompatbility lint `ambiguous_associated_items` #57644

Open petrochenkov opened 5 years ago

petrochenkov commented 5 years ago

What is this lint about

With variants being resolved as inherent associated items (https://github.com/rust-lang/rfcs/pull/2338) code like this become ambiguous:

enum E {
    V
}

trait Tr {
    type V;
    fn f() -> Self::V;
}

impl Tr for E {
    type V = u8;
    fn f() -> Self::V { 0 } // `Self::V` in type namespace may refer to both variant and associated type
}

This is not a problem right now, because variants cannot be used in type positions, but it may become a problem in the future if https://github.com/rust-lang/rfcs/pull/2593 is accepted. So this lints warns against cases like this and recommends to rewrite them as <Self as Tr>::V.

How to fix this warning/error

Explicitly disambiguate in favor of associated types from traits: <Type as Trait>::Ambiguous.

Current status

mkpankov commented 4 years ago

Self::V in type namespace may refer to both variant and associated type

How is a variant present in type namespace? Syntactically only type is possible in that position, a function can't return a variant of an enum.