Skip to content

Commit d0a92ae

Browse files
bors[bot]Eijebongcuviper
committed
Merge #28
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>
2 parents bbaeeb1 + d93f537 commit d0a92ae

File tree

8 files changed

+25
-81
lines changed

8 files changed

+25
-81
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
language: rust
22
sudo: false
33
rust:
4-
- 1.15.0
5-
- 1.20.0
6-
- 1.26.0 # has_i128
74
- 1.31.0 # 2018!
85
- stable
96
- beta

Cargo.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ categories = [ "science" ]
88
license = "MIT/Apache-2.0"
99
name = "num-derive"
1010
repository = "https://github.com/rust-num/num-derive"
11-
version = "0.2.5"
11+
version = "0.3.0"
1212
readme = "README.md"
13-
build = "build.rs"
1413
exclude = ["/ci/*", "/.travis.yml", "/bors.toml"]
1514

1615
[dependencies]
17-
proc-macro2 = "0.4.2"
18-
quote = "0.6"
19-
syn = "0.15"
16+
proc-macro2 = "1"
17+
quote = "1"
18+
syn = "1"
2019

2120
[dev-dependencies]
2221
num = "0.2"
@@ -29,6 +28,3 @@ full-syntax = ["syn/full"]
2928
name = "num_derive"
3029
proc-macro = true
3130
test = false
32-
33-
[build-dependencies]
34-
autocfg = "0.1.2"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-derive.svg)](https://crates.io/crates/num-derive)
44
[![documentation](https://docs.rs/num-derive/badge.svg)](https://docs.rs/num-derive)
5+
![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)
56
[![Travis status](https://travis-ci.org/rust-num/num-derive.svg?branch=master)](https://travis-ci.org/rust-num/num-derive)
67

78
Procedural macros to derive numeric traits in Rust.
@@ -13,7 +14,7 @@ Add this to your `Cargo.toml`:
1314
```toml
1415
[dependencies]
1516
num-traits = "0.2"
16-
num-derive = "0.2"
17+
num-derive = "0.3"
1718
```
1819

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

5152
## Compatibility
5253

53-
The `num-derive` crate is tested for rustc 1.15 and greater.
54+
The `num-derive` crate is tested for rustc 1.31 and greater.

build.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

ci/rustup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -ex
66

77
export TRAVIS_RUST_VERSION
8-
for TRAVIS_RUST_VERSION in 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do
8+
for TRAVIS_RUST_VERSION in 1.31.0 stable beta nightly; do
99
run="rustup run $TRAVIS_RUST_VERSION"
1010
$run $PWD/ci/test_full.sh
1111
env FEATURES="full-syntax" $run $PWD/ci/test_full.sh

ci/test_full.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,4 @@ echo Testing num-derive on rustc ${TRAVIS_RUST_VERSION}
66

77
# num-derive should build and test everywhere.
88
cargo build --verbose --features="$FEATURES"
9-
10-
# Some cargo versions were buggy about passing dev-deps to rustdoc,
11-
# but worked when docs were tested separately.
12-
case "$TRAVIS_RUST_VERSION" in
13-
1.20.0 | 1.26.0 )
14-
cargo test --verbose --features="$FEATURES" --tests
15-
cargo test --verbose --features="$FEATURES" --doc
16-
;;
17-
*)
18-
cargo test --verbose --features="$FEATURES"
19-
;;
20-
esac
9+
cargo test --verbose --features="$FEATURES"

src/lib.rs

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,18 @@ fn dummy_const_trick<T: quote::ToTokens>(
7878
Span::call_site(),
7979
);
8080
quote! {
81-
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
81+
#[allow(non_upper_case_globals, unused_qualifications)]
8282
const #dummy_const: () = {
83-
#[allow(unknown_lints)]
84-
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
83+
#[allow(clippy::useless_attribute)]
8584
#[allow(rust_2018_idioms)]
8685
extern crate num_traits as _num_traits;
8786
#exp
8887
};
8988
}
9089
}
9190

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

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

179174
let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
180-
let i128_fns = if cfg!(has_i128) {
181-
quote! {
182-
fn from_i128(n: i128) -> Option<Self> {
183-
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
184-
}
185-
fn from_u128(n: u128) -> Option<Self> {
186-
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
187-
}
188-
}
189-
} else {
190-
quote! {}
191-
};
192-
193175
quote! {
194176
impl _num_traits::FromPrimitive for #name {
195177
fn from_i64(n: i64) -> Option<Self> {
@@ -210,6 +192,9 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
210192
fn from_i32(n: i32) -> Option<Self> {
211193
<#inner_ty as _num_traits::FromPrimitive>::from_i32(n).map(#name)
212194
}
195+
fn from_i128(n: i128) -> Option<Self> {
196+
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
197+
}
213198
fn from_usize(n: usize) -> Option<Self> {
214199
<#inner_ty as _num_traits::FromPrimitive>::from_usize(n).map(#name)
215200
}
@@ -222,13 +207,15 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
222207
fn from_u32(n: u32) -> Option<Self> {
223208
<#inner_ty as _num_traits::FromPrimitive>::from_u32(n).map(#name)
224209
}
210+
fn from_u128(n: u128) -> Option<Self> {
211+
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
212+
}
225213
fn from_f32(n: f32) -> Option<Self> {
226214
<#inner_ty as _num_traits::FromPrimitive>::from_f32(n).map(#name)
227215
}
228216
fn from_f64(n: f64) -> Option<Self> {
229217
<#inner_ty as _num_traits::FromPrimitive>::from_f64(n).map(#name)
230218
}
231-
#i128_fns
232219
}
233220
}
234221
} else {
@@ -341,19 +328,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
341328
let name = &ast.ident;
342329

343330
let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
344-
let i128_fns = if cfg!(has_i128) {
345-
quote! {
346-
fn to_i128(&self) -> Option<i128> {
347-
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
348-
}
349-
fn to_u128(&self) -> Option<u128> {
350-
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
351-
}
352-
}
353-
} else {
354-
quote! {}
355-
};
356-
357331
quote! {
358332
impl _num_traits::ToPrimitive for #name {
359333
fn to_i64(&self) -> Option<i64> {
@@ -374,6 +348,9 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
374348
fn to_i32(&self) -> Option<i32> {
375349
<#inner_ty as _num_traits::ToPrimitive>::to_i32(&self.0)
376350
}
351+
fn to_i128(&self) -> Option<i128> {
352+
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
353+
}
377354
fn to_usize(&self) -> Option<usize> {
378355
<#inner_ty as _num_traits::ToPrimitive>::to_usize(&self.0)
379356
}
@@ -386,13 +363,15 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
386363
fn to_u32(&self) -> Option<u32> {
387364
<#inner_ty as _num_traits::ToPrimitive>::to_u32(&self.0)
388365
}
366+
fn to_u128(&self) -> Option<u128> {
367+
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
368+
}
389369
fn to_f32(&self) -> Option<f32> {
390370
<#inner_ty as _num_traits::ToPrimitive>::to_f32(&self.0)
391371
}
392372
fn to_f64(&self) -> Option<f64> {
393373
<#inner_ty as _num_traits::ToPrimitive>::to_f64(&self.0)
394374
}
395-
#i128_fns
396375
}
397376
}
398377
} else {
@@ -452,9 +431,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
452431
dummy_const_trick("ToPrimitive", &name, impl_).into()
453432
}
454433

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

459436
/// Derives [`num_traits::NumOps`][num_ops] for newtypes. The inner type must already implement
460437
/// `NumOps`.

tests/newtype.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ fn test_from_primitive() {
3535
}
3636

3737
#[test]
38-
#[cfg(has_i128)]
3938
fn test_from_primitive_128() {
4039
assert_eq!(
4140
MyFloat::from_i128(std::i128::MIN),
@@ -49,7 +48,6 @@ fn test_to_primitive() {
4948
}
5049

5150
#[test]
52-
#[cfg(has_i128)]
5351
fn test_to_primitive_128() {
5452
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
5553
assert_eq!(f.to_i128(), None);

0 commit comments

Comments
 (0)