Skip to content

Commit f0a79af

Browse files
committed
Remove unnecessary cast in generated code
The cast seems to have been added as a precaution, but upon further inspection we can see that it's not necessary in any situation. Add a test to make sure this allow-by-default lint isn't triggered. Also test enums with exactly one variant, as the generated code is subtly different.
1 parent 52db1b1 commit f0a79af

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

enumflags_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn gen_enumflags(ident: &Ident, item: &DeriveInput, data: &DataEnum)
224224

225225
fn all() -> Self::Type {
226226
// make sure it's evaluated at compile time
227-
const VALUE: #ty = #all as #ty;
227+
const VALUE: #ty = #all;
228228
VALUE
229229
}
230230

test_suite/tests/not_literal.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![forbid(trivial_numeric_casts)]
2+
13
const FOO_BAR: u8 = 1;
24
const FOO_BAZ: u8 = 2;
35

@@ -7,3 +9,9 @@ enum Foo {
79
Bar = FOO_BAR,
810
Baz = FOO_BAZ,
911
}
12+
13+
#[derive(Clone, Copy, enumflags2::BitFlags)]
14+
#[repr(u8)]
15+
enum SingleTest {
16+
Hello = FOO_BAR,
17+
}

0 commit comments

Comments
 (0)