Skip to content

Commit be8c716

Browse files
committed
Minor cleanup (mostly clippy suggestions)
1 parent 021da30 commit be8c716

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

enumflags/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ where
204204

205205
/// Toggles the matching bits
206206
pub fn toggle<B: Into<BitFlags<T>>>(&mut self, other: B) {
207-
*self = *self ^ other.into();
207+
*self ^= other.into();
208208
}
209209

210210
/// Inserts the flags into the BitFlag
211211
pub fn insert<B: Into<BitFlags<T>>>(&mut self, other: B) {
212-
*self = *self | other.into();
212+
*self |= other.into();
213213
}
214214

215215
/// Removes the matching flags
216216
pub fn remove<B: Into<BitFlags<T>>>(&mut self, other: B) {
217-
*self = *self & !other.into();
217+
*self &= !other.into();
218218
}
219219

220220
/// Returns an iterator that yields each set flag

enumflags_derive/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ fn max_value_of(ty: &str) -> Option<usize> {
3333

3434
fn fold_expr(expr: &syn::Expr) -> u64 {
3535
use syn::Expr;
36-
match expr{
37-
&Expr::Lit(ref expr_lit) => {
36+
match expr {
37+
Expr::Lit(ref expr_lit) => {
3838
match expr_lit.lit {
3939
syn::Lit::Int(ref lit_int) => lit_int.base10_parse().expect("Int literal out of range"),
4040
_ => panic!("Only Int literals are supported")
4141
}
4242
},
43-
&Expr::Binary(ref expr_binary) => {
43+
Expr::Binary(ref expr_binary) => {
4444
let l = fold_expr(&expr_binary.left);
4545
let r = fold_expr(&expr_binary.right);
4646
match &expr_binary.op {
4747
syn::BinOp::Shl(_) => l << r,
4848
op => panic!("{} not supported", op.to_token_stream())
4949
}
50-
5150
}
5251
_ => panic!("Only literals are supported")
5352
}
@@ -76,13 +75,17 @@ fn extract_repr(attrs: &[syn::Attribute]) -> Option<syn::Ident> {
7675
})
7776
.nth(0)
7877
}
78+
7979
fn gen_enumflags(ident: &Ident, item: &DeriveInput, data: &DataEnum) -> TokenStream {
8080
let span = Span::call_site();
8181
let variants = data.variants.iter().map(|v| &v.ident);
82-
let flag_values: Vec<_> = data.variants.iter()
83-
.map(|v| v.discriminant.as_ref().map(|d| fold_expr(&d.1)).expect("No discriminant")).collect();
82+
let flag_values: Vec<_> =
83+
data.variants.iter()
84+
.map(|v| v.discriminant.as_ref()
85+
.map(|d| fold_expr(&d.1)).expect("No discriminant"))
86+
.collect();
8487
let variants_len = flag_values.len();
85-
assert!(flag_values.iter().find(|&&v| v == 0).is_none(), "Null flag is not allowed");
88+
assert!(flag_values.iter().all(|&v| v != 0), "Null flag is not allowed");
8689
let names = flag_values.iter().map(|_| &ident);
8790
let ty = extract_repr(&item.attrs).unwrap_or(Ident::new("usize", span));
8891
let max_flag_value = flag_values.iter().max().unwrap();
@@ -109,7 +112,7 @@ fn gen_enumflags(ident: &Ident, item: &DeriveInput, data: &DataEnum) -> TokenStr
109112
})
110113
.collect();
111114
assert!(
112-
wrong_flag_values.len() == 0,
115+
wrong_flag_values.is_empty(),
113116
format!(
114117
"The following flags are not unique: {data:?}",
115118
data = wrong_flag_values

0 commit comments

Comments
 (0)