Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
0123456789-jpg committed Mar 23, 2024
1 parent 5023c93 commit 54b31f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/util/edcode-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ maintenance = { status = "passively-maintained" }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
syn = { version = "2.0" }
quote = { version = "1.0" }
proc-macro2 = { version = "1.0" }
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0"

[lints]
workspace = true
Expand Down
27 changes: 12 additions & 15 deletions crates/util/edcode-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn parse_derive_enum(
let mut enum_idents: Vec<Ident> = vec![];
let mut enum_vals: Vec<Expr> = vec![];
for var in data.variants.into_iter() {
if let Fields::Unit = var.fields {
if matches!(var.fields, Fields::Unit) {
enum_idents.push(var.ident.clone());
} else {
return Err(Error::new(var.fields.span(), fields_disallowed!())
Expand Down Expand Up @@ -78,12 +78,12 @@ fn parse_derive_enum(
let mut iter = meta.tokens.into_iter().peekable();
let span = iter.peek().span();
macro_rules! ident_helper {
($span:expr => $( $ty:ident ),*) => {
vec![
$( Ident::new(stringify!($ty), $span) ),*
]
};
}
($span:expr => $( $ty:ident ),*) => {
vec![
$( Ident::new(stringify!($ty), $span) ),*
]
};
}
let supported = iter.next().is_some_and(|x| {
if let TokenTree::Ident(id) = x {
if ident_helper!(span => u8, u16, u32, u64, i8, i16, i32, i64).contains(&id)
Expand All @@ -105,14 +105,11 @@ fn parse_derive_enum(
}
}
}
let repr_type = match repr_type {
None => {
return Err(Error::new(ident.span(), repr_required!())
.into_compile_error()
.into())
}
Some(x) => x,
};
let repr_type = repr_type.ok_or_else(|| {
std::convert::Into::<TokenStream>::into(
Error::new(ident.span(), repr_required!()).into_compile_error(),
)
})?;
Ok((ident, repr_type, enum_idents, enum_vals))
}

Expand Down

0 comments on commit 54b31f9

Please sign in to comment.