Skip to content

Commit 4d8afcd

Browse files
committed
Avoid ref when using format! for perf
Clean up a few minor refs in `format!` macro, as it has a tiny perf cost. A few more minor related cleanups.
1 parent eae9451 commit 4d8afcd

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

core/src/fmt/builders.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
10261026
/// assert_eq!(format!("{}", value), "a");
10271027
/// assert_eq!(format!("{:?}", value), "'a'");
10281028
///
1029-
/// let wrapped = fmt::FormatterFn(|f| write!(f, "{:?}", &value));
1029+
/// let wrapped = fmt::FormatterFn(|f| write!(f, "{value:?}"));
10301030
/// assert_eq!(format!("{}", wrapped), "'a'");
10311031
/// assert_eq!(format!("{:?}", wrapped), "'a'");
10321032
/// ```

core/tests/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn test_join() {
5656

5757
let y = String::new();
5858
let x = join!(async {
59-
println!("{}", &y);
59+
println!("{y}");
6060
1
6161
})
6262
.await;

proc_macro/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1544,10 +1544,10 @@ impl fmt::Debug for Literal {
15441544
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15451545
f.debug_struct("Literal")
15461546
// format the kind on one line even in {:#?} mode
1547-
.field("kind", &format_args!("{:?}", &self.0.kind))
1547+
.field("kind", &format_args!("{:?}", self.0.kind))
15481548
.field("symbol", &self.0.symbol)
15491549
// format `Some("...")` on one line even in {:#?} mode
1550-
.field("suffix", &format_args!("{:?}", &self.0.suffix))
1550+
.field("suffix", &format_args!("{:?}", self.0.suffix))
15511551
.field("span", &self.0.span)
15521552
.finish()
15531553
}

std/src/fs/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ fn recursive_rmdir_toctou() {
683683
let drop_canary_arc = Arc::new(());
684684
let drop_canary_weak = Arc::downgrade(&drop_canary_arc);
685685

686-
eprintln!("x: {:?}", &victim_del_path);
686+
eprintln!("x: {victim_del_path:?}");
687687

688688
// victim just continuously removes `victim_del`
689689
thread::spawn(move || {

std/src/io/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl Error {
775775
///
776776
/// impl Display for MyError {
777777
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
778-
/// write!(f, "MyError: {}", &self.v)
778+
/// write!(f, "MyError: {}", self.v)
779779
/// }
780780
/// }
781781
///

0 commit comments

Comments
 (0)