From 2bf0931b84064e79b7af0c37a5bb25c06fdedce0 Mon Sep 17 00:00:00 2001 From: Nick Hackman Date: Wed, 14 Aug 2019 22:52:24 -0400 Subject: Removed all warnings besides two Majority of warnings removed via RustFix Two remain one being a long return type and another being a name suggestion from Clippy `to_owned` for MaybeString --- src/ser.rs | 59 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'src/ser.rs') diff --git a/src/ser.rs b/src/ser.rs index fe4674e..05918e8 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -247,7 +247,7 @@ impl<'a> Serializer<'a> { /// will be present in `dst`. pub fn new(dst: &'a mut String) -> Serializer<'a> { Serializer { - dst: dst, + dst, state: State::End, settings: Rc::new(Settings::default()), } @@ -263,7 +263,7 @@ impl<'a> Serializer<'a> { /// have a trailing comma. See `Serializer::pretty_array` pub fn pretty(dst: &'a mut String) -> Serializer<'a> { Serializer { - dst: dst, + dst, state: State::End, settings: Rc::new(Settings { array: Some(ArraySettings::pretty()), @@ -331,13 +331,12 @@ impl<'a> Serializer<'a> { /// """ /// ``` pub fn pretty_string_literal(&mut self, value: bool) -> &mut Self { - let use_default = - if let &mut Some(ref mut s) = &mut Rc::get_mut(&mut self.settings).unwrap().string { - s.literal = value; - false - } else { - true - }; + let use_default = if let Some(ref mut s) = Rc::get_mut(&mut self.settings).unwrap().string { + s.literal = value; + false + } else { + true + }; if use_default { let mut string = StringSettings::pretty(); @@ -387,13 +386,12 @@ impl<'a> Serializer<'a> { /// /// See `Serializer::pretty_array` for more details. pub fn pretty_array_indent(&mut self, value: usize) -> &mut Self { - let use_default = - if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings).unwrap().array { - a.indent = value; - false - } else { - true - }; + let use_default = if let Some(ref mut a) = Rc::get_mut(&mut self.settings).unwrap().array { + a.indent = value; + false + } else { + true + }; if use_default { let mut array = ArraySettings::pretty(); @@ -407,13 +405,12 @@ impl<'a> Serializer<'a> { /// /// See `Serializer::pretty_array` for more details. pub fn pretty_array_trailing_comma(&mut self, value: bool) -> &mut Self { - let use_default = - if let &mut Some(ref mut a) = &mut Rc::get_mut(&mut self.settings).unwrap().array { - a.trailing_comma = value; - false - } else { - true - }; + let use_default = if let Some(ref mut a) = Rc::get_mut(&mut self.settings).unwrap().array { + a.trailing_comma = value; + false + } else { + true + }; if use_default { let mut array = ArraySettings::pretty(); @@ -610,7 +607,7 @@ impl<'a> Serializer<'a> { (&Some(StringSettings { literal: false, .. }), Repr::Literal(_, ty)) => { Repr::Std(ty) } - (_, r @ _) => r, + (_, r) => r, } } else { Repr::Std(Type::OnelineSingle) @@ -902,7 +899,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { ser: self, first: Cell::new(true), type_: Cell::new(None), - len: len, + len, }) } @@ -1099,10 +1096,10 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> { let res = value.serialize(&mut Serializer { dst: &mut *ser.dst, state: State::Table { - key: key, + key, parent: &ser.state, - first: first, - table_emitted: table_emitted, + first, + table_emitted, }, settings: ser.settings.clone(), }); @@ -1155,10 +1152,10 @@ impl<'a, 'b> ser::SerializeStruct for SerializeTable<'a, 'b> { let res = value.serialize(&mut Serializer { dst: &mut *ser.dst, state: State::Table { - key: key, + key, parent: &ser.state, - first: first, - table_emitted: table_emitted, + first, + table_emitted, }, settings: ser.settings.clone(), }); -- cgit v1.2.3 From b7d26c8a05e3d79a57f67b60ea938147a97094cd Mon Sep 17 00:00:00 2001 From: Nick Hackman Date: Sun, 18 Aug 2019 20:23:40 -0400 Subject: Potential Solution to drop clippy errors Calling the write!, the result that it returns doesn't matter or wasn't deemed as important and was dropped before. This was just removed and then the unused Result is ignored via clippy attribute. This is a plausible solution to get past the Clippy Error, but others may be more ideal. --- src/ser.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/ser.rs') diff --git a/src/ser.rs b/src/ser.rs index 05918e8..6a537e2 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -25,6 +25,8 @@ //! # fn main() {} //! ``` +#![allow(unused_must_use)] + use std::cell::Cell; use std::error; use std::fmt::{self, Write}; @@ -422,7 +424,7 @@ impl<'a> Serializer<'a> { fn display(&mut self, t: T, type_: &'static str) -> Result<(), Error> { self.emit_key(type_)?; - drop(write!(self.dst, "{}", t)); + write!(self.dst, "{}", t); if let State::Table { .. } = self.state { self.dst.push_str("\n"); } @@ -515,7 +517,7 @@ impl<'a> Serializer<'a> { _ => false, }); if ok { - drop(write!(self.dst, "{}", key)); + write!(self.dst, "{}", key); } else { self.emit_str(key, true)?; } @@ -647,7 +649,9 @@ impl<'a> Serializer<'a> { '\u{d}' => self.dst.push_str("\\r"), '\u{22}' => self.dst.push_str("\\\""), '\u{5c}' => self.dst.push_str("\\\\"), - c if c < '\u{1f}' => drop(write!(self.dst, "\\u{:04X}", ch as u32)), + c if c < '\u{1f}' => { + write!(self.dst, "\\u{:04X}", ch as u32); + } ch => self.dst.push(ch), } } @@ -750,15 +754,15 @@ macro_rules! serialize_float { ($this:expr, $v:expr) => {{ $this.emit_key("float")?; if ($v.is_nan() || $v == 0.0) && $v.is_sign_negative() { - drop(write!($this.dst, "-")); + write!($this.dst, "-"); } if $v.is_nan() { - drop(write!($this.dst, "nan")); + write!($this.dst, "nan"); } else { - drop(write!($this.dst, "{}", $v)); + write!($this.dst, "{}", $v); } if $v % 1.0 == 0.0 { - drop(write!($this.dst, ".0")); + write!($this.dst, ".0"); } if let State::Table { .. } = $this.state { $this.dst.push_str("\n"); -- cgit v1.2.3 From 022e914ccf9ae0ed61e5fd09152b41f37737602a Mon Sep 17 00:00:00 2001 From: Nick Hackman Date: Tue, 20 Aug 2019 12:59:28 -0400 Subject: Propogate write! errors to ser::Error std::fmt::Errors are now converted to ser::Errors via ser::Error::custom --- src/ser.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/ser.rs') diff --git a/src/ser.rs b/src/ser.rs index 6a537e2..039c1f3 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -25,8 +25,6 @@ //! # fn main() {} //! ``` -#![allow(unused_must_use)] - use std::cell::Cell; use std::error; use std::fmt::{self, Write}; @@ -424,7 +422,7 @@ impl<'a> Serializer<'a> { fn display(&mut self, t: T, type_: &'static str) -> Result<(), Error> { self.emit_key(type_)?; - write!(self.dst, "{}", t); + write!(self.dst, "{}", t).map_err(ser::Error::custom)?; if let State::Table { .. } = self.state { self.dst.push_str("\n"); } @@ -517,7 +515,7 @@ impl<'a> Serializer<'a> { _ => false, }); if ok { - write!(self.dst, "{}", key); + write!(self.dst, "{}", key).map_err(ser::Error::custom)?; } else { self.emit_str(key, true)?; } @@ -650,7 +648,7 @@ impl<'a> Serializer<'a> { '\u{22}' => self.dst.push_str("\\\""), '\u{5c}' => self.dst.push_str("\\\\"), c if c < '\u{1f}' => { - write!(self.dst, "\\u{:04X}", ch as u32); + write!(self.dst, "\\u{:04X}", ch as u32).map_err(ser::Error::custom)?; } ch => self.dst.push(ch), } @@ -754,15 +752,15 @@ macro_rules! serialize_float { ($this:expr, $v:expr) => {{ $this.emit_key("float")?; if ($v.is_nan() || $v == 0.0) && $v.is_sign_negative() { - write!($this.dst, "-"); + write!($this.dst, "-").map_err(ser::Error::custom)?; } if $v.is_nan() { - write!($this.dst, "nan"); + write!($this.dst, "nan").map_err(ser::Error::custom)?; } else { - write!($this.dst, "{}", $v); + write!($this.dst, "{}", $v).map_err(ser::Error::custom)?; } if $v % 1.0 == 0.0 { - write!($this.dst, ".0"); + write!($this.dst, ".0").map_err(ser::Error::custom)?; } if let State::Table { .. } = $this.state { $this.dst.push_str("\n"); -- cgit v1.2.3