From fd7c783efb8e6dcf9d42de638921882588dbaa17 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 8 May 2021 00:53:17 +0200 Subject: [PATCH] Moving to MSRV 1.36.0 --- .github/workflows/build.yml | 14 ++++ Cargo.lock | 132 +++++++++++++++---------------- README.md | 8 +- derive/src/display.rs | 50 ++++++------ derive/src/util.rs | 4 +- derive/src/wrapper.rs | 152 ++++++++++++++++++------------------ src/hex.rs | 1 - syn/src/attr.rs | 2 +- syn/src/cls.rs | 2 - syn/src/error.rs | 4 +- syn/src/req.rs | 46 ++++++----- 11 files changed, 214 insertions(+), 201 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3b21645..cc337dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,6 +50,20 @@ jobs: with: command: build args: --workspace --all-targets --all-features + ancient: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install rust 1.36.0 + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.36.0 + override: true + - name: All features + uses: actions-rs/cargo@v1 + with: + command: build + args: --all-features dependency: runs-on: ubuntu-latest steps: diff --git a/Cargo.lock b/Cargo.lock index d90909c..ff2414d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,179 +1,162 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - [[package]] name = "amplify" version = "3.5.1" dependencies = [ - "amplify_derive", - "amplify_syn", - "bincode", - "libc", - "parse_arg", - "serde", - "serde_json", - "serde_yaml", + "amplify_derive 2.7.0", + "amplify_syn 1.1.3", + "bincode 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)", + "parse_arg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_yaml 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", "stringly_conversions 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "toml", + "toml 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "amplify_derive" version = "2.7.0" dependencies = [ - "amplify", - "amplify_syn", - "proc-macro2", - "quote", - "syn", + "amplify 3.5.1", + "amplify_syn 1.1.3", + "proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.72 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "amplify_syn" version = "1.1.3" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.72 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bincode" version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "serde", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "dtoa" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" [[package]] name = "itoa" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "libc" version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "linked-hash-map" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "parse_arg" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14248cc8eced350e20122a291613de29e4fa129ba2731818c4cdbb44fccd3e55" [[package]] name = "paste" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "proc-macro2" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "serde" version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ - "serde_derive", + "serde_derive 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.72 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_json" version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ - "itoa", - "ryu", - "serde", + "itoa 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_str_helpers" version = "0.1.2" dependencies = [ - "serde", - "serde_derive", - "serde_json", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_str_helpers" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b744a7c94f2f3785496af33a0d93857dfc0c521e25c38e993e9c5bb45f09c841" dependencies = [ - "serde", - "serde_derive", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_yaml" version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23" dependencies = [ - "dtoa", - "linked-hash-map", - "serde", - "yaml-rust", + "dtoa 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "linked-hash-map 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", + "yaml-rust 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "stringly_conversions" version = "0.1.1" dependencies = [ - "paste", + "paste 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_str_helpers 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -181,9 +164,8 @@ dependencies = [ name = "stringly_conversions" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff63080f492dd4d289ffcaed8d7ece38adfb423db910eb342c0e04d409536a7a" dependencies = [ - "paste", + "paste 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_str_helpers 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -191,33 +173,51 @@ dependencies = [ name = "syn" version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "toml" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "serde", + "serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "yaml-rust" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ - "linked-hash-map", -] + "linked-hash-map 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum bincode 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +"checksum dtoa 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" +"checksum itoa 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +"checksum libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)" = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +"checksum linked-hash-map 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" +"checksum parse_arg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "14248cc8eced350e20122a291613de29e4fa129ba2731818c4cdbb44fccd3e55" +"checksum paste 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" +"checksum proc-macro2 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +"checksum quote 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +"checksum serde 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)" = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +"checksum serde_derive 1.0.125 (registry+https://github.com/rust-lang/crates.io-index)" = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +"checksum serde_json 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)" = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +"checksum serde_str_helpers 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b744a7c94f2f3785496af33a0d93857dfc0c521e25c38e993e9c5bb45f09c841" +"checksum serde_yaml 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23" +"checksum stringly_conversions 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ff63080f492dd4d289ffcaed8d7ece38adfb423db910eb342c0e04d409536a7a" +"checksum syn 1.0.72 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +"checksum toml 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +"checksum unicode-xid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +"checksum yaml-rust 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" diff --git a/README.md b/README.md index b080d3d..8b4cd00 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Amplifying Rust language capabilities: multiple generic trait implementations, type wrappers, derive macros. Tiny library with zero non-optional dependencies. Able to work as `no_std`. -Minimum supported rust compiler version (MSRV): 1.41.1 +Minimum supported rust compiler version (MSRV): 1.36.0 (if +`stringly_conversions` feature is not used) and 1.41.1 (for +`stringly_conversions` and `serde_str_helpers` sub-crates). ## Main features @@ -153,8 +155,8 @@ cargo build --all cargo test ``` -As a reminder, minimum supported rust compiler version (MSRV) is 1.41.1, so it -can be build with either nightly, dev, stable or 1.41+ version of the rust +As a reminder, minimum supported rust compiler version (MSRV) is 1.36.0, so it +can be build with either nightly, dev, stable or 1.36+ version of the rust compiler. Use `rustup` for getting the proper version, or add `+toolchain` parameter to both `cargo build` and `cargo test` commands. diff --git a/derive/src/display.rs b/derive/src/display.rs index 35ae0e2..67e17ba 100644 --- a/derive/src/display.rs +++ b/derive/src/display.rs @@ -47,14 +47,14 @@ impl FormattingTrait { )), |segment| { Ok(match segment.ident.to_string().as_str() { - "Debug" => Some(Self::Debug), - "Octal" => Some(Self::Octal), - "Binary" => Some(Self::Binary), - "Pointer" => Some(Self::Pointer), - "LowerHex" => Some(Self::LowerHex), - "UpperHex" => Some(Self::UpperHex), - "LowerExp" => Some(Self::LowerExp), - "UpperExp" => Some(Self::UpperExp), + "Debug" => Some(FormattingTrait::Debug), + "Octal" => Some(FormattingTrait::Octal), + "Binary" => Some(FormattingTrait::Binary), + "Pointer" => Some(FormattingTrait::Pointer), + "LowerHex" => Some(FormattingTrait::LowerHex), + "UpperHex" => Some(FormattingTrait::UpperHex), + "LowerExp" => Some(FormattingTrait::LowerExp), + "UpperExp" => Some(FormattingTrait::UpperExp), _ => None, }) }, @@ -137,17 +137,19 @@ impl Technique { let mut iter = list.nested.iter(); let mut res = match iter.next() { Some(NestedMeta::Lit(Lit::Str(format))) => { - Some(Self::WithFormat(format.clone(), None)) + Some(Technique::WithFormat(format.clone(), None)) } Some(NestedMeta::Meta(Meta::Path(path))) if path.is_ident("doc_comments") => { - Some(Self::DocComments(String::new())) + Some(Technique::DocComments(String::new())) } Some(NestedMeta::Meta(Meta::Path(path))) if path.is_ident("inner") => { - Some(Self::Inner) + Some(Technique::Inner) } Some(NestedMeta::Meta(Meta::Path(path))) => Some( FormattingTrait::from_path(path, list.span())? - .map_or(Self::FromMethod(path.clone()), |fmt| Self::FromTrait(fmt)), + .map_or(Technique::FromMethod(path.clone()), |fmt| { + Technique::FromTrait(fmt) + }), ), Some(_) => err!(span, "argument must be a string literal"), None => err!(span, "argument is required"), @@ -180,7 +182,7 @@ impl Technique { Some(Meta::NameValue(MetaNameValue { lit: Lit::Str(format), .. - })) => Some(Self::WithFormat(format, None)), + })) => Some(Technique::WithFormat(format, None)), Some(_) => err!(span, "argument must be a string literal"), None => None, }; @@ -193,9 +195,9 @@ impl Technique { pub fn to_fmt(&self, alt: bool) -> TokenStream2 { match self { - Self::FromTrait(fmt) => fmt.to_fmt(alt), - Self::FromMethod(_) => quote! { "{}" }, - Self::WithFormat(fmt, fmt_alt) => { + Technique::FromTrait(fmt) => fmt.to_fmt(alt), + Technique::FromMethod(_) => quote! { "{}" }, + Technique::WithFormat(fmt, fmt_alt) => { if alt && fmt_alt.is_some() { let alt = fmt_alt .as_ref() @@ -205,8 +207,8 @@ impl Technique { quote! {#fmt} } } - Self::DocComments(doc) => quote! { #doc }, - Self::Inner => { + Technique::DocComments(doc) => quote! { #doc }, + Technique::Inner => { if alt { quote! { "{_0:#}" } } else { @@ -310,20 +312,20 @@ impl Technique { .replace("{9", "{_9") } - if let Self::WithFormat(fmt, x) = self { - *self = Self::WithFormat( + if let Technique::WithFormat(fmt, x) = self { + *self = Technique::WithFormat( LitStr::new(&fix(&fmt.value()), Span::call_site()), x.clone(), ); } - if let Self::WithFormat(x, Some(fmt)) = self { - *self = Self::WithFormat( + if let Technique::WithFormat(x, Some(fmt)) = self { + *self = Technique::WithFormat( x.clone(), Some(LitStr::new(&fix(&fmt.value()), Span::call_site())), ); } - if let Self::DocComments(fmt) = self { - *self = Self::DocComments(fix(fmt)) + if let Technique::DocComments(fmt) = self { + *self = Technique::DocComments(fix(fmt)) } } } diff --git a/derive/src/util.rs b/derive/src/util.rs index eaaf0bb..6a68d1d 100644 --- a/derive/src/util.rs +++ b/derive/src/util.rs @@ -53,13 +53,13 @@ pub(crate) fn get_amplify_crate(input: &DeriveInput) -> Path { let example = "#[amplify_crate(amplify_crate_path)]"; let default = Path::from(Ident::new("amplify", input.span())); - let list = match attr_list(&input.attrs, name, example).ok().flatten() { + let list = match attr_list(&input.attrs, name, example).ok().unwrap_or(None) { Some(x) => x, None => return default, }; nested_one_path(&list, name, example) .ok() - .flatten() + .unwrap_or(None) .unwrap_or(default) } diff --git a/derive/src/wrapper.rs b/derive/src/wrapper.rs index 938d097..ec8e9e3 100644 --- a/derive/src/wrapper.rs +++ b/derive/src/wrapper.rs @@ -77,44 +77,44 @@ impl WrapperDerives { )), |segment| { Ok(match segment.ident.to_string().as_str() { - "FromStr" => Some(Self::FromStr), - "Display" => Some(Self::Display), - "Debug" => Some(Self::Debug), - "Octal" => Some(Self::Octal), - "LowerHex" => Some(Self::LowerHex), - "UpperHex" => Some(Self::UpperHex), - "LowerExp" => Some(Self::LowerExp), - "UpperExp" => Some(Self::UpperExp), - "BorrowSlice" => Some(Self::BorrowSlice), - "Index" => Some(Self::Index), - "IndexMut" => Some(Self::IndexMut), - "IndexRange" => Some(Self::IndexRange), - "IndexFull" => Some(Self::IndexFull), - "IndexFrom" => Some(Self::IndexFrom), - "IndexTo" => Some(Self::IndexTo), - "IndexInclusive" => Some(Self::IndexInclusive), - "Add" => Some(Self::Add), - "Neg" => Some(Self::Neg), - "Not" => Some(Self::Not), - "Sub" => Some(Self::Sub), - "Mul" => Some(Self::Mul), - "Div" => Some(Self::Div), - "Rem" => Some(Self::Rem), - "Shl" => Some(Self::Shl), - "Shr" => Some(Self::Shr), - "BitAnd" => Some(Self::BitAnd), - "BitOr" => Some(Self::BitOr), - "BitXor" => Some(Self::BitXor), - "AddAssign" => Some(Self::AddAssign), - "SubAssign" => Some(Self::SubAssign), - "MulAssign" => Some(Self::MulAssign), - "DivAssign" => Some(Self::DivAssign), - "RemAssign" => Some(Self::RemAssign), - "ShlAssign" => Some(Self::ShlAssign), - "ShrAssign" => Some(Self::ShrAssign), - "BitAndAssign" => Some(Self::BitAndAssign), - "BitOrAssign" => Some(Self::BitOrAssign), - "BitXorAssign" => Some(Self::BitXorAssign), + "FromStr" => Some(WrapperDerives::FromStr), + "Display" => Some(WrapperDerives::Display), + "Debug" => Some(WrapperDerives::Debug), + "Octal" => Some(WrapperDerives::Octal), + "LowerHex" => Some(WrapperDerives::LowerHex), + "UpperHex" => Some(WrapperDerives::UpperHex), + "LowerExp" => Some(WrapperDerives::LowerExp), + "UpperExp" => Some(WrapperDerives::UpperExp), + "BorrowSlice" => Some(WrapperDerives::BorrowSlice), + "Index" => Some(WrapperDerives::Index), + "IndexMut" => Some(WrapperDerives::IndexMut), + "IndexRange" => Some(WrapperDerives::IndexRange), + "IndexFull" => Some(WrapperDerives::IndexFull), + "IndexFrom" => Some(WrapperDerives::IndexFrom), + "IndexTo" => Some(WrapperDerives::IndexTo), + "IndexInclusive" => Some(WrapperDerives::IndexInclusive), + "Add" => Some(WrapperDerives::Add), + "Neg" => Some(WrapperDerives::Neg), + "Not" => Some(WrapperDerives::Not), + "Sub" => Some(WrapperDerives::Sub), + "Mul" => Some(WrapperDerives::Mul), + "Div" => Some(WrapperDerives::Div), + "Rem" => Some(WrapperDerives::Rem), + "Shl" => Some(WrapperDerives::Shl), + "Shr" => Some(WrapperDerives::Shr), + "BitAnd" => Some(WrapperDerives::BitAnd), + "BitOr" => Some(WrapperDerives::BitOr), + "BitXor" => Some(WrapperDerives::BitXor), + "AddAssign" => Some(WrapperDerives::AddAssign), + "SubAssign" => Some(WrapperDerives::SubAssign), + "MulAssign" => Some(WrapperDerives::MulAssign), + "DivAssign" => Some(WrapperDerives::DivAssign), + "RemAssign" => Some(WrapperDerives::RemAssign), + "ShlAssign" => Some(WrapperDerives::ShlAssign), + "ShrAssign" => Some(WrapperDerives::ShrAssign), + "BitAndAssign" => Some(WrapperDerives::BitAndAssign), + "BitOrAssign" => Some(WrapperDerives::BitOrAssign), + "BitXorAssign" => Some(WrapperDerives::BitXorAssign), _ => None, }) }, @@ -128,7 +128,7 @@ impl WrapperDerives { let amplify_crate = get_amplify_crate(&input); match self { - Self::FromStr => quote! { + WrapperDerives::FromStr => quote! { impl #impl_generics ::std::str::FromStr for #ident_name #ty_generics #where_clause { type Err = <::Inner as ::std::str::FromStr>::Err; @@ -143,7 +143,7 @@ impl WrapperDerives { } } }, - Self::Display => quote! { + WrapperDerives::Display => quote! { impl #impl_generics ::std::fmt::Display for #ident_name #ty_generics #where_clause { #[inline] @@ -153,7 +153,7 @@ impl WrapperDerives { } } }, - Self::Debug => quote! { + WrapperDerives::Debug => quote! { impl #impl_generics ::std::fmt::Debug for #ident_name #ty_generics #where_clause { #[inline] @@ -163,7 +163,7 @@ impl WrapperDerives { } } }, - Self::Octal => quote! { + WrapperDerives::Octal => quote! { impl #impl_generics ::std::fmt::Octal for #ident_name #ty_generics #where_clause { #[inline] @@ -173,7 +173,7 @@ impl WrapperDerives { } } }, - Self::LowerHex => quote! { + WrapperDerives::LowerHex => quote! { impl #impl_generics ::std::fmt::LowerHex for #ident_name #ty_generics #where_clause { #[inline] @@ -183,7 +183,7 @@ impl WrapperDerives { } } }, - Self::UpperHex => quote! { + WrapperDerives::UpperHex => quote! { impl #impl_generics ::std::fmt::UpperHex for #ident_name #ty_generics #where_clause { #[inline] @@ -193,7 +193,7 @@ impl WrapperDerives { } } }, - Self::LowerExp => quote! { + WrapperDerives::LowerExp => quote! { impl #impl_generics ::std::fmt::LowerExp for #ident_name #ty_generics #where_clause { #[inline] @@ -203,7 +203,7 @@ impl WrapperDerives { } } }, - Self::UpperExp => quote! { + WrapperDerives::UpperExp => quote! { impl #impl_generics ::std::fmt::UpperExp for #ident_name #ty_generics #where_clause { #[inline] @@ -213,7 +213,7 @@ impl WrapperDerives { } } }, - Self::BorrowSlice => quote! { + WrapperDerives::BorrowSlice => quote! { impl #impl_generics ::core::borrow::Borrow<[u8]> for #ident_name #ty_generics #where_clause { #[inline] @@ -223,7 +223,7 @@ impl WrapperDerives { } } }, - Self::Index => { + WrapperDerives::Index => { let where_clause = match where_clause { None => quote! { where }, Some(_) => quote! { #where_clause }, @@ -241,7 +241,7 @@ impl WrapperDerives { } } } - Self::IndexMut => { + WrapperDerives::IndexMut => { let where_clause = match where_clause { None => quote! { where }, Some(_) => quote! { #where_clause }, @@ -257,7 +257,7 @@ impl WrapperDerives { } } } - Self::IndexRange => { + WrapperDerives::IndexRange => { quote! { impl <#impl_generics_params> ::core::ops::Index<::core::ops::Range> for #ident_name #ty_generics #where_clause { @@ -271,7 +271,7 @@ impl WrapperDerives { } } } - Self::IndexFrom => { + WrapperDerives::IndexFrom => { quote! { impl <#impl_generics_params> ::core::ops::Index<::core::ops::RangeFrom> for #ident_name #ty_generics #where_clause { @@ -285,7 +285,7 @@ impl WrapperDerives { } } } - Self::IndexTo => { + WrapperDerives::IndexTo => { quote! { impl <#impl_generics_params> ::core::ops::Index<::core::ops::RangeTo> for #ident_name #ty_generics #where_clause { @@ -299,7 +299,7 @@ impl WrapperDerives { } } } - Self::IndexInclusive => { + WrapperDerives::IndexInclusive => { quote! { impl <#impl_generics_params> ::core::ops::Index<::core::ops::RangeInclusive> for #ident_name #ty_generics #where_clause { @@ -313,7 +313,7 @@ impl WrapperDerives { } } } - Self::IndexFull => { + WrapperDerives::IndexFull => { quote! { impl <#impl_generics_params> ::core::ops::Index<::core::ops::RangeFull> for #ident_name #ty_generics #where_clause { @@ -327,7 +327,7 @@ impl WrapperDerives { } } } - Self::Neg => quote! { + WrapperDerives::Neg => quote! { impl #impl_generics ::core::ops::Neg for #ident_name #ty_generics #where_clause { type Output = Self; @@ -339,7 +339,7 @@ impl WrapperDerives { } } }, - Self::Not => quote! { + WrapperDerives::Not => quote! { impl #impl_generics ::core::ops::Not for #ident_name #ty_generics #where_clause { type Output = Self; @@ -351,7 +351,7 @@ impl WrapperDerives { } } }, - Self::Add => quote! { + WrapperDerives::Add => quote! { impl #impl_generics ::core::ops::Add for #ident_name #ty_generics #where_clause { type Output = Self; @@ -363,7 +363,7 @@ impl WrapperDerives { } } }, - Self::Sub => quote! { + WrapperDerives::Sub => quote! { impl #impl_generics ::core::ops::Sub for #ident_name #ty_generics #where_clause { type Output = Self; @@ -375,7 +375,7 @@ impl WrapperDerives { } } }, - Self::Mul => quote! { + WrapperDerives::Mul => quote! { impl #impl_generics ::core::ops::Mul for #ident_name #ty_generics #where_clause { type Output = Self; @@ -387,7 +387,7 @@ impl WrapperDerives { } } }, - Self::Div => quote! { + WrapperDerives::Div => quote! { impl #impl_generics ::core::ops::Div for #ident_name #ty_generics #where_clause { type Output = Self; @@ -399,7 +399,7 @@ impl WrapperDerives { } } }, - Self::Rem => quote! { + WrapperDerives::Rem => quote! { impl #impl_generics ::core::ops::Rem for #ident_name #ty_generics #where_clause { type Output = Self; @@ -411,7 +411,7 @@ impl WrapperDerives { } } }, - Self::Shl => quote! { + WrapperDerives::Shl => quote! { impl #impl_generics ::core::ops::Shl for #ident_name #ty_generics #where_clause { type Output = Self; @@ -423,7 +423,7 @@ impl WrapperDerives { } } }, - Self::Shr => quote! { + WrapperDerives::Shr => quote! { impl #impl_generics ::core::ops::Shr for #ident_name #ty_generics #where_clause { type Output = Self; @@ -435,7 +435,7 @@ impl WrapperDerives { } } }, - Self::BitAnd => quote! { + WrapperDerives::BitAnd => quote! { impl #impl_generics ::core::ops::BitAnd for #ident_name #ty_generics #where_clause { type Output = Self; @@ -447,7 +447,7 @@ impl WrapperDerives { } } }, - Self::BitOr => quote! { + WrapperDerives::BitOr => quote! { impl #impl_generics ::core::ops::BitOr for #ident_name #ty_generics #where_clause { type Output = Self; @@ -459,7 +459,7 @@ impl WrapperDerives { } } }, - Self::BitXor => quote! { + WrapperDerives::BitXor => quote! { impl #impl_generics ::core::ops::BitXor for #ident_name #ty_generics #where_clause { type Output = Self; @@ -471,7 +471,7 @@ impl WrapperDerives { } } }, - Self::AddAssign => quote! { + WrapperDerives::AddAssign => quote! { impl #impl_generics ::core::ops::AddAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -481,7 +481,7 @@ impl WrapperDerives { } } }, - Self::SubAssign => quote! { + WrapperDerives::SubAssign => quote! { impl #impl_generics ::core::ops::SubAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -491,7 +491,7 @@ impl WrapperDerives { } } }, - Self::MulAssign => quote! { + WrapperDerives::MulAssign => quote! { impl #impl_generics ::core::ops::MulAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -501,7 +501,7 @@ impl WrapperDerives { } } }, - Self::DivAssign => quote! { + WrapperDerives::DivAssign => quote! { impl #impl_generics ::core::ops::DivAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -511,7 +511,7 @@ impl WrapperDerives { } } }, - Self::RemAssign => quote! {4 + WrapperDerives::RemAssign => quote! {4 impl #impl_generics ::core::ops::RemAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -521,7 +521,7 @@ impl WrapperDerives { } } }, - Self::ShlAssign => quote! { + WrapperDerives::ShlAssign => quote! { impl #impl_generics ::core::ops::ShlAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -531,7 +531,7 @@ impl WrapperDerives { } } }, - Self::ShrAssign => quote! { + WrapperDerives::ShrAssign => quote! { impl #impl_generics ::core::ops::ShrAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -541,7 +541,7 @@ impl WrapperDerives { } } }, - Self::BitAndAssign => quote! { + WrapperDerives::BitAndAssign => quote! { impl #impl_generics ::core::ops::BitAndAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -551,7 +551,7 @@ impl WrapperDerives { } } }, - Self::BitOrAssign => quote! { + WrapperDerives::BitOrAssign => quote! { impl #impl_generics ::core::ops::BitOrAssign for #ident_name #ty_generics #where_clause { #[inline] @@ -561,7 +561,7 @@ impl WrapperDerives { } } }, - Self::BitXorAssign => quote! { + WrapperDerives::BitXorAssign => quote! { impl #impl_generics ::core::ops::BitXorAssign for #ident_name #ty_generics #where_clause { #[inline] diff --git a/src/hex.rs b/src/hex.rs index f003f57..bf20397 100644 --- a/src/hex.rs +++ b/src/hex.rs @@ -17,7 +17,6 @@ //! # Hex encoding and decoding use core::{fmt, str}; -use Hash; /// Hex decoding error #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/syn/src/attr.rs b/syn/src/attr.rs index 50a3553..6ee5c87 100644 --- a/syn/src/attr.rs +++ b/syn/src/attr.rs @@ -563,7 +563,7 @@ impl ParametrizedAttr { MetaArg::Literal(Lit::Bool(_)) if self.bool.is_some() => { return Err(Error::MultipleLiteralValues(self.name.clone())) } - MetaArg::Literal(Lit::Bool(lit)) if self.bool.is_none() => { + MetaArg::Literal(Lit::Bool(ref lit)) if self.bool.is_none() => { self.bool = Some(lit.clone()) } diff --git a/syn/src/cls.rs b/syn/src/cls.rs index 1bb2045..1aeb556 100644 --- a/syn/src/cls.rs +++ b/syn/src/cls.rs @@ -13,8 +13,6 @@ // along with this software. // If not, see . -use std::hash::Hash; -use std::fmt::{Debug}; use syn::{Type, Lit}; use crate::{Error, ArgValue}; diff --git a/syn/src/error.rs b/syn/src/error.rs index 50e0d61..f8f5f57 100644 --- a/syn/src/error.rs +++ b/syn/src/error.rs @@ -13,6 +13,8 @@ // along with this software. // If not, see . +#![allow(deprecated)] // We need this at mod level to support rustc 1.26.0 + use std::fmt::{Display, Formatter, self}; use std::convert::Infallible; use proc_macro2::Span; @@ -229,7 +231,6 @@ impl Display for Error { name = name ) } - #[allow(deprecated)] Error::NestedListsNotSupported(name) => write!( f, "Attribute `{name}` must be in `{name} = ...` form and a nested list", @@ -281,7 +282,6 @@ impl std::error::Error for Error { | Error::AttributeUnknownArgument { .. } | Error::ArgNumberExceedsMax { .. } | Error::ArgValueTypeMismatch { .. } => None, - #[allow(deprecated)] Error::NestedListsNotSupported(_) => None, } } diff --git a/syn/src/req.rs b/syn/src/req.rs index 33672c1..44488a5 100644 --- a/syn/src/req.rs +++ b/syn/src/req.rs @@ -152,14 +152,14 @@ impl ArgValueReq { arg: impl ToString, ) -> Result<(), Error> { let value = match (value, self) { - (val, ArgValueReq::Required { default: None, .. }) if val.is_none() => { + (ref val, ArgValueReq::Required { default: None, .. }) if val.is_none() => { return Err(Error::ArgValueRequired { attr: attr.to_string(), arg: arg.to_string(), }) } - (val, ArgValueReq::Prohibited) if val.is_some() => { + (ref val, ArgValueReq::Prohibited) if val.is_some() => { return Err(Error::ArgMustNotHaveValue { attr: attr.to_string(), arg: arg.to_string(), @@ -167,7 +167,7 @@ impl ArgValueReq { } ( - val, + ref val, ArgValueReq::Required { default: Some(d), .. }, @@ -181,18 +181,17 @@ impl ArgValueReq { ); } - ( - val, - ArgValueReq::Required { - default: Some(d), .. - }, - ) if val.is_none() => { - *val = d.clone(); + (val, req) => { + if val.is_none() { + if let ArgValueReq::Required { + default: Some(d), .. + } = req + { + *val = d.clone(); + } + } val } - - // We are fine here - (val, _) => val, }; if let Some(value_class) = self.value_class() { @@ -241,24 +240,23 @@ impl ValueReq { arg: impl ToString, ) -> Result<(), Error> where - T: Clone + Into, - ArgValue: TryInto, + T: Clone, + ArgValue: From + TryInto, Error: From<>::Error>, { let attr = attr.to_string(); + let arg_value = ArgValue::from(value.clone()); match (self, value) { - (ValueReq::Required, v) if v.clone().into().is_none() => Err(Error::ArgValueRequired { + (ValueReq::Required, _) if arg_value.is_none() => Err(Error::ArgValueRequired { attr: attr.to_string(), arg: arg.to_string(), }), - (ValueReq::Prohibited, v) if v.clone().into().is_some() => { - Err(Error::ArgMustNotHaveValue { - attr: attr.to_string(), - arg: arg.to_string(), - }) - } - (ValueReq::Default(ref val), v) if v.clone().into().is_none() => { - *v = val.clone().try_into()?; + (ValueReq::Prohibited, _) if arg_value.is_some() => Err(Error::ArgMustNotHaveValue { + attr: attr.to_string(), + arg: arg.to_string(), + }), + (ValueReq::Default(ref val), ref mut v) if arg_value.is_none() => { + **v = val.clone().try_into()?; Ok(()) } _ => Ok(()),