diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 000000000..aa9f871f5 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,2 @@ +msrv = "1.36" +blacklisted-names = [] diff --git a/src/de/mod.rs b/src/de/mod.rs index ed91bb143..af355b8b8 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -41,7 +41,7 @@ impl<'de> Deserializer<'de> { } pub fn remainder(&self) -> Cow<'_, str> { - String::from_utf8_lossy(&self.bytes.bytes()) + String::from_utf8_lossy(self.bytes.bytes()) } } @@ -315,7 +315,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { let string = self.bytes.string()?; let base64_str = match string { ParsedStr::Allocated(ref s) => s.as_str(), - ParsedStr::Slice(ref s) => s, + ParsedStr::Slice(s) => s, }; base64::decode(base64_str) }; diff --git a/src/parse.rs b/src/parse.rs index 126873290..d20c0f9b2 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -323,7 +323,7 @@ impl<'a> Bytes<'a> { } pub fn bytes(&self) -> &[u8] { - &self.bytes + self.bytes } pub fn char(&mut self) -> Result { diff --git a/src/ser/mod.rs b/src/ser/mod.rs index d8c4ce649..0f85ec4c2 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -412,8 +412,8 @@ impl<'a, W: io::Write> ser::Serializer for &'a mut Serializer { fn serialize_f32(self, v: f32) -> Result<()> { write!(self.output, "{}", v)?; - // TODO: use f32::EPSILON when minimum supported rust version is 1.43 - pub const EPSILON: f32 = 1.192_092_9e-7; + #[allow(clippy::excessive_precision)] + pub const EPSILON: f32 = 1.192_092_90e-07_f32; if self.decimal_floats() && (v - v.floor()).abs() < EPSILON { write!(self.output, ".0")?; } @@ -423,7 +423,8 @@ impl<'a, W: io::Write> ser::Serializer for &'a mut Serializer { fn serialize_f64(self, v: f64) -> Result<()> { write!(self.output, "{}", v)?; // TODO: use f64::EPSILON when minimum supported rust version is 1.43 - pub const EPSILON: f64 = 2.220_446_049_250_313e-16; + #[allow(clippy::excessive_precision)] + pub const EPSILON: f64 = 2.220_446_049_250_313e-16_f64; if self.decimal_floats() && (v - v.floor()).abs() < EPSILON { write!(self.output, ".0")?; } diff --git a/src/ser/tests.rs b/src/ser/tests.rs index b3543799f..f95de18b1 100644 --- a/src/ser/tests.rs +++ b/src/ser/tests.rs @@ -89,10 +89,10 @@ fn test_map() { map.insert((false, false), 123); let s = to_string(&map).unwrap(); - s.starts_with("{"); + s.starts_with('{'); s.contains("(true,false):4"); s.contains("(false,false):123"); - s.ends_with("}"); + s.ends_with('}'); } #[test] diff --git a/src/value.rs b/src/value.rs index c7a435b04..339288a43 100644 --- a/src/value.rs +++ b/src/value.rs @@ -37,8 +37,8 @@ impl Map { } /// Returns `true` if `self.len() == 0`, `false` otherwise. - pub fn is_empty(&self) -> usize { - self.0.len() + pub fn is_empty(&self) -> bool { + self.0.len() == 0 } /// Inserts a new element, returning the previous element with this `key` if diff --git a/tests/129_indexmap.rs b/tests/129_indexmap.rs index a10a11e27..ccaaaef96 100644 --- a/tests/129_indexmap.rs +++ b/tests/129_indexmap.rs @@ -30,7 +30,7 @@ tasks: { Value::String("debug message".to_string()) ); assert_eq!( - *map.keys().skip(1).next().unwrap(), + *map.keys().nth(1).unwrap(), Value::String("shell command".to_string()) ); } @@ -65,7 +65,7 @@ tasks: { Value::String("shell command".to_string()) ); assert_eq!( - *map.keys().skip(1).next().unwrap(), + *map.keys().nth(1).unwrap(), Value::String("debug message".to_string()) ); } diff --git a/tests/extensions.rs b/tests/extensions.rs index 81157257a..bc07d699b 100644 --- a/tests/extensions.rs +++ b/tests/extensions.rs @@ -47,7 +47,7 @@ const CONFIG_U_NT: &str = " #[test] fn unwrap_newtypes() { - let d: Struct = ron::de::from_str(&CONFIG_U_NT).expect("Failed to deserialize"); + let d: Struct = ron::de::from_str(CONFIG_U_NT).expect("Failed to deserialize"); println!("unwrap_newtypes: {:#?}", d); } @@ -75,7 +75,7 @@ const CONFIG_I_S: &str = " #[test] fn implicit_some() { - let d: Struct = ron::de::from_str(&CONFIG_I_S).expect("Failed to deserialize"); + let d: Struct = ron::de::from_str(CONFIG_I_S).expect("Failed to deserialize"); println!("implicit_some: {:#?}", d); } diff --git a/tests/value.rs b/tests/value.rs index 1e1ff5b99..f71bb3dd3 100644 --- a/tests/value.rs +++ b/tests/value.rs @@ -1,5 +1,6 @@ use ron::value::{Map, Number, Value}; use serde::Serialize; +use std::f64; #[test] fn bool() { @@ -23,7 +24,10 @@ fn map() { #[test] fn number() { assert_eq!("42".parse(), Ok(Value::Number(Number::new(42)))); - assert_eq!("3.1415".parse(), Ok(Value::Number(Number::new(3.1415f64)))); + assert_eq!( + "3.141592653589793".parse(), + Ok(Value::Number(Number::new(f64::consts::PI))) + ); } #[test]