Skip to content

Commit

Permalink
Merge #54
Browse files Browse the repository at this point in the history
54: Update to syn-2 r=cuviper a=maurer

Also moves a test out of doctest compilefail since syn-2 will build it correctly even without the "full" feature.

Co-authored-by: Matthew Maurer <mmaurer@google.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people authored Jun 30, 2023
2 parents c259ebc + d2fa314 commit fce481d
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 15 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
2 changes: 1 addition & 1 deletion bors.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
status = [
"Test (1.31.0)",
"Test (1.56.0)",
"Test (stable)",
"Test (beta)",
"Test (nightly)",
Expand Down
2 changes: 1 addition & 1 deletion ci/rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CRATE=num-derive
MSRV=1.31
MSRV=1.56

get_rust_version() {
local array=($(rustc --version));
Expand All @@ -27,7 +27,7 @@ if ! check_version $MSRV ; then
exit 1
fi

FEATURES=(full-syntax)
FEATURES=()
echo "Testing supported features: ${FEATURES[*]}"

set -x
Expand Down
38 changes: 17 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -954,5 +952,3 @@ pub fn float(input: TokenStream) -> TokenStream {

import.wrap("Float", &name, impl_).into()
}

mod test;
31 changes: 0 additions & 31 deletions src/test.rs

This file was deleted.

11 changes: 11 additions & 0 deletions tests/issue-16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro_rules! get_an_isize {
() => {
0_isize
};
}

#[derive(num_derive::FromPrimitive)]
pub enum CLikeEnum {
VarA = get_an_isize!(),
VarB = 2,
}
2 changes: 2 additions & 0 deletions tests/newtype-2018.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Same source, just compiled for 2018 edition
include!("newtype.rs");
2 changes: 2 additions & 0 deletions tests/trivial-2018.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Same source, just compiled for 2018 edition
include!("trivial.rs");
2 changes: 0 additions & 2 deletions tests/with_custom_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fce481d

Please sign in to comment.