Skip to content

Commit 16c4bb4

Browse files
committed
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
1 parent 4a3502c commit 16c4bb4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/fallback.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{Delimiter, Spacing, TokenTree};
44
use std::cell::RefCell;
55
#[cfg(span_locations)]
66
use std::cmp;
7-
use std::fmt::{self, Debug, Display};
7+
use std::fmt::{self, Debug, Display, Write as _};
88
use std::iter::FromIterator;
99
use std::mem;
1010
use std::ops::RangeBounds;
@@ -876,7 +876,9 @@ impl Literal {
876876
b'"' => escaped.push_str("\\\""),
877877
b'\\' => escaped.push_str("\\\\"),
878878
b'\x20'..=b'\x7E' => escaped.push(*b as char),
879-
_ => escaped.push_str(&format!("\\x{:02X}", b)),
879+
_ => {
880+
let _ = write!(escaped, "\\x{:02X}", b);
881+
}
880882
}
881883
}
882884
escaped.push('"');

0 commit comments

Comments
 (0)