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 5addf90..a2f19e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,35 +8,41 @@ 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 = "2018" +edition = "2021" +rust-version = "1.56.0" [dependencies] proc-macro2 = "1" quote = "1" -syn = "1" +syn = "2.0.5" [dev-dependencies] -num = "0.3" +num = "0.4" num-traits = "0.2" -[features] -full-syntax = ["syn/full"] - [lib] 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/README.md b/README.md index 9826cdf..20d66a6 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. @@ -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: @@ -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/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! 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 513fbc4..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)); @@ -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 ef55e4b..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()); } } @@ -170,16 +162,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 +952,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, +} 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"); 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;