Skip to content

fix: Enum variant named Error causes ambiguous item#1098

Merged
LucioFranco merged 1 commit intotokio-rs:masterfrom
caspermeijn:enum_variant_error
Jul 9, 2024
Merged

fix: Enum variant named Error causes ambiguous item#1098
LucioFranco merged 1 commit intotokio-rs:masterfrom
caspermeijn:enum_variant_error

Conversation

@caspermeijn
Copy link
Contributor

The generated code uses Self::Error to refer to ::prost::UnknownEnumValue, but the term Error is not unique when an enum variant is called Error. Use the full type name to resolve the ambiguity.

The compiler reported:

error: ambiguous associated item
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:2:68
    |
2   | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
    |                                                                    ^^^^^^^^^^^^^^^^^^^^
    |
    = 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: `Error` could refer to the variant defined here
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:10:5
    |
10  |     Error = 4,
    |     ^^^^^
note: `Error` could also refer to the associated type defined here
   --> /home/ircdev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:682:5
    |
682 |     type Error;
    |     ^^^^^^^^^^
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = note: this error originates in the derive macro `::prost::Enumeration` (in Nightly builds, run with -Z macro-backtrace for more info)

Fixes #1097

The generated code uses `Self::Error` to refer to `::prost::UnknownEnumValue`, but the term `Error` is not unique when an enum variant is called `Error`. Use the full type name to resolve the ambiguity.

The compiler reported:
```
error: ambiguous associated item
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:2:68
    |
2   | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
    |                                                                    ^^^^^^^^^^^^^^^^^^^^
    |
    = 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 <rust-lang/rust#57644>
note: `Error` could refer to the variant defined here
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:10:5
    |
10  |     Error = 4,
    |     ^^^^^
note: `Error` could also refer to the associated type defined here
   --> /home/ircdev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:682:5
    |
682 |     type Error;
    |     ^^^^^^^^^^
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = note: this error originates in the derive macro `::prost::Enumeration` (in Nightly builds, run with -Z macro-backtrace for more info)
```
@caspermeijn
Copy link
Contributor Author

CIFuzz is failing due to a problem not related to this change: google/oss-fuzz#12168

@LucioFranco LucioFranco added this pull request to the merge queue Jul 9, 2024
Merged via the queue into tokio-rs:master with commit 26463f4 Jul 9, 2024
@caspermeijn caspermeijn deleted the enum_variant_error branch July 10, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants