Skip to content

Ambiguous associated item lint triggered when an enum member is named 'Error' #1097

@KodrAus

Description

@KodrAus

On rustc 1.81.0-nightly (ed7e35f34 2024-07-06) the following code will trigger the ambiguous_associated_items warning:

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum SeverityNumber {
    Error = 1,
}

The issue appears to be the generated TryFrom impl:

impl ::core::convert::TryFrom<i32> for SeverityNumber {
    type Error = ::prost::UnknownEnumValue;
    fn try_from(value: i32) -> ::core::result::Result<SeverityNumber, Self::Error> {
        match value {
            1 => ::core::result::Result::Ok(SeverityNumber::Error),
            _ => ::core::result::Result::Err(::prost::UnknownEnumValue(value)),
        }
    }
}

It needs to disambiguate Self::Error:

impl ::core::convert::TryFrom<i32> for SeverityNumber {
    type Error = ::prost::UnknownEnumValue;
    fn try_from(value: i32) -> ::core::result::Result<SeverityNumber, <Self as ::core::convert::TryFrom<i32>>::Error> {
        match value {
            1 => ::core::result::Result::Ok(SeverityNumber::Error),
            _ => ::core::result::Result::Err(::prost::UnknownEnumValue(value)),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions