Skip to content

Commit 62e7a87

Browse files
committed
fix: Enum variant named Error causes ambiguous item
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) ```
1 parent 23f7174 commit 62e7a87

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

prost-derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn try_enumeration(input: TokenStream) -> Result<TokenStream, Error> {
351351
impl #impl_generics ::core::convert::TryFrom::<i32> for #ident #ty_generics #where_clause {
352352
type Error = ::prost::UnknownEnumValue;
353353

354-
fn try_from(value: i32) -> ::core::result::Result<#ident, Self::Error> {
354+
fn try_from(value: i32) -> ::core::result::Result<#ident, ::prost::UnknownEnumValue> {
355355
match value {
356356
#(#try_from,)*
357357
_ => ::core::result::Result::Err(::prost::UnknownEnumValue(value)),

tests/src/enum_keyword_variant.proto

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum Feeding {
88
// Careful: code generation resulted in "Self". Now it is "Self_".
99
FEEDING_SELF = 2;
1010
FEEDING_ELSE = 3;
11+
FEEDING_ERROR = 4;
1112
}
1213

1314
enum Grooming {

0 commit comments

Comments
 (0)