From 0717595781c7fe8995316720160f1f53c6b6566f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 11 May 2022 15:15:49 +0100 Subject: [PATCH] clippy: Use write! rather than push_str, format This does involve unwrap, but of course that can't fail unless the formats fail, which would already panic (that's implied by format!). --- crates/arti/src/lib.rs | 4 +++- crates/tor-cell/src/relaycell/msg.rs | 5 +++-- crates/tor-dirclient/src/util.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/arti/src/lib.rs b/crates/arti/src/lib.rs index 781a80233..50a6393d6 100644 --- a/crates/arti/src/lib.rs +++ b/crates/arti/src/lib.rs @@ -122,6 +122,8 @@ pub mod process; pub mod socks; pub mod watch_cfg; +use std::fmt::Write; + pub use cfg::{ ApplicationConfig, ApplicationConfigBuilder, ArtiConfig, ArtiConfigBuilder, ProxyConfig, ProxyConfigBuilder, SystemConfig, SystemConfigBuilder, @@ -267,7 +269,7 @@ pub fn main_main() -> Result<()> { // If we couldn't resolve the default config file, then too bad. If something // actually tries to use it, it will produce an error, but don't fail here // just for that reason. - config_file_help.push_str(&format!(" Defaults to {:?}", default)); + write!(config_file_help, " Defaults to {:?}", default).unwrap(); } // We create the runtime now so that we can use its `Debug` impl to describe it for diff --git a/crates/tor-cell/src/relaycell/msg.rs b/crates/tor-cell/src/relaycell/msg.rs index 93dd2a87a..0a17cf066 100644 --- a/crates/tor-cell/src/relaycell/msg.rs +++ b/crates/tor-cell/src/relaycell/msg.rs @@ -8,6 +8,7 @@ use crate::chancell::msg::{DestroyReason, TAP_C_HANDSHAKE_LEN, TAP_S_HANDSHAKE_L use crate::chancell::CELL_DATA_LEN; use caret::caret_int; use educe::Educe; +use std::fmt::Write; use std::net::{IpAddr, Ipv4Addr}; use tor_bytes::{Error, Result}; use tor_bytes::{Readable, Reader, Writeable, Writer}; @@ -921,9 +922,9 @@ impl Resolve { for o in v6.octets().iter().rev() { let high_nybble = o >> 4; let low_nybble = o & 15; - s.push_str(&format!("{:x}.{:x}.", low_nybble, high_nybble)); + write!(s, "{:x}.{:x}.", low_nybble, high_nybble).unwrap(); } - s.push_str("ip6.arpa"); + write!(s, "ip6.arpa").unwrap(); s } }; diff --git a/crates/tor-dirclient/src/util.rs b/crates/tor-dirclient/src/util.rs index 87d280c7d..bf80f21e6 100644 --- a/crates/tor-dirclient/src/util.rs +++ b/crates/tor-dirclient/src/util.rs @@ -1,16 +1,20 @@ //! Helper functions for the directory client code +use std::fmt::Write; + /// Encode an HTTP request in a quick and dirty HTTP 1.0 format. pub(crate) fn encode_request(req: &http::Request<()>) -> String { let mut s = format!("{} {} HTTP/1.0\r\n", req.method(), req.uri()); for (key, val) in req.headers().iter() { - s.push_str(&format!( + write!( + s, "{}: {}\r\n", key, val.to_str() .expect("Added an HTTP header that wasn't UTF-8!") - )); + ) + .unwrap(); } s.push_str("\r\n"); s