about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/back
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-30 06:29:39 +0000
committerbors <bors@rust-lang.org>2018-07-30 06:29:39 +0000
commit7bbcd005b30582d07f1a39dcf50f77b54e055828 (patch)
treeee814e901b90440bc7b76ab13bdbb7468b3b17de /src/librustc_codegen_llvm/back
parenta3f519df09bf40d09c1a111599b8f115f11fbb49 (diff)
parent421b2ba347a3a1afa41b91f4254f238c790fd73b (diff)
downloadrust-7bbcd005b30582d07f1a39dcf50f77b54e055828.tar.gz
rust-7bbcd005b30582d07f1a39dcf50f77b54e055828.zip
Auto merge of #52805 - ljedrz:format_str_literal, r=petrochenkov
Don't format!() string literals

Prefer `to_string()` to `format!()` take 2, this time targetting string literals. In some cases (`&format!("...")` -> `"..."`) also removes allocations. Occurences of `format!("")` are changed to `String::new()`.
Diffstat (limited to 'src/librustc_codegen_llvm/back')
-rw-r--r--src/librustc_codegen_llvm/back/bytecode.rs14
-rw-r--r--src/librustc_codegen_llvm/back/link.rs4
-rw-r--r--src/librustc_codegen_llvm/back/linker.rs2
-rw-r--r--src/librustc_codegen_llvm/back/lto.rs14
4 files changed, 17 insertions, 17 deletions
diff --git a/src/librustc_codegen_llvm/back/bytecode.rs b/src/librustc_codegen_llvm/back/bytecode.rs
index 212d1aaf055..9a3dd9d2f88 100644
--- a/src/librustc_codegen_llvm/back/bytecode.rs
+++ b/src/librustc_codegen_llvm/back/bytecode.rs
@@ -108,37 +108,37 @@ pub struct DecodedBytecode<'a> {
 impl<'a> DecodedBytecode<'a> {
     pub fn new(data: &'a [u8]) -> Result<DecodedBytecode<'a>, String> {
         if !data.starts_with(RLIB_BYTECODE_OBJECT_MAGIC) {
-            return Err(format!("magic bytecode prefix not found"))
+            return Err("magic bytecode prefix not found".to_string())
         }
         let data = &data[RLIB_BYTECODE_OBJECT_MAGIC.len()..];
         if !data.starts_with(&[RLIB_BYTECODE_OBJECT_VERSION, 0, 0, 0]) {
-            return Err(format!("wrong version prefix found in bytecode"))
+            return Err("wrong version prefix found in bytecode".to_string())
         }
         let data = &data[4..];
         if data.len() < 4 {
-            return Err(format!("bytecode corrupted"))
+            return Err("bytecode corrupted".to_string())
         }
         let identifier_len = unsafe {
             u32::from_le(ptr::read_unaligned(data.as_ptr() as *const u32)) as usize
         };
         let data = &data[4..];
         if data.len() < identifier_len {
-            return Err(format!("bytecode corrupted"))
+            return Err("bytecode corrupted".to_string())
         }
         let identifier = match str::from_utf8(&data[..identifier_len]) {
             Ok(s) => s,
-            Err(_) => return Err(format!("bytecode corrupted"))
+            Err(_) => return Err("bytecode corrupted".to_string())
         };
         let data = &data[identifier_len..];
         if data.len() < 8 {
-            return Err(format!("bytecode corrupted"))
+            return Err("bytecode corrupted".to_string())
         }
         let bytecode_len = unsafe {
             u64::from_le(ptr::read_unaligned(data.as_ptr() as *const u64)) as usize
         };
         let data = &data[8..];
         if data.len() < bytecode_len {
-            return Err(format!("bytecode corrupted"))
+            return Err("bytecode corrupted".to_string())
         }
         let encoded_bytecode = &data[..bytecode_len];
 
diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs
index 83ff8bc821c..845a66c6e44 100644
--- a/src/librustc_codegen_llvm/back/link.rs
+++ b/src/librustc_codegen_llvm/back/link.rs
@@ -261,14 +261,14 @@ pub(crate) fn each_linked_rlib(sess: &Session,
                    .or_else(|| fmts.get(&config::CrateTypeProcMacro));
     let fmts = match fmts {
         Some(f) => f,
-        None => return Err(format!("could not find formats for rlibs"))
+        None => return Err("could not find formats for rlibs".to_string())
     };
     for &(cnum, ref path) in crates {
         match fmts.get(cnum.as_usize() - 1) {
             Some(&Linkage::NotLinked) |
             Some(&Linkage::IncludedFromDylib) => continue,
             Some(_) => {}
-            None => return Err(format!("could not find formats for rlibs"))
+            None => return Err("could not find formats for rlibs".to_string())
         }
         let name = &info.crate_name[&cnum];
         let path = match *path {
diff --git a/src/librustc_codegen_llvm/back/linker.rs b/src/librustc_codegen_llvm/back/linker.rs
index f5bd31a67e5..5f2f3733ec7 100644
--- a/src/librustc_codegen_llvm/back/linker.rs
+++ b/src/librustc_codegen_llvm/back/linker.rs
@@ -206,7 +206,7 @@ impl<'a> GccLinker<'a> {
         match self.sess.opts.cg.lto {
             config::Lto::Thin |
             config::Lto::ThinLocal => {
-                self.linker_arg(&format!("-plugin-opt=thin"));
+                self.linker_arg("-plugin-opt=thin");
             }
             config::Lto::Fat |
             config::Lto::Yes |
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs
index 60b5cf2ec76..93cb9eb9767 100644
--- a/src/librustc_codegen_llvm/back/lto.rs
+++ b/src/librustc_codegen_llvm/back/lto.rs
@@ -421,7 +421,7 @@ fn thin_lto(diag_handler: &Handler,
             symbol_white_list.len() as u32,
         );
         if data.is_null() {
-            let msg = format!("failed to prepare thin LTO context");
+            let msg = "failed to prepare thin LTO context".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
         let data = ThinData(data);
@@ -647,7 +647,7 @@ impl ThinModule {
             self.shared.module_names[self.idx].as_ptr(),
         );
         if llmod.is_null() {
-            let msg = format!("failed to parse bitcode for thin LTO module");
+            let msg = "failed to parse bitcode for thin LTO module".to_string();
             return Err(write::llvm_err(&diag_handler, msg));
         }
         let module = ModuleCodegen {
@@ -670,7 +670,7 @@ impl ThinModule {
         let mut cu2 = ptr::null_mut();
         llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
         if !cu2.is_null() {
-            let msg = format!("multiple source DICompileUnits found");
+            let msg = "multiple source DICompileUnits found".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
 
@@ -691,25 +691,25 @@ impl ThinModule {
         // You can find some more comments about these functions in the LLVM
         // bindings we've got (currently `PassWrapper.cpp`)
         if !llvm::LLVMRustPrepareThinLTORename(self.shared.data.0, llmod) {
-            let msg = format!("failed to prepare thin LTO module");
+            let msg = "failed to prepare thin LTO module".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
         cgcx.save_temp_bitcode(&module, "thin-lto-after-rename");
         timeline.record("rename");
         if !llvm::LLVMRustPrepareThinLTOResolveWeak(self.shared.data.0, llmod) {
-            let msg = format!("failed to prepare thin LTO module");
+            let msg = "failed to prepare thin LTO module".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
         cgcx.save_temp_bitcode(&module, "thin-lto-after-resolve");
         timeline.record("resolve");
         if !llvm::LLVMRustPrepareThinLTOInternalize(self.shared.data.0, llmod) {
-            let msg = format!("failed to prepare thin LTO module");
+            let msg = "failed to prepare thin LTO module".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
         cgcx.save_temp_bitcode(&module, "thin-lto-after-internalize");
         timeline.record("internalize");
         if !llvm::LLVMRustPrepareThinLTOImport(self.shared.data.0, llmod) {
-            let msg = format!("failed to prepare thin LTO module");
+            let msg = "failed to prepare thin LTO module".to_string();
             return Err(write::llvm_err(&diag_handler, msg))
         }
         cgcx.save_temp_bitcode(&module, "thin-lto-after-import");