diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..6c9e623d --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,7 @@ +#comment_width = 100 +#error_on_unformatted = true +#format_strings = true +#imports_indent = "Block" +#match_block_trailing_comma = true +newline_style = "Native" +#reorder_imports = true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 56be56dd..dbda1a0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,11 +23,18 @@ rust: matrix: allow_failures: - rust: nightly + include: + - env: RUSTFMT + rust: 1.26.1 + install: + - rustup component add rustfmt-preview + script: + - cargo fmt -- --write-mode=diff before_script: | test "${TRAVIS_RUST_VERSION//./_}" != "stable" || (test -x /home/travis/.cargo/bin/cargo-coveralls || cargo install cargo-travis) || - (test $(grep "cargo-travis" /home/travis/.cargo/.crates.toml | sed -r "s/\"cargo-travis ([^\ ]+).+/\1/") = $(cargo search cargo-travis --limit 1 | sed -r "s/cargo-travis \(([^\)]+)\).+/\1/") || cargoo install cargo-travis --force) + (test $(grep "cargo-travis" /home/travis/.cargo/.crates.toml | sed -r "s/\"cargo-travis ([^\ ]+).+/\1/") = $(cargo search cargo-travis --limit 1 | sed -r "s/cargo-travis \(([^\)]+)\).+/\1/") || cargo install cargo-travis --force) script: | cargo build --verbose --no-default-features --features "autoconvert usize u8 u16 u32 u64 isize i8 i16 i32 i64 bigint biguint rational rational32 rational64 bigrational f32 f64 si std use_serde" && diff --git a/examples/base.rs b/examples/base.rs index b776f32c..cdaf4a2c 100644 --- a/examples/base.rs +++ b/examples/base.rs @@ -8,7 +8,11 @@ use uom::si::length::{centimeter, meter}; use uom::si::time::second; mod cgs { - ISQ!(uom::si, f32, (centimeter, gram, second, ampere, kelvin, mole, candela)); + ISQ!( + uom::si, + f32, + (centimeter, gram, second, ampere, kelvin, mole, candela) + ); } fn main() { diff --git a/examples/mks.rs b/examples/mks.rs index c7bb9fe4..d93e5bcb 100644 --- a/examples/mks.rs +++ b/examples/mks.rs @@ -82,7 +82,7 @@ system! { mod f32 { mod s { - pub use ::*; + pub use *; } Q!(f32::s, f32); diff --git a/examples/si.rs b/examples/si.rs index f8dbcd25..164d3f66 100644 --- a/examples/si.rs +++ b/examples/si.rs @@ -2,11 +2,11 @@ extern crate uom; -use uom::si::Unit; use uom::si::f32::*; use uom::si::length::{centimeter, kilometer, meter}; use uom::si::time::second; use uom::si::velocity::{kilometer_per_second, meter_per_second}; +use uom::si::Unit; fn main() { let l1 = Length::new::(15.0); diff --git a/src/lib.rs b/src/lib.rs index 59683c75..32954cdb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,7 +136,7 @@ //! * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or //! ) //! * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) -//! +//! //! at your option. //! //! [BIPM]: http://www.bipm.org/en/about-us/ @@ -146,23 +146,21 @@ // Compile with `no_std` when the `std` feature is not specified. #![cfg_attr(not(feature = "std"), no_std)] - // Default rustc lints. -#![warn( - missing_copy_implementations, - missing_debug_implementations, - missing_docs, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results)] - +#![warn(missing_copy_implementations)] +#![warn(missing_debug_implementations)] +#![warn(missing_docs)] +#![warn(trivial_casts)] +#![warn(trivial_numeric_casts)] +#![warn(unused_extern_crates)] +#![warn(unused_import_braces)] +#![warn(unused_qualifications)] +#![warn(unused_results)] // Clippy lints. #![cfg_attr(feature = "cargo-clippy", allow(inline_always))] // Fail to compile if no underlying storage type features are specified. +#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg(not(any( feature = "usize", feature = "u8", feature = "u16", feature = "u32", feature = "u64", feature = "isize", feature = "i8", feature = "i16", feature = "i32", feature = "i64", @@ -266,6 +264,7 @@ pub trait Conversion { /// Trait representing a [conversion factor][factor]. /// /// [factor]: https://jcgm.bipm.org/vim/en/1.24.html +#[cfg_attr(rustfmt, rustfmt_skip)] pub trait ConversionFactor : lib::ops::Div + lib::ops::Mul diff --git a/src/si/prefix.rs b/src/si/prefix.rs index f86d6547..fd77ff46 100644 --- a/src/si/prefix.rs +++ b/src/si/prefix.rs @@ -8,6 +8,7 @@ /// [si]: http://jcgm.bipm.org/vim/en/1.16.html /// [mult]: http://jcgm.bipm.org/vim/en/1.17.html /// [submult]: http://jcgm.bipm.org/vim/en/1.18.html +#[cfg_attr(rustfmt, rustfmt_skip)] #[macro_export] macro_rules! prefix { (yotta) => { 1.0E24 }; diff --git a/src/tests.rs b/src/tests.rs index c39ea4a0..aad41e62 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,16 +1,16 @@ use self::length::{kilometer, meter}; use self::mass::kilogram; -#[allow(unused_imports)] -use {Conversion, ConversionFactor}; +use lib::fmt::Debug; +use lib::marker::PhantomData; #[allow(unused_imports)] use num::{Float, FromPrimitive, One, Saturating, Signed, Zero}; use quickcheck::TestResult; -use lib::fmt::Debug; -use lib::marker::PhantomData; #[cfg(feature = "serde")] use serde_json; #[allow(unused_imports)] use typenum::{N1, P1, P2, P3, Z0}; +#[allow(unused_imports)] +use {Conversion, ConversionFactor}; #[macro_use] mod length { @@ -47,6 +47,7 @@ system! { } /// Test trait to allow tests to perform storage-type sensitive comparisons. +#[cfg_attr(rustfmt, rustfmt_skip)] pub trait Test : Debug + Sized