Skip to content

Commit

Permalink
Update syn to v2
Browse files Browse the repository at this point in the history
This requires bumping MSRV to 1.56.
  • Loading branch information
mwkmwkmwk authored and meithecatte committed Apr 1, 2023
1 parent c898257 commit d43378e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
keywords = ["enum", "bitflag", "flag", "bitflags"]
documentation = "https://docs.rs/enumflags2"
edition = "2018"
rust-version = "1.41.1"
rust-version = "1.56"

[dependencies.enumflags2_derive]
version = "=0.7.4"
Expand Down
4 changes: 2 additions & 2 deletions enumflags_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/NieDzejkob/enumflags2"
keywords = ["enum", "bitflag", "flag", "bitflags"]
edition = "2018"
rust-version = "1.41.1"
rust-version = "1.56"

[lib]
proc-macro = true

[dependencies]
syn = { version = "^1.0", features = ["full"] }
syn = { version = "^2.0", features = ["full"] }
quote = "^1.0"
proc-macro2 = "^1.0"
29 changes: 12 additions & 17 deletions enumflags_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,18 @@ fn infer_values(flags: &mut [Flag], type_name: &Ident, repr: &Ident) {
/// Given a list of attributes, find the `repr`, if any, and return the integer
/// type specified.
fn extract_repr(attrs: &[syn::Attribute]) -> Result<Option<Ident>, syn::Error> {
use syn::{Meta, NestedMeta};
attrs
.iter()
.find_map(|attr| match attr.parse_meta() {
Err(why) => Some(Err(syn::Error::new_spanned(
attr,
format!("Couldn't parse attribute: {}", why),
))),
Ok(Meta::List(ref meta)) if meta.path.is_ident("repr") => {
meta.nested.iter().find_map(|mi| match mi {
NestedMeta::Meta(Meta::Path(path)) => path.get_ident().cloned().map(Ok),
_ => None,
})
}
Ok(_) => None,
})
.transpose()
let mut res = None;
for attr in attrs {
if attr.path().is_ident("repr") {
attr.parse_nested_meta(|meta| {
if let Some(ident) = meta.path.get_ident() {
res = Some(ident.clone());
}
Ok(())
})?;
}
}
Ok(res)
}

/// Check the repr and return the number of bits available
Expand Down

0 comments on commit d43378e

Please sign in to comment.