From 80c5e5bd4e9fa26a12097ce2ba30629ff2e6685e Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Wed, 22 Mar 2023 22:08:02 +0000 Subject: [PATCH 1/6] Update to syn-2 Also moves a test out of doctest compilefail since syn-2 will build it correctly even without the "full" feature. --- Cargo.toml | 2 +- src/lib.rs | 28 ++++++++++++++++------------ src/test.rs | 31 ------------------------------- tests/issue-16.rs | 11 +++++++++++ 4 files changed, 28 insertions(+), 44 deletions(-) delete mode 100644 src/test.rs create mode 100644 tests/issue-16.rs diff --git a/Cargo.toml b/Cargo.toml index 5addf90..1ebaa36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" [dependencies] proc-macro2 = "1" quote = "1" -syn = "1" +syn = "2" [dev-dependencies] num = "0.3" diff --git a/src/lib.rs b/src/lib.rs index ef55e4b..2ee7823 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,16 +170,22 @@ impl NumTraits { // retrieve its value, and use it to create an `Ident` to be used // to import the `num_traits` crate. for attr in &ast.attrs { - if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() { - if mnv.path.is_ident("num_traits") { - if let syn::Lit::Str(lit_str) = mnv.lit { - return NumTraits { - import: syn::Ident::new(&lit_str.value(), lit_str.span()), - explicit: true, - }; - } else { - panic!("#[num_traits] attribute value must be a str"); - } + if attr.path().is_ident("num_traits") { + if let Ok(syn::MetaNameValue { + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(ref lit_str), + .. + }), + .. + }) = attr.meta.require_name_value() + { + return NumTraits { + import: syn::Ident::new(&lit_str.value(), lit_str.span()), + explicit: true, + }; + } else { + panic!("#[num_traits] attribute value must be a str"); } } } @@ -954,5 +960,3 @@ pub fn float(input: TokenStream) -> TokenStream { import.wrap("Float", &name, impl_).into() } - -mod test; diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index c4cd7fe..0000000 --- a/src/test.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This module uses doc-tests on modules for `compile_fail` - -// We need "syn/full" to parse macros. -// Use `--nocapture` to check the quality of the error message. -#[cfg(not(feature = "full-syntax"))] -/// ```compile_fail -/// macro_rules! get_an_isize { -/// () => (0_isize) -/// } -/// -/// #[derive(num_derive::FromPrimitive)] -/// pub enum CLikeEnum { -/// VarA = get_an_isize!(), // error without "syn/full" -/// VarB = 2, -/// } -/// ``` -mod issue16 {} - -#[cfg(feature = "full-syntax")] -/// ``` -/// macro_rules! get_an_isize { -/// () => (0_isize) -/// } -/// -/// #[derive(num_derive::FromPrimitive)] -/// pub enum CLikeEnum { -/// VarA = get_an_isize!(), // ok with "syn/full" -/// VarB = 2, -/// } -/// ``` -mod issue16 {} diff --git a/tests/issue-16.rs b/tests/issue-16.rs new file mode 100644 index 0000000..48cc2fb --- /dev/null +++ b/tests/issue-16.rs @@ -0,0 +1,11 @@ +macro_rules! get_an_isize { + () => { + 0_isize + }; +} + +#[derive(num_derive::FromPrimitive)] +pub enum CLikeEnum { + VarA = get_an_isize!(), + VarB = 2, +} From 843675563540c29eb01f00a6872d520f6ffdec6b Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Thu, 23 Mar 2023 23:48:24 +0000 Subject: [PATCH 2/6] Remove full-syntax feature The primary use-case of full-syntax (complex discriminants) is now covered by syn even without full, so this feature is unnecessary. Since bumping the MSRV for syn to 1.56 is a breaking change, we can drop the full-syntax feature at the same time. --- Cargo.toml | 3 --- ci/test_full.sh | 2 +- src/lib.rs | 10 +--------- tests/with_custom_values.rs | 2 -- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ebaa36..84f774d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,6 @@ syn = "2" num = "0.3" num-traits = "0.2" -[features] -full-syntax = ["syn/full"] - [lib] name = "num_derive" proc-macro = true diff --git a/ci/test_full.sh b/ci/test_full.sh index 513fbc4..a6b7b3c 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -27,7 +27,7 @@ if ! check_version $MSRV ; then exit 1 fi -FEATURES=(full-syntax) +FEATURES=() echo "Testing supported features: ${FEATURES[*]}" set -x diff --git a/src/lib.rs b/src/lib.rs index 2ee7823..26b9c77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,19 +71,11 @@ use quote::quote; use syn::{Data, Fields, Ident}; /// Try to parse the tokens, or else return a compilation error -/// suggesting "full-syntax" if that's not already enabled. macro_rules! parse { ($tokens:ident as $type:ty) => { match syn::parse::<$type>($tokens) { Ok(parsed) => parsed, - Err(mut error) => { - if cfg!(not(feature = "full-syntax")) { - let hint = syn::Error::new( - Span::call_site(), - r#"this might need the "full-syntax" feature of `num-derive`"#, - ); - error.combine(hint); - } + Err(error) => { return TokenStream::from(error.to_compile_error()); } } diff --git a/tests/with_custom_values.rs b/tests/with_custom_values.rs index 94c8445..9b202f4 100644 --- a/tests/with_custom_values.rs +++ b/tests/with_custom_values.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(feature = "full-syntax")] - extern crate num as num_renamed; #[macro_use] extern crate num_derive; From 4ff3da1cfa6165e9dc380a3bc82789fc949f7e9e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 29 Jun 2023 19:11:04 -0700 Subject: [PATCH 3/6] Need minimal syn 2.0.5 to pass tests --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 84f774d..faaf55d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" [dependencies] proc-macro2 = "1" quote = "1" -syn = "2" +syn = "2.0.5" [dev-dependencies] num = "0.3" From e90d123bd34e82d9134f5faab6cf77b5b194fa16 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 29 Jun 2023 19:11:21 -0700 Subject: [PATCH 4/6] Bump to MSRV 1.56.0 --- .github/workflows/ci.yaml | 4 ++-- .github/workflows/master.yaml | 2 +- .github/workflows/pr.yaml | 4 ++-- Cargo.toml | 1 + README.md | 4 ++-- bors.toml | 2 +- ci/rustup.sh | 2 +- ci/test_full.sh | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2de7e23..19cdd28 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.31.0, stable, beta, nightly] + rust: [1.56.0, stable, beta, nightly] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@1.62.0 + - uses: dtolnay/rust-toolchain@1.70.0 with: components: rustfmt - run: cargo fmt --all --check diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index 98e8f8e..f23d140 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.31.0, stable] + rust: [1.56.0, stable] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index d221a73..e195455 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.31.0, stable] + rust: [1.56.0, stable] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@1.62.0 + - uses: dtolnay/rust-toolchain@1.70.0 with: components: rustfmt - run: cargo fmt --all --check diff --git a/Cargo.toml b/Cargo.toml index faaf55d..0a16ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ version = "0.3.3" readme = "README.md" exclude = ["/bors.toml", "/ci/*", "/.github/*"] edition = "2018" +rust-version = "1.56.0" [dependencies] proc-macro2 = "1" diff --git a/README.md b/README.md index 9826cdf..3fb9498 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-derive.svg)](https://crates.io/crates/num-derive) [![documentation](https://docs.rs/num-derive/badge.svg)](https://docs.rs/num-derive) -[![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![minimum rustc 1.56](https://img.shields.io/badge/rustc-1.56+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) [![build status](https://github.com/rust-num/num-derive/workflows/master/badge.svg)](https://github.com/rust-num/num-derive/actions) Procedural macros to derive numeric traits in Rust. @@ -51,7 +51,7 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-derive` crate is tested for rustc 1.31 and greater. +The `num-derive` crate is tested for rustc 1.56 and greater. ## License diff --git a/bors.toml b/bors.toml index 4c20337..f44ffa3 100644 --- a/bors.toml +++ b/bors.toml @@ -1,5 +1,5 @@ status = [ - "Test (1.31.0)", + "Test (1.56.0)", "Test (stable)", "Test (beta)", "Test (nightly)", diff --git a/ci/rustup.sh b/ci/rustup.sh index fed3e45..5289138 100755 --- a/ci/rustup.sh +++ b/ci/rustup.sh @@ -5,6 +5,6 @@ set -ex ci=$(dirname $0) -for version in 1.31.0 stable beta nightly; do +for version in 1.56.0 stable beta nightly; do rustup run "$version" "$ci/test_full.sh" done diff --git a/ci/test_full.sh b/ci/test_full.sh index a6b7b3c..d3fe896 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -3,7 +3,7 @@ set -e CRATE=num-derive -MSRV=1.31 +MSRV=1.56 get_rust_version() { local array=($(rustc --version)); From 678529b255a67ae0822d90285575dab1794c39cd Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 29 Jun 2023 19:17:47 -0700 Subject: [PATCH 5/6] Update to 2021 edition --- Cargo.toml | 14 +++++++++++--- tests/newtype-2018.rs | 2 ++ tests/trivial-2018.rs | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/newtype-2018.rs create mode 100644 tests/trivial-2018.rs diff --git a/Cargo.toml b/Cargo.toml index 0a16ebc..0b9f0f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/rust-num/num-derive" version = "0.3.3" readme = "README.md" exclude = ["/bors.toml", "/ci/*", "/.github/*"] -edition = "2018" +edition = "2021" rust-version = "1.56.0" [dependencies] @@ -28,13 +28,21 @@ name = "num_derive" proc-macro = true test = false -# Most of the tests are left implicily detected, compiled for Rust 2018, -# but let's try a few of them with the old 2015 edition too. +# Most of the tests are left implicily detected, compiled for Rust 2021, +# but let's try a few of them with the older editions too. [[test]] name = "newtype-2015" edition = "2015" +[[test]] +name = "newtype-2018" +edition = "2018" + [[test]] name = "trivial-2015" edition = "2015" + +[[test]] +name = "trivial-2018" +edition = "2018" diff --git a/tests/newtype-2018.rs b/tests/newtype-2018.rs new file mode 100644 index 0000000..814529e --- /dev/null +++ b/tests/newtype-2018.rs @@ -0,0 +1,2 @@ +// Same source, just compiled for 2018 edition +include!("newtype.rs"); diff --git a/tests/trivial-2018.rs b/tests/trivial-2018.rs new file mode 100644 index 0000000..92b971b --- /dev/null +++ b/tests/trivial-2018.rs @@ -0,0 +1,2 @@ +// Same source, just compiled for 2018 edition +include!("trivial.rs"); From d2fa314b70ecff4ddd90883c3a3c90600f994b53 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 29 Jun 2023 19:18:38 -0700 Subject: [PATCH 6/6] Release 0.4.0 --- Cargo.toml | 4 ++-- README.md | 2 +- RELEASES.md | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b9f0f3..a2f19e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = [ "science" ] license = "MIT OR Apache-2.0" name = "num-derive" repository = "https://github.com/rust-num/num-derive" -version = "0.3.3" +version = "0.4.0" readme = "README.md" exclude = ["/bors.toml", "/ci/*", "/.github/*"] edition = "2021" @@ -20,7 +20,7 @@ quote = "1" syn = "2.0.5" [dev-dependencies] -num = "0.3" +num = "0.4" num-traits = "0.2" [lib] diff --git a/README.md b/README.md index 3fb9498..20d66a6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] num-traits = "0.2" -num-derive = "0.3" +num-derive = "0.4" ``` and this to your crate root: diff --git a/RELEASES.md b/RELEASES.md index c3e18cc..fbb34da 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,11 @@ +# Release 0.4.0 (2023-06-29) + +- [Update to syn-2][54] -- thanks @maurer! + - This raises the minimum supported rustc to 1.56. + - The "full-syntax" feature has also been removed. + +[54]: https://github.com/rust-num/num-derive/pull/54 + # Release 0.3.3 (2020-10-29) - [Make `NumOps` work with `no_std`][41] -- thanks @jedrzejboczar!