diff options
| author | bors <bors@rust-lang.org> | 2023-11-21 22:34:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-21 22:34:19 +0000 |
| commit | fec80b4475c871ad3e4d70d29d1781ee771fe631 (patch) | |
| tree | 9397b939e5b564fab21d6f252d3f737625e40df8 /compiler/rustc_codegen_ssa/src/back | |
| parent | 2f8d81f9dbac6b8df982199f69da04a4c8357227 (diff) | |
| parent | 21a870515b18e5b2b90435d0f1a6d3089b5217ae (diff) | |
| download | rust-fec80b4475c871ad3e4d70d29d1781ee771fe631.tar.gz rust-fec80b4475c871ad3e4d70d29d1781ee771fe631.zip | |
Auto merge of #118143 - Nilstrieb:only-borrow-what-you-need, r=compiler-errors
Fix `clippy::needless_borrow` in the compiler `x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now. r? `@compiler-errors` you told me you want to review this I will do a self review first (which, for this, is easiest on GitHub once the PR is open) - did it
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/archive.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 34 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 6 |
5 files changed, 26 insertions, 27 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 1c464b3eca4..4dc28adf336 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -175,8 +175,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { ) -> io::Result<()> { let mut archive_path = archive_path.to_path_buf(); if self.sess.target.llvm_target.contains("-apple-macosx") { - if let Some(new_archive_path) = - try_extract_macho_fat_archive(&self.sess, &archive_path)? + if let Some(new_archive_path) = try_extract_macho_fat_archive(self.sess, &archive_path)? { archive_path = new_archive_path } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 33e8f352cd8..903563671a6 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -277,7 +277,7 @@ pub fn each_linked_rlib( let crate_name = info.crate_name[&cnum]; let used_crate_source = &info.used_crate_source[&cnum]; if let Some((path, _)) = &used_crate_source.rlib { - f(cnum, &path); + f(cnum, path); } else { if used_crate_source.rmeta.is_some() { return Err(errors::LinkRlibError::OnlyRmetaFound { crate_name }); @@ -524,7 +524,7 @@ fn link_staticlib<'a>( && !ignored_for_lto(sess, &codegen_results.crate_info, cnum); let native_libs = codegen_results.crate_info.native_libraries[&cnum].iter(); - let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, &lib)); + let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, lib)); let relevant_libs: FxHashSet<_> = relevant.filter_map(|lib| lib.filename).collect(); let bundled_libs: FxHashSet<_> = native_libs.filter_map(|lib| lib.filename).collect(); @@ -689,7 +689,7 @@ fn link_dwarf_object<'a>( // Adding an executable is primarily done to make `thorin` check that all the referenced // dwarf objects are found in the end. package.add_executable( - &executable_out_filename, + executable_out_filename, thorin::MissingReferencedObjectBehaviour::Skip, )?; @@ -945,7 +945,7 @@ fn link_natively<'a>( { let is_vs_installed = windows_registry::find_vs_version().is_ok(); let has_linker = windows_registry::find_tool( - &sess.opts.target_triple.triple(), + sess.opts.target_triple.triple(), "link.exe", ) .is_some(); @@ -1038,14 +1038,14 @@ fn link_natively<'a>( if sess.target.is_like_osx { match (strip, crate_type) { (Strip::Debuginfo, _) => { - strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-S")) + strip_symbols_with_external_utility(sess, "strip", out_filename, Some("-S")) } // Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988) (Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => { - strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-x")) + strip_symbols_with_external_utility(sess, "strip", out_filename, Some("-x")) } (Strip::Symbols, _) => { - strip_symbols_with_external_utility(sess, "strip", &out_filename, None) + strip_symbols_with_external_utility(sess, "strip", out_filename, None) } (Strip::None, _) => {} } @@ -1059,7 +1059,7 @@ fn link_natively<'a>( match strip { // Always preserve the symbol table (-x). Strip::Debuginfo => { - strip_symbols_with_external_utility(sess, stripcmd, &out_filename, Some("-x")) + strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-x")) } // Strip::Symbols is handled via the --strip-all linker option. Strip::Symbols => {} @@ -1245,13 +1245,13 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) { // rpath to the library as well (the rpath should be absolute, see // PR #41352 for details). let filename = format!("rustc{channel}_rt.{name}"); - let path = find_sanitizer_runtime(&sess, &filename); + let path = find_sanitizer_runtime(sess, &filename); let rpath = path.to_str().expect("non-utf8 component in path"); linker.args(&["-Wl,-rpath", "-Xlinker", rpath]); linker.link_dylib(&filename, false, true); } else { let filename = format!("librustc{channel}_rt.{name}.a"); - let path = find_sanitizer_runtime(&sess, &filename).join(&filename); + let path = find_sanitizer_runtime(sess, &filename).join(&filename); linker.link_whole_rlib(&path); } } @@ -1685,7 +1685,7 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind { // Returns true if linker is located within sysroot fn detect_self_contained_mingw(sess: &Session) -> bool { - let (linker, _) = linker_and_flavor(&sess); + let (linker, _) = linker_and_flavor(sess); // Assume `-C linker=rust-lld` as self-contained mode if linker == Path::new("rust-lld") { return true; @@ -1737,7 +1737,7 @@ fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfC LinkSelfContainedDefault::InferredForMingw => { sess.host == sess.target && sess.target.vendor != "uwp" - && detect_self_contained_mingw(&sess) + && detect_self_contained_mingw(sess) } } }; @@ -2432,7 +2432,7 @@ fn add_native_libs_from_crate( // If rlib contains native libs as archives, unpack them to tmpdir. let rlib = &codegen_results.crate_info.used_crate_source[&cnum].rlib.as_ref().unwrap().0; archive_builder_builder - .extract_bundled_libs(rlib, tmpdir, &bundled_libs) + .extract_bundled_libs(rlib, tmpdir, bundled_libs) .unwrap_or_else(|e| sess.emit_fatal(e)); } @@ -2485,7 +2485,7 @@ fn add_native_libs_from_crate( cmd.link_whole_staticlib( name, verbatim, - &search_paths.get_or_init(|| archive_search_paths(sess)), + search_paths.get_or_init(|| archive_search_paths(sess)), ); } else { cmd.link_staticlib(name, verbatim) @@ -2719,7 +2719,7 @@ fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf { // already had `fix_windows_verbatim_for_gcc()` applied if needed. sysroot_lib_path } else { - fix_windows_verbatim_for_gcc(&lib_dir) + fix_windows_verbatim_for_gcc(lib_dir) } } @@ -2756,7 +2756,7 @@ fn add_static_crate<'a>( let mut link_upstream = |path: &Path| { let rlib_path = if let Some(dir) = path.parent() { let file_name = path.file_name().expect("rlib path has no file name path component"); - rehome_sysroot_lib_dir(sess, &dir).join(file_name) + rehome_sysroot_lib_dir(sess, dir).join(file_name) } else { fix_windows_verbatim_for_gcc(path) }; @@ -2793,7 +2793,7 @@ fn add_static_crate<'a>( let canonical = f.replace('-', "_"); let is_rust_object = - canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f); + canonical.starts_with(&canonical_name) && looks_like_rust_object_file(f); // If we're performing LTO and this is a rust-generated object // file, then we don't need the object file as it's part of the diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 09434513e31..0cb35021b62 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -45,7 +45,7 @@ pub fn get_linker<'a>( self_contained: bool, target_cpu: &'a str, ) -> Box<dyn Linker + 'a> { - let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe"); + let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.triple(), "link.exe"); // If our linker looks like a batch script on Windows then to execute this // we'll need to spawn `cmd` explicitly. This is primarily done to handle @@ -78,7 +78,7 @@ pub fn get_linker<'a>( if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == "uwp" { if let Some(ref tool) = msvc_tool { let original_path = tool.path(); - if let Some(ref root_lib_path) = original_path.ancestors().nth(4) { + if let Some(root_lib_path) = original_path.ancestors().nth(4) { let arch = match t.arch.as_ref() { "x86_64" => Some("x64"), "x86" => Some("x86"), @@ -519,7 +519,7 @@ impl<'a> Linker for GccLinker<'a> { // -force_load is the macOS equivalent of --whole-archive, but it // involves passing the full path to the library to link. self.linker_arg("-force_load"); - let lib = find_native_static_library(lib, verbatim, search_path, &self.sess); + let lib = find_native_static_library(lib, verbatim, search_path, self.sess); self.linker_arg(&lib); } } @@ -1590,7 +1590,7 @@ impl<'a> Linker for AixLinker<'a> { fn link_whole_staticlib(&mut self, lib: &str, verbatim: bool, search_path: &[PathBuf]) { self.hint_static(); - let lib = find_native_static_library(lib, verbatim, search_path, &self.sess); + let lib = find_native_static_library(lib, verbatim, search_path, self.sess); self.cmd.arg(format!("-bkeepfile:{}", lib.to_str().unwrap())); } diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 9cd4394108a..b12ac881100 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -621,7 +621,7 @@ fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, S let mut ret = FxHashMap::default(); for (def_id, lib) in tcx.foreign_modules(cnum).iter() { - let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module()); + let module = def_id_to_native_lib.get(def_id).and_then(|s| s.wasm_import_module()); let Some(module) = module else { continue }; ret.extend(lib.foreign_items.iter().map(|id| { assert_eq!(id.krate, cnum); diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 3d6a2124334..8f17e4ea0bd 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -892,7 +892,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap(); let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| { - let source_file = in_incr_comp_dir(&incr_comp_session_dir, saved_path); + let source_file = in_incr_comp_dir(incr_comp_session_dir, saved_path); debug!( "copying preexisting module `{}` from {:?} to {}", module.name, @@ -914,7 +914,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( let object = load_from_incr_comp_dir( cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)), - &module.source.saved_files.get("o").expect("no saved object file in work product"), + module.source.saved_files.get("o").expect("no saved object file in work product"), ); let dwarf_object = module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| { @@ -924,7 +924,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( .expect( "saved dwarf object in work product but `split_dwarf_path` returned `None`", ); - load_from_incr_comp_dir(dwarf_obj_out, &saved_dwarf_object_file) + load_from_incr_comp_dir(dwarf_obj_out, saved_dwarf_object_file) }); WorkItemResult::Finished(CompiledModule { |
