Skip to content

Commit

Permalink
Rollup merge of #127984 - nyurik:src-refs, r=onur-ozkan
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matthiaskrgr authored Jul 20, 2024
2 parents cd8c5f7 + 8bcf0b4 commit 40cfc88
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ fn copy_sanitizers(
|| target == "x86_64-apple-ios"
{
// Update the library’s install name to reflect that it has been renamed.
apple_darwin_update_library_name(builder, &dst, &format!("@rpath/{}", &runtime.name));
apple_darwin_update_library_name(builder, &dst, &format!("@rpath/{}", runtime.name));
// Upon renaming the install name, the code signature of the file will invalidate,
// so we will sign it again.
apple_darwin_sign_file(builder, &dst);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ impl Step for Libunwind {
}
}
}
assert_eq!(cpp_len, count, "Can't get object files from {:?}", &out_dir);
assert_eq!(cpp_len, count, "Can't get object files from {out_dir:?}");

cc_cfg.compile("unwind");
out_dir
Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/utils/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ pub fn find_target(build: &Build, target: TargetSelection) {
build.cxx.borrow_mut().insert(target, compiler);
}

build.verbose(|| println!("CC_{} = {:?}", &target.triple, build.cc(target)));
build.verbose(|| println!("CFLAGS_{} = {:?}", &target.triple, cflags));
build.verbose(|| println!("CC_{} = {:?}", target.triple, build.cc(target)));
build.verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple));
if let Ok(cxx) = build.cxx(target) {
let cxxflags = build.cflags(target, GitRepo::Rustc, CLang::Cxx);
build.verbose(|| println!("CXX_{} = {:?}", &target.triple, cxx));
build.verbose(|| println!("CXXFLAGS_{} = {:?}", &target.triple, cxxflags));
build.verbose(|| println!("CXX_{} = {cxx:?}", target.triple));
build.verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple));
}
if let Some(ar) = ar {
build.verbose(|| println!("AR_{} = {:?}", &target.triple, ar));
build.verbose(|| println!("AR_{} = {ar:?}", target.triple));
build.ar.borrow_mut().insert(target, ar);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/utils/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<'a> Tarball<'a> {
cmd.arg("generate")
.arg("--image-dir")
.arg(&this.image_dir)
.arg(format!("--component-name={}", &component_name));
.arg(format!("--component-name={component_name}"));

if let Some((dir, dirs)) = this.bulk_dirs.split_first() {
let mut arg = dir.as_os_str().to_os_string();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ fn resolved_path<'cx>(
}
}
if w.alternate() {
write!(w, "{}{:#}", &last.name, last.args.print(cx))?;
write!(w, "{}{:#}", last.name, last.args.print(cx))?;
} else {
let path = if use_absolute {
if let Ok((_, _, fqp)) = href(did, cx) {
Expand Down

0 comments on commit 40cfc88

Please sign in to comment.