Skip to content

Commit 40cfc88

Browse files
authored
Rollup merge of rust-lang#127984 - nyurik:src-refs, r=onur-ozkan
Avoid ref when using format! in src Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).  Inlining format args prevents accidental `&` misuse. See also rust-lang/rust-clippy#10851
2 parents cd8c5f7 + 8bcf0b4 commit 40cfc88

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ fn copy_sanitizers(
695695
|| target == "x86_64-apple-ios"
696696
{
697697
// Update the library’s install name to reflect that it has been renamed.
698-
apple_darwin_update_library_name(builder, &dst, &format!("@rpath/{}", &runtime.name));
698+
apple_darwin_update_library_name(builder, &dst, &format!("@rpath/{}", runtime.name));
699699
// Upon renaming the install name, the code signature of the file will invalidate,
700700
// so we will sign it again.
701701
apple_darwin_sign_file(builder, &dst);

src/bootstrap/src/core/build_steps/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ impl Step for Libunwind {
14111411
}
14121412
}
14131413
}
1414-
assert_eq!(cpp_len, count, "Can't get object files from {:?}", &out_dir);
1414+
assert_eq!(cpp_len, count, "Can't get object files from {out_dir:?}");
14151415

14161416
cc_cfg.compile("unwind");
14171417
out_dir

src/bootstrap/src/utils/cc_detect.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ pub fn find_target(build: &Build, target: TargetSelection) {
142142
build.cxx.borrow_mut().insert(target, compiler);
143143
}
144144

145-
build.verbose(|| println!("CC_{} = {:?}", &target.triple, build.cc(target)));
146-
build.verbose(|| println!("CFLAGS_{} = {:?}", &target.triple, cflags));
145+
build.verbose(|| println!("CC_{} = {:?}", target.triple, build.cc(target)));
146+
build.verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple));
147147
if let Ok(cxx) = build.cxx(target) {
148148
let cxxflags = build.cflags(target, GitRepo::Rustc, CLang::Cxx);
149-
build.verbose(|| println!("CXX_{} = {:?}", &target.triple, cxx));
150-
build.verbose(|| println!("CXXFLAGS_{} = {:?}", &target.triple, cxxflags));
149+
build.verbose(|| println!("CXX_{} = {cxx:?}", target.triple));
150+
build.verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple));
151151
}
152152
if let Some(ar) = ar {
153-
build.verbose(|| println!("AR_{} = {:?}", &target.triple, ar));
153+
build.verbose(|| println!("AR_{} = {ar:?}", target.triple));
154154
build.ar.borrow_mut().insert(target, ar);
155155
}
156156

src/bootstrap/src/utils/tarball.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a> Tarball<'a> {
244244
cmd.arg("generate")
245245
.arg("--image-dir")
246246
.arg(&this.image_dir)
247-
.arg(format!("--component-name={}", &component_name));
247+
.arg(format!("--component-name={component_name}"));
248248

249249
if let Some((dir, dirs)) = this.bulk_dirs.split_first() {
250250
let mut arg = dir.as_os_str().to_os_string();

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ fn resolved_path<'cx>(
850850
}
851851
}
852852
if w.alternate() {
853-
write!(w, "{}{:#}", &last.name, last.args.print(cx))?;
853+
write!(w, "{}{:#}", last.name, last.args.print(cx))?;
854854
} else {
855855
let path = if use_absolute {
856856
if let Ok((_, _, fqp)) = href(did, cx) {

0 commit comments

Comments
 (0)