Skip to content

Commit 104d812

Browse files
bors[bot]cuviper
andcommitted
Merge #23
23: Check formatting in CI r=cuviper a=cuviper Co-authored-by: Josh Stone <cuviper@gmail.com>
2 parents 2a868fe + c72fcc0 commit 104d812

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

.travis.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
language: rust
2+
sudo: false
23
rust:
34
- 1.15.0
5+
- 1.20.0
6+
- 1.26.0 # has_i128
7+
- 1.31.0 # 2018!
48
- stable
59
- beta
610
- nightly
711
env:
812
matrix:
913
- # no features
1014
- FEATURES="full-syntax"
15+
script:
16+
- cargo build --verbose --features="$FEATURES"
17+
- ./ci/test_full.sh
1118

1219
matrix:
1320
include:
1421
# try a no-std target
15-
- rust: stable
22+
- name: "no_std"
23+
rust: stable
1624
env: TARGET=thumbv6m-none-eabi
1725
before_script:
1826
- rustup target add "$TARGET"
@@ -21,10 +29,13 @@ matrix:
2129
# independent features for no-std. (rust-lang/cargo#2589)
2230
- cd check && cargo check --target "$TARGET"
2331

24-
sudo: false
25-
script:
26-
- cargo build --verbose --features="$FEATURES"
27-
- ./ci/test_full.sh
32+
- name: "rustfmt"
33+
rust: 1.31.0
34+
before_script:
35+
- rustup component add rustfmt
36+
script:
37+
- cargo fmt --all -- --check
38+
2839
notifications:
2940
email:
3041
on_success: never

ci/rustup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/sh
22
# Use rustup to locally run the same suite of tests as .travis.yml.
3-
# (You should first install/update 1.15.0, stable, beta, and nightly.)
3+
# (You should first install/update the rust versions listed below.)
44

55
set -ex
66

77
export TRAVIS_RUST_VERSION
8-
for TRAVIS_RUST_VERSION in 1.15.0 stable beta nightly; do
8+
for TRAVIS_RUST_VERSION in 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do
99
run="rustup run $TRAVIS_RUST_VERSION"
10-
$run cargo build --verbose
1110
$run $PWD/ci/test_full.sh
11+
env FEATURES="full-syntax" $run $PWD/ci/test_full.sh
1212
done

ci/test_full.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ 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-
cargo test --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

src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,29 @@ fn dummy_const_trick<T: quote::ToTokens>(
7474
exp: T,
7575
) -> proc_macro2::TokenStream {
7676
let dummy_const = Ident::new(
77-
&format!(
78-
"_IMPL_NUM_{}_FOR_{}",
79-
trait_.to_uppercase(),
80-
format!("{}", name).to_uppercase()
81-
),
77+
&format!("_IMPL_NUM_{}_FOR_{}", trait_, unraw(name)),
8278
Span::call_site(),
8379
);
8480
quote! {
81+
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
8582
const #dummy_const: () = {
83+
#[allow(unknown_lints)]
84+
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
85+
#[allow(rust_2018_idioms)]
86+
extern crate num_traits as _num_traits;
8687
#exp
8788
};
8889
}
8990
}
9091

92+
#[allow(deprecated)]
93+
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()
98+
}
99+
91100
// If `data` is a newtype, return the type it's wrapping.
92101
fn newtype_inner(data: &syn::Data) -> Option<syn::Type> {
93102
match data {
@@ -182,7 +191,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
182191
};
183192

184193
quote! {
185-
extern crate num_traits as _num_traits;
186194
impl _num_traits::FromPrimitive for #name {
187195
fn from_i64(n: i64) -> Option<Self> {
188196
<#inner_ty as _num_traits::FromPrimitive>::from_i64(n).map(#name)
@@ -261,9 +269,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
261269
};
262270

263271
quote! {
264-
#[allow(unused_qualifications)]
265-
extern crate num_traits as _num_traits;
266-
267272
impl _num_traits::FromPrimitive for #name {
268273
#[allow(trivial_numeric_casts)]
269274
fn from_i64(#from_i64_var: i64) -> Option<Self> {
@@ -350,7 +355,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
350355
};
351356

352357
quote! {
353-
extern crate num_traits as _num_traits;
354358
impl _num_traits::ToPrimitive for #name {
355359
fn to_i64(&self) -> Option<i64> {
356360
<#inner_ty as _num_traits::ToPrimitive>::to_i64(&self.0)
@@ -432,9 +436,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
432436
};
433437

434438
quote! {
435-
#[allow(unused_qualifications)]
436-
extern crate num_traits as _num_traits;
437-
438439
impl _num_traits::ToPrimitive for #name {
439440
#[allow(trivial_numeric_casts)]
440441
fn to_i64(&self) -> Option<i64> {
@@ -518,7 +519,6 @@ pub fn num_cast(input: TokenStream) -> TokenStream {
518519
"NumCast",
519520
&name,
520521
quote! {
521-
extern crate num_traits as _num_traits;
522522
impl _num_traits::NumCast for #name {
523523
fn from<T: _num_traits::ToPrimitive>(n: T) -> Option<Self> {
524524
<#inner_ty as _num_traits::NumCast>::from(n).map(#name)
@@ -541,7 +541,6 @@ pub fn zero(input: TokenStream) -> TokenStream {
541541
"Zero",
542542
&name,
543543
quote! {
544-
extern crate num_traits as _num_traits;
545544
impl _num_traits::Zero for #name {
546545
fn zero() -> Self {
547546
#name(<#inner_ty as _num_traits::Zero>::zero())
@@ -567,7 +566,6 @@ pub fn one(input: TokenStream) -> TokenStream {
567566
"One",
568567
&name,
569568
quote! {
570-
extern crate num_traits as _num_traits;
571569
impl _num_traits::One for #name {
572570
fn one() -> Self {
573571
#name(<#inner_ty as _num_traits::One>::one())
@@ -593,7 +591,6 @@ pub fn num(input: TokenStream) -> TokenStream {
593591
"Num",
594592
&name,
595593
quote! {
596-
extern crate num_traits as _num_traits;
597594
impl _num_traits::Num for #name {
598595
type FromStrRadixErr = <#inner_ty as _num_traits::Num>::FromStrRadixErr;
599596
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
@@ -618,7 +615,6 @@ pub fn float(input: TokenStream) -> TokenStream {
618615
"Float",
619616
&name,
620617
quote! {
621-
extern crate num_traits as _num_traits;
622618
impl _num_traits::Float for #name {
623619
fn nan() -> Self {
624620
#name(<#inner_ty as _num_traits::Float>::nan())

0 commit comments

Comments
 (0)