diff options
| author | bors <bors@rust-lang.org> | 2018-11-10 23:16:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-11-10 23:16:25 +0000 |
| commit | 6408162ea13446852cb45d9e781e64ba85ec7bb1 (patch) | |
| tree | 7e96365ba8883f8ed58e380d1864674855bd2de5 /src/librustc_codegen_utils | |
| parent | 6e9b84296223126a0a59bde63a0f97011bb7b0f5 (diff) | |
| parent | 2f99d09ef7b622286d9eedef1366399cdcca4d6d (diff) | |
| download | rust-6408162ea13446852cb45d9e781e64ba85ec7bb1.tar.gz rust-6408162ea13446852cb45d9e781e64ba85ec7bb1.zip | |
Auto merge of #54864 - ljedrz:cleanup_codegen_llvm_back, r=Mark-Simulacrum
Cleanup codegen_llvm/back - improve allocations - use `Cow<'static, str>` where applicable - use `to_owned` instead of `to_string` with string literals - remove a redundant `continue` - possible minor speedup in logic - use `mem::replace` instead of `swap` where more concise - remove `'static` from consts - improve common patterns - remove explicit `return`s - whitespace & formatting fixes
Diffstat (limited to 'src/librustc_codegen_utils')
| -rw-r--r-- | src/librustc_codegen_utils/linker.rs | 48 | ||||
| -rw-r--r-- | src/librustc_codegen_utils/symbol_export.rs | 11 |
2 files changed, 23 insertions, 36 deletions
diff --git a/src/librustc_codegen_utils/linker.rs b/src/librustc_codegen_utils/linker.rs index c1f41fd509a..ae1d77f1521 100644 --- a/src/librustc_codegen_utils/linker.rs +++ b/src/librustc_codegen_utils/linker.rs @@ -224,9 +224,9 @@ impl<'a> GccLinker<'a> { } impl<'a> Linker for GccLinker<'a> { - fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg(format!("-l{}",lib)); } + fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg(format!("-l{}", lib)); } fn link_staticlib(&mut self, lib: &str) { - self.hint_static(); self.cmd.arg(format!("-l{}",lib)); + self.hint_static(); self.cmd.arg(format!("-l{}", lib)); } fn link_rlib(&mut self, lib: &Path) { self.hint_static(); self.cmd.arg(lib); } fn include_path(&mut self, path: &Path) { self.cmd.arg("-L").arg(path); } @@ -243,7 +243,7 @@ impl<'a> Linker for GccLinker<'a> { fn link_rust_dylib(&mut self, lib: &str, _path: &Path) { self.hint_dynamic(); - self.cmd.arg(format!("-l{}",lib)); + self.cmd.arg(format!("-l{}", lib)); } fn link_framework(&mut self, framework: &str) { @@ -261,7 +261,7 @@ impl<'a> Linker for GccLinker<'a> { self.hint_static(); let target = &self.sess.target.target; if !target.options.is_like_osx { - self.linker_arg("--whole-archive").cmd.arg(format!("-l{}",lib)); + self.linker_arg("--whole-archive").cmd.arg(format!("-l{}", lib)); self.linker_arg("--no-whole-archive"); } else { // -force_load is the macOS equivalent of --whole-archive, but it @@ -343,17 +343,13 @@ impl<'a> Linker for GccLinker<'a> { } fn debuginfo(&mut self) { - match self.sess.opts.debuginfo { - DebugInfo::None => { - // If we are building without debuginfo enabled and we were called with - // `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo - // found when linking to get rid of symbols from libstd. - match self.sess.opts.debugging_opts.strip_debuginfo_if_disabled { - Some(true) => { self.linker_arg("-S"); }, - _ => {}, - } - }, - _ => {}, + if let DebugInfo::None = self.sess.opts.debuginfo { + // If we are building without debuginfo enabled and we were called with + // `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo + // found when linking to get rid of symbols from libstd. + if let Some(true) = self.sess.opts.debugging_opts.strip_debuginfo_if_disabled { + self.linker_arg("-S"); + } }; } @@ -373,8 +369,7 @@ impl<'a> Linker for GccLinker<'a> { // purely to support rustbuild right now, we should get a more // principled solution at some point to force the compiler to pass // the right `-Wl,-install_name` with an `@rpath` in it. - if self.sess.opts.cg.rpath || - self.sess.opts.debugging_opts.osx_rpath_install_name { + if self.sess.opts.cg.rpath || self.sess.opts.debugging_opts.osx_rpath_install_name { self.linker_arg("-install_name"); let mut v = OsString::from("@rpath/"); v.push(out_filename.file_name().unwrap()); @@ -461,9 +456,8 @@ impl<'a> Linker for GccLinker<'a> { fn finalize(&mut self) -> Command { self.hint_dynamic(); // Reset to default before returning the composed command line. - let mut cmd = Command::new(""); - ::std::mem::swap(&mut cmd, &mut self.cmd); - cmd + + ::std::mem::replace(&mut self.cmd, Command::new("")) } fn group_start(&mut self) { @@ -715,9 +709,7 @@ impl<'a> Linker for MsvcLinker<'a> { } fn finalize(&mut self) -> Command { - let mut cmd = Command::new(""); - ::std::mem::swap(&mut cmd, &mut self.cmd); - cmd + ::std::mem::replace(&mut self.cmd, Command::new("")) } // MSVC doesn't need group indicators @@ -865,7 +857,7 @@ impl<'a> Linker for EmLinker<'a> { let res = encoder.emit_seq(symbols.len(), |encoder| { for (i, sym) in symbols.iter().enumerate() { encoder.emit_seq_elt(i, |encoder| { - encoder.emit_str(&("_".to_string() + sym)) + encoder.emit_str(&("_".to_owned() + sym)) })?; } Ok(()) @@ -885,9 +877,7 @@ impl<'a> Linker for EmLinker<'a> { } fn finalize(&mut self) -> Command { - let mut cmd = Command::new(""); - ::std::mem::swap(&mut cmd, &mut self.cmd); - cmd + ::std::mem::replace(&mut self.cmd, Command::new("")) } // Appears not necessary on Emscripten @@ -1085,9 +1075,7 @@ impl<'a> Linker for WasmLd<'a> { // indicative of bugs, let's prevent them. self.cmd.arg("--fatal-warnings"); - let mut cmd = Command::new(""); - ::std::mem::swap(&mut cmd, &mut self.cmd); - cmd + ::std::mem::replace(&mut self.cmd, Command::new("")) } // Not needed for now with LLD diff --git a/src/librustc_codegen_utils/symbol_export.rs b/src/librustc_codegen_utils/symbol_export.rs index 6c40296b2ef..dff7e518630 100644 --- a/src/librustc_codegen_utils/symbol_export.rs +++ b/src/librustc_codegen_utils/symbol_export.rs @@ -47,11 +47,10 @@ fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel { } } -pub fn crates_export_threshold(crate_types: &[config::CrateType]) - -> SymbolExportLevel { - if crate_types.iter().any(|&crate_type| { - crate_export_threshold(crate_type) == SymbolExportLevel::Rust - }) { +pub fn crates_export_threshold(crate_types: &[config::CrateType]) -> SymbolExportLevel { + if crate_types.iter().any(|&crate_type| + crate_export_threshold(crate_type) == SymbolExportLevel::Rust) + { SymbolExportLevel::Rust } else { SymbolExportLevel::C @@ -359,7 +358,7 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt, def_id: DefId) -> bool !tcx.reachable_set(LOCAL_CRATE).0.contains(&node_id) } else { bug!("is_unreachable_local_definition called with non-local DefId: {:?}", - def_id) + def_id) } } |
