From 770e5009e06ea3898a50cd3bf3e24a224215a22d Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 5 Jun 2025 13:50:02 +0200 Subject: [PATCH] Use fully-qualified path to refer to the associated type Prevent "ambiguous associated type" if one of the variants is named `Numeric`. --- enumflags_derive/src/lib.rs | 8 ++++---- test_suite/common.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/enumflags_derive/src/lib.rs b/enumflags_derive/src/lib.rs index cbdf139..2cdc12e 100644 --- a/enumflags_derive/src/lib.rs +++ b/enumflags_derive/src/lib.rs @@ -334,18 +334,18 @@ fn gen_enumflags(ast: &mut DeriveInput, default: Vec) -> Result::Numeric = 0; - const DEFAULT: Self::Numeric = + const DEFAULT: ::Numeric = 0 #(| (Self::#default as #repr))*; - const ALL_BITS: Self::Numeric = + const ALL_BITS: ::Numeric = 0 #(| (Self::#variant_names as #repr))*; const BITFLAGS_TYPE_NAME : &'static str = concat!("BitFlags<", stringify!(#ident), ">"); - fn bits(self) -> Self::Numeric { + fn bits(self) -> ::Numeric { self as #repr } } diff --git a/test_suite/common.rs b/test_suite/common.rs index 60b2be9..e08e0fc 100644 --- a/test_suite/common.rs +++ b/test_suite/common.rs @@ -29,6 +29,14 @@ enum Default6 { D = 1 << 3, } +#[bitflags] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[repr(u8)] +enum AssociatedTypeNameConflict { + Stringy = 1 << 0, + Numeric = 1 << 1, +} + #[test] fn test_ctors() { use enumflags2::BitFlags;