diff --git a/Cargo.toml b/Cargo.toml index 446dd48..758f1f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/enumflags_derive/Cargo.toml b/enumflags_derive/Cargo.toml index 4903161..985a619 100644 --- a/enumflags_derive/Cargo.toml +++ b/enumflags_derive/Cargo.toml @@ -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" diff --git a/enumflags_derive/src/lib.rs b/enumflags_derive/src/lib.rs index b259aa6..2845e82 100644 --- a/enumflags_derive/src/lib.rs +++ b/enumflags_derive/src/lib.rs @@ -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, 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