From 6dab6b1891be9c92ed14cdd1a7764c4a7e74ecf8 Mon Sep 17 00:00:00 2001 From: Nick Hynes Date: Sun, 1 Sep 2019 17:36:50 +0000 Subject: [PATCH 1/2] Add cargo clippy to CI --- .travis.yml | 1 + src/de.rs | 3 ++- src/error.rs | 2 +- src/ser.rs | 8 ++++---- src/value/ser.rs | 2 +- tests/de.rs | 1 - 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05943014..e282a757 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ before_script: - rustup target add thumbv7em-none-eabihf # Any target that does not have a standard library will do script: - cargo fmt --all -- --check + - (rustup component add clippy && cargo clippy --all --all-features -- -D clippy::all) || exit 0 - cargo build - cargo test - cargo build --no-default-features --target thumbv7em-none-eabihf # Test we can build a platform that does not have std. diff --git a/src/de.rs b/src/de.rs index 56420f2f..e5ef4dff 100644 --- a/src/de.rs +++ b/src/de.rs @@ -226,6 +226,7 @@ where } /// Turn a CBOR deserializer into an iterator over values of type T. + #[allow(clippy::should_implement_trait)] // Trait doesn't allow unconstrained T. pub fn into_iter(self) -> StreamDeserializer<'de, R, T> where T: de::Deserialize<'de>, @@ -599,7 +600,7 @@ where 0x3b => { let value = self.parse_u64()?; if value > i64::max_value() as u64 { - return visitor.visit_i128(-1 - value as i128); + return visitor.visit_i128(-1 - i128::from(value)); } visitor.visit_i64(-1 - value as i64) } diff --git a/src/error.rs b/src/error.rs index e462061c..b1a6a459 100644 --- a/src/error.rs +++ b/src/error.rs @@ -60,7 +60,7 @@ impl Error { pub fn scratch_too_small(offset: u64) -> Error { Error(ErrorImpl { code: ErrorCode::ScratchTooSmall, - offset: offset, + offset, }) } diff --git a/src/ser.rs b/src/ser.rs index 5d13f96b..d827728c 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -61,7 +61,7 @@ where #[inline] pub fn new(writer: W) -> Self { Serializer { - writer: writer, + writer, packed: false, enum_as_map: true, } @@ -263,12 +263,12 @@ where #[inline] fn serialize_i128(self, value: i128) -> Result<()> { if value < 0 { - if -(value + 1) > u64::max_value() as i128 { + if -(value + 1) > i128::from(u64::max_value()) { return Err(Error::message("The number can't be stored in CBOR")); } self.write_u64(1, -(value + 1) as u64) } else { - if value > u64::max_value() as i128 { + if value > i128::from(u64::max_value()) { return Err(Error::message("The number can't be stored in CBOR")); } self.write_u64(0, value as u64) @@ -297,7 +297,7 @@ where #[inline] fn serialize_u128(self, value: u128) -> Result<()> { - if value > u64::max_value() as u128 { + if value > u128::from(u64::max_value()) { return Err(Error::message("The number can't be stored in CBOR")); } self.write_u64(0, value as u64) diff --git a/src/value/ser.rs b/src/value/ser.rs index e931abbc..e51dea89 100644 --- a/src/value/ser.rs +++ b/src/value/ser.rs @@ -344,7 +344,7 @@ impl serde::ser::SerializeMap for SerializeMap { where T: Serialize, { - self.next_key = Some(Value::from(to_value(&key)?)); + self.next_key = Some(to_value(&key)?); Ok(()) } diff --git a/tests/de.rs b/tests/de.rs index 8eed7cd1..7e3fd9cf 100644 --- a/tests/de.rs +++ b/tests/de.rs @@ -725,5 +725,4 @@ mod std_tests { let deserialized_ip = from_slice::(&buf).unwrap(); assert_eq!(ip, deserialized_ip); } - } From 86a8fe354c2cc5daebb3949549e4b632d97dea48 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 3 Sep 2019 10:26:36 +0200 Subject: [PATCH 2/2] Don't abort build when clippy fails Before, if the `clippy` check would fail `exit 0` would be called which exited the test script. This meant that all subsequent steps would be skipped and the test would pass. Now instead of exiting the test script we just make sure that the script always return a zero exit code. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e282a757..6d272d12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_script: - rustup target add thumbv7em-none-eabihf # Any target that does not have a standard library will do script: - cargo fmt --all -- --check - - (rustup component add clippy && cargo clippy --all --all-features -- -D clippy::all) || exit 0 + - (rustup component add clippy && cargo clippy --all --all-features -- -D clippy::all) || true - cargo build - cargo test - cargo build --no-default-features --target thumbv7em-none-eabihf # Test we can build a platform that does not have std.