Skip to content

Commit 035c027

Browse files
LukeMathWalkermeithecatte
authored andcommitted
Use fully-qualified path to refer to the associated type
Prevent "ambiguous associated type" if one of the variants is named `Numeric`.
1 parent 774b8e5 commit 035c027

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

enumflags_derive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,18 @@ fn gen_enumflags(ast: &mut DeriveInput, default: Vec<Ident>) -> Result<TokenStre
334334
unsafe impl ::enumflags2::_internal::RawBitFlags for #ident {
335335
type Numeric = #repr;
336336

337-
const EMPTY: Self::Numeric = 0;
337+
const EMPTY: <Self as ::enumflags2::_internal::RawBitFlags>::Numeric = 0;
338338

339-
const DEFAULT: Self::Numeric =
339+
const DEFAULT: <Self as ::enumflags2::_internal::RawBitFlags>::Numeric =
340340
0 #(| (Self::#default as #repr))*;
341341

342-
const ALL_BITS: Self::Numeric =
342+
const ALL_BITS: <Self as ::enumflags2::_internal::RawBitFlags>::Numeric =
343343
0 #(| (Self::#variant_names as #repr))*;
344344

345345
const BITFLAGS_TYPE_NAME : &'static str =
346346
concat!("BitFlags<", stringify!(#ident), ">");
347347

348-
fn bits(self) -> Self::Numeric {
348+
fn bits(self) -> <Self as ::enumflags2::_internal::RawBitFlags>::Numeric {
349349
self as #repr
350350
}
351351
}

test_suite/common.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ enum Default6 {
2929
D = 1 << 3,
3030
}
3131

32+
#[bitflags]
33+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
34+
#[repr(u8)]
35+
enum AssociatedTypeNameConflict {
36+
Stringy = 1 << 0,
37+
Numeric = 1 << 1,
38+
}
39+
3240
#[test]
3341
fn test_ctors() {
3442
use enumflags2::BitFlags;

0 commit comments

Comments
 (0)