From 16c4bb476c4a34cf6680568edf5dd65b3965d340 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 5 May 2022 21:34:28 -0700 Subject: [PATCH 1/2] Eliminate an allocation from Literal::byte_string error: `format!(..)` appended to existing `String` --> src/fallback.rs:879:22 | 879 | _ => escaped.push_str(&format!("\\x{:02X}", b)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::format-push-string` implied by `-D clippy::all` = help: consider using `write!` to avoid the extra allocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string --- src/fallback.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fallback.rs b/src/fallback.rs index be53877f..c365ecbf 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -4,7 +4,7 @@ use crate::{Delimiter, Spacing, TokenTree}; use std::cell::RefCell; #[cfg(span_locations)] use std::cmp; -use std::fmt::{self, Debug, Display}; +use std::fmt::{self, Debug, Display, Write as _}; use std::iter::FromIterator; use std::mem; use std::ops::RangeBounds; @@ -876,7 +876,9 @@ impl Literal { b'"' => escaped.push_str("\\\""), b'\\' => escaped.push_str("\\\\"), b'\x20'..=b'\x7E' => escaped.push(*b as char), - _ => escaped.push_str(&format!("\\x{:02X}", b)), + _ => { + let _ = write!(escaped, "\\x{:02X}", b); + } } } escaped.push('"'); From d307f5650aa0dbc77c5a277300ad12550fef60cc Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 5 May 2022 21:39:18 -0700 Subject: [PATCH 2/2] Restore support for rust pre-1.33 error[E0658]: renaming imports with `_` is unstable (see issue 48216) --> src/fallback.rs:7:38 | 7 | use std::fmt::{self, Debug, Display, Write as _}; | ^^^^^^^^^^ --- src/fallback.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fallback.rs b/src/fallback.rs index c365ecbf..21ede03f 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -4,7 +4,7 @@ use crate::{Delimiter, Spacing, TokenTree}; use std::cell::RefCell; #[cfg(span_locations)] use std::cmp; -use std::fmt::{self, Debug, Display, Write as _}; +use std::fmt::{self, Debug, Display, Write}; use std::iter::FromIterator; use std::mem; use std::ops::RangeBounds;