Skip to content

Commit dff8e50

Browse files
bors[bot]cuviper
andcommitted
Merge #22
22: Allow deriving for no-std targets r=cuviper a=cuviper By pulling in `num-traits` as a direct dependency, we corrupt the feature selection for anybody using `num-derive` too, which makes it impossible to use on no-std targets. We really only need it for testing as a dev-dependency though. Co-authored-by: Josh Stone <cuviper@gmail.com>
2 parents 6a8631a + f9c3497 commit dff8e50

File tree

6 files changed

+57
-11
lines changed

6 files changed

+57
-11
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ env:
88
matrix:
99
- # no features
1010
- FEATURES="full-syntax"
11+
12+
matrix:
13+
include:
14+
# try a no-std target
15+
- rust: stable
16+
env: TARGET=thumbv6m-none-eabi
17+
before_script:
18+
- rustup target add "$TARGET"
19+
script:
20+
# This test crate is intentionally separate, because we need
21+
# independent features for no-std. (rust-lang/cargo#2589)
22+
- cd check && cargo check --target "$TARGET"
23+
1124
sudo: false
1225
script:
1326
- cargo build --verbose --features="$FEATURES"

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ 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.3"
11+
version = "0.2.4"
1212
readme = "README.md"
1313
build = "build.rs"
1414

1515
[dependencies]
16-
num-traits = "0.2"
1716
proc-macro2 = "0.4.2"
1817
quote = "0.6"
1918
syn = "0.15"
2019

2120
[dev-dependencies]
2221
num = "0.2"
22+
num-traits = "0.2"
2323

2424
[features]
2525
full-syntax = ["syn/full"]

RELEASES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Release 0.2.4 (2019-01-25)
2+
3+
- [Adjusted dependencies to allow no-std targets][22].
4+
5+
[22]: https://github.com/rust-num/num-derive/pull/22
6+
17
# Release 0.2.3 (2018-10-03)
28

39
- [Added newtype deriving][17] for `FromPrimitive`, `ToPrimitive`,

check/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "check"
3+
version = "0.1.0"
4+
authors = ["Josh Stone <cuviper@gmail.com>"]
5+
edition = "2018"
6+
7+
[dependencies.num-derive]
8+
path = ".."
9+
10+
[dependencies.num-traits]
11+
version = "0.2"
12+
default-features = false

check/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_std]
2+
3+
#[derive(num_derive::FromPrimitive)]
4+
pub enum ABC {
5+
A,
6+
B,
7+
C,
8+
}

src/lib.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
178178
}
179179
}
180180
} else {
181-
quote!{}
181+
quote! {}
182182
};
183183

184184
quote! {
@@ -251,7 +251,8 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
251251
Some(#name::#ident)
252252
}
253253
}
254-
}).collect();
254+
})
255+
.collect();
255256

256257
let from_i64_var = if clauses.is_empty() {
257258
quote!(_)
@@ -345,7 +346,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
345346
}
346347
}
347348
} else {
348-
quote!{}
349+
quote! {}
349350
};
350351

351352
quote! {
@@ -500,7 +501,8 @@ pub fn num_ops(input: TokenStream) -> TokenStream {
500501
}
501502
}
502503
},
503-
).into()
504+
)
505+
.into()
504506
}
505507

506508
/// Derives [`num_traits::NumCast`][num_cast] for newtypes. The inner type must already implement
@@ -523,7 +525,8 @@ pub fn num_cast(input: TokenStream) -> TokenStream {
523525
}
524526
}
525527
},
526-
).into()
528+
)
529+
.into()
527530
}
528531

529532
/// Derives [`num_traits::Zero`][zero] for newtypes. The inner type must already implement `Zero`.
@@ -548,7 +551,8 @@ pub fn zero(input: TokenStream) -> TokenStream {
548551
}
549552
}
550553
},
551-
).into()
554+
)
555+
.into()
552556
}
553557

554558
/// Derives [`num_traits::One`][one] for newtypes. The inner type must already implement `One`.
@@ -573,7 +577,8 @@ pub fn one(input: TokenStream) -> TokenStream {
573577
}
574578
}
575579
},
576-
).into()
580+
)
581+
.into()
577582
}
578583

579584
/// Derives [`num_traits::Num`][num] for newtypes. The inner type must already implement `Num`.
@@ -596,7 +601,8 @@ pub fn num(input: TokenStream) -> TokenStream {
596601
}
597602
}
598603
},
599-
).into()
604+
)
605+
.into()
600606
}
601607

602608
/// Derives [`num_traits::Float`][float] for newtypes. The inner type must already implement
@@ -788,5 +794,6 @@ pub fn float(input: TokenStream) -> TokenStream {
788794
}
789795
}
790796
},
791-
).into()
797+
)
798+
.into()
792799
}

0 commit comments

Comments
 (0)