Skip to content

Commit

Permalink
Merge #28
Browse files Browse the repository at this point in the history
28: Update syn related dependencies to 1.0 and bump version r=cuviper a=Eijebong



Co-authored-by: Bastien Orivel <eijebong@bananium.fr>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people committed Aug 15, 2019
2 parents bbaeeb1 + d93f537 commit d0a92ae
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 81 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
@@ -1,9 +1,6 @@
language: rust
sudo: false
rust:
- 1.15.0
- 1.20.0
- 1.26.0 # has_i128
- 1.31.0 # 2018!
- stable
- beta
Expand Down
12 changes: 4 additions & 8 deletions Cargo.toml
Expand Up @@ -8,15 +8,14 @@ categories = [ "science" ]
license = "MIT/Apache-2.0"
name = "num-derive"
repository = "https://github.com/rust-num/num-derive"
version = "0.2.5"
version = "0.3.0"
readme = "README.md"
build = "build.rs"
exclude = ["/ci/*", "/.travis.yml", "/bors.toml"]

[dependencies]
proc-macro2 = "0.4.2"
quote = "0.6"
syn = "0.15"
proc-macro2 = "1"
quote = "1"
syn = "1"

[dev-dependencies]
num = "0.2"
Expand All @@ -29,6 +28,3 @@ full-syntax = ["syn/full"]
name = "num_derive"
proc-macro = true
test = false

[build-dependencies]
autocfg = "0.1.2"
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -2,6 +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)
[![Travis status](https://travis-ci.org/rust-num/num-derive.svg?branch=master)](https://travis-ci.org/rust-num/num-derive)

Procedural macros to derive numeric traits in Rust.
Expand All @@ -13,7 +14,7 @@ Add this to your `Cargo.toml`:
```toml
[dependencies]
num-traits = "0.2"
num-derive = "0.2"
num-derive = "0.3"
```

and this to your crate root:
Expand Down Expand Up @@ -50,4 +51,4 @@ Release notes are available in [RELEASES.md](RELEASES.md).

## Compatibility

The `num-derive` crate is tested for rustc 1.15 and greater.
The `num-derive` crate is tested for rustc 1.31 and greater.
14 changes: 0 additions & 14 deletions build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ci/rustup.sh
Expand Up @@ -5,7 +5,7 @@
set -ex

export TRAVIS_RUST_VERSION
for TRAVIS_RUST_VERSION in 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do
for TRAVIS_RUST_VERSION in 1.31.0 stable beta nightly; do
run="rustup run $TRAVIS_RUST_VERSION"
$run $PWD/ci/test_full.sh
env FEATURES="full-syntax" $run $PWD/ci/test_full.sh
Expand Down
13 changes: 1 addition & 12 deletions ci/test_full.sh
Expand Up @@ -6,15 +6,4 @@ echo Testing num-derive on rustc ${TRAVIS_RUST_VERSION}

# num-derive should build and test everywhere.
cargo build --verbose --features="$FEATURES"

# Some cargo versions were buggy about passing dev-deps to rustdoc,
# but worked when docs were tested separately.
case "$TRAVIS_RUST_VERSION" in
1.20.0 | 1.26.0 )
cargo test --verbose --features="$FEATURES" --tests
cargo test --verbose --features="$FEATURES" --doc
;;
*)
cargo test --verbose --features="$FEATURES"
;;
esac
cargo test --verbose --features="$FEATURES"
55 changes: 16 additions & 39 deletions src/lib.rs
Expand Up @@ -78,23 +78,18 @@ fn dummy_const_trick<T: quote::ToTokens>(
Span::call_site(),
);
quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
#[allow(non_upper_case_globals, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(clippy::useless_attribute)]
#[allow(rust_2018_idioms)]
extern crate num_traits as _num_traits;
#exp
};
}
}

#[allow(deprecated)]
fn unraw(ident: &proc_macro2::Ident) -> String {
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
// in 1.33. We currently support rustc back to 1.15 so we need to continue
// to use the deprecated one.
ident.to_string().trim_left_matches("r#").to_owned()
ident.to_string().trim_start_matches("r#").to_owned()
}

// If `data` is a newtype, return the type it's wrapping.
Expand Down Expand Up @@ -177,19 +172,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
let name = &ast.ident;

let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
let i128_fns = if cfg!(has_i128) {
quote! {
fn from_i128(n: i128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
}
fn from_u128(n: u128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
}
}
} else {
quote! {}
};

quote! {
impl _num_traits::FromPrimitive for #name {
fn from_i64(n: i64) -> Option<Self> {
Expand All @@ -210,6 +192,9 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
fn from_i32(n: i32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i32(n).map(#name)
}
fn from_i128(n: i128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
}
fn from_usize(n: usize) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_usize(n).map(#name)
}
Expand All @@ -222,13 +207,15 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
fn from_u32(n: u32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u32(n).map(#name)
}
fn from_u128(n: u128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
}
fn from_f32(n: f32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_f32(n).map(#name)
}
fn from_f64(n: f64) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_f64(n).map(#name)
}
#i128_fns
}
}
} else {
Expand Down Expand Up @@ -341,19 +328,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
let name = &ast.ident;

let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
let i128_fns = if cfg!(has_i128) {
quote! {
fn to_i128(&self) -> Option<i128> {
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
}
fn to_u128(&self) -> Option<u128> {
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
}
}
} else {
quote! {}
};

quote! {
impl _num_traits::ToPrimitive for #name {
fn to_i64(&self) -> Option<i64> {
Expand All @@ -374,6 +348,9 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
fn to_i32(&self) -> Option<i32> {
<#inner_ty as _num_traits::ToPrimitive>::to_i32(&self.0)
}
fn to_i128(&self) -> Option<i128> {
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
}
fn to_usize(&self) -> Option<usize> {
<#inner_ty as _num_traits::ToPrimitive>::to_usize(&self.0)
}
Expand All @@ -386,13 +363,15 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
fn to_u32(&self) -> Option<u32> {
<#inner_ty as _num_traits::ToPrimitive>::to_u32(&self.0)
}
fn to_u128(&self) -> Option<u128> {
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
}
fn to_f32(&self) -> Option<f32> {
<#inner_ty as _num_traits::ToPrimitive>::to_f32(&self.0)
}
fn to_f64(&self) -> Option<f64> {
<#inner_ty as _num_traits::ToPrimitive>::to_f64(&self.0)
}
#i128_fns
}
}
} else {
Expand Down Expand Up @@ -452,9 +431,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
dummy_const_trick("ToPrimitive", &name, impl_).into()
}

#[allow(renamed_and_removed_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(const_static_lifetime))]
const NEWTYPE_ONLY: &'static str = "This trait can only be derived for newtypes";
const NEWTYPE_ONLY: &str = "This trait can only be derived for newtypes";

/// Derives [`num_traits::NumOps`][num_ops] for newtypes. The inner type must already implement
/// `NumOps`.
Expand Down
2 changes: 0 additions & 2 deletions tests/newtype.rs
Expand Up @@ -35,7 +35,6 @@ fn test_from_primitive() {
}

#[test]
#[cfg(has_i128)]
fn test_from_primitive_128() {
assert_eq!(
MyFloat::from_i128(std::i128::MIN),
Expand All @@ -49,7 +48,6 @@ fn test_to_primitive() {
}

#[test]
#[cfg(has_i128)]
fn test_to_primitive_128() {
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
assert_eq!(f.to_i128(), None);
Expand Down

0 comments on commit d0a92ae

Please sign in to comment.