Skip to content

Commit

Permalink
Merge #23
Browse files Browse the repository at this point in the history
23: Check formatting in CI r=cuviper a=cuviper



Co-authored-by: Josh Stone <[email protected]>
  • Loading branch information
bors[bot] and cuviper committed Apr 23, 2019
2 parents 2a868fe + c72fcc0 commit 104d812
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
language: rust
sudo: false
rust:
- 1.15.0
- 1.20.0
- 1.26.0 # has_i128
- 1.31.0 # 2018!
- stable
- beta
- nightly
env:
matrix:
- # no features
- FEATURES="full-syntax"
script:
- cargo build --verbose --features="$FEATURES"
- ./ci/test_full.sh

matrix:
include:
# try a no-std target
- rust: stable
- name: "no_std"
rust: stable
env: TARGET=thumbv6m-none-eabi
before_script:
- rustup target add "$TARGET"
Expand All @@ -21,10 +29,13 @@ matrix:
# independent features for no-std. (rust-lang/cargo#2589)
- cd check && cargo check --target "$TARGET"

sudo: false
script:
- cargo build --verbose --features="$FEATURES"
- ./ci/test_full.sh
- name: "rustfmt"
rust: 1.31.0
before_script:
- rustup component add rustfmt
script:
- cargo fmt --all -- --check

notifications:
email:
on_success: never
Expand Down
6 changes: 3 additions & 3 deletions ci/rustup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
# Use rustup to locally run the same suite of tests as .travis.yml.
# (You should first install/update 1.15.0, stable, beta, and nightly.)
# (You should first install/update the rust versions listed below.)

set -ex

export TRAVIS_RUST_VERSION
for TRAVIS_RUST_VERSION in 1.15.0 stable beta nightly; do
for TRAVIS_RUST_VERSION in 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do
run="rustup run $TRAVIS_RUST_VERSION"
$run cargo build --verbose
$run $PWD/ci/test_full.sh
env FEATURES="full-syntax" $run $PWD/ci/test_full.sh
done
13 changes: 12 additions & 1 deletion ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ echo Testing num-derive on rustc ${TRAVIS_RUST_VERSION}

# num-derive should build and test everywhere.
cargo build --verbose --features="$FEATURES"
cargo test --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
32 changes: 14 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,29 @@ fn dummy_const_trick<T: quote::ToTokens>(
exp: T,
) -> proc_macro2::TokenStream {
let dummy_const = Ident::new(
&format!(
"_IMPL_NUM_{}_FOR_{}",
trait_.to_uppercase(),
format!("{}", name).to_uppercase()
),
&format!("_IMPL_NUM_{}_FOR_{}", trait_, unraw(name)),
Span::call_site(),
);
quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(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()
}

// If `data` is a newtype, return the type it's wrapping.
fn newtype_inner(data: &syn::Data) -> Option<syn::Type> {
match data {
Expand Down Expand Up @@ -182,7 +191,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
};

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

quote! {
#[allow(unused_qualifications)]
extern crate num_traits as _num_traits;

impl _num_traits::FromPrimitive for #name {
#[allow(trivial_numeric_casts)]
fn from_i64(#from_i64_var: i64) -> Option<Self> {
Expand Down Expand Up @@ -350,7 +355,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
};

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

quote! {
#[allow(unused_qualifications)]
extern crate num_traits as _num_traits;

impl _num_traits::ToPrimitive for #name {
#[allow(trivial_numeric_casts)]
fn to_i64(&self) -> Option<i64> {
Expand Down Expand Up @@ -518,7 +519,6 @@ pub fn num_cast(input: TokenStream) -> TokenStream {
"NumCast",
&name,
quote! {
extern crate num_traits as _num_traits;
impl _num_traits::NumCast for #name {
fn from<T: _num_traits::ToPrimitive>(n: T) -> Option<Self> {
<#inner_ty as _num_traits::NumCast>::from(n).map(#name)
Expand All @@ -541,7 +541,6 @@ pub fn zero(input: TokenStream) -> TokenStream {
"Zero",
&name,
quote! {
extern crate num_traits as _num_traits;
impl _num_traits::Zero for #name {
fn zero() -> Self {
#name(<#inner_ty as _num_traits::Zero>::zero())
Expand All @@ -567,7 +566,6 @@ pub fn one(input: TokenStream) -> TokenStream {
"One",
&name,
quote! {
extern crate num_traits as _num_traits;
impl _num_traits::One for #name {
fn one() -> Self {
#name(<#inner_ty as _num_traits::One>::one())
Expand All @@ -593,7 +591,6 @@ pub fn num(input: TokenStream) -> TokenStream {
"Num",
&name,
quote! {
extern crate num_traits as _num_traits;
impl _num_traits::Num for #name {
type FromStrRadixErr = <#inner_ty as _num_traits::Num>::FromStrRadixErr;
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
Expand All @@ -618,7 +615,6 @@ pub fn float(input: TokenStream) -> TokenStream {
"Float",
&name,
quote! {
extern crate num_traits as _num_traits;
impl _num_traits::Float for #name {
fn nan() -> Self {
#name(<#inner_ty as _num_traits::Float>::nan())
Expand Down

0 comments on commit 104d812

Please sign in to comment.