about summary refs log tree commit diff
path: root/src/librustc_codegen_utils
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-07 23:26:14 +0000
committerbors <bors@rust-lang.org>2018-12-07 23:26:14 +0000
commit0a7798079608b4ff014471ae64b6c8201aa59cdf (patch)
treed7b77b0fc5a6446207132b666952751aecf40a51 /src/librustc_codegen_utils
parent4a45578bc58ff262864f72680cc02e83f5d2f5b3 (diff)
parent2f6226518bd5085896a0f27cfd3ea396367ecd50 (diff)
downloadrust-0a7798079608b4ff014471ae64b6c8201aa59cdf.tar.gz
rust-0a7798079608b4ff014471ae64b6c8201aa59cdf.zip
Auto merge of #56258 - euclio:fs-read-write, r=euclio
use top level `fs` functions where appropriate

This commit replaces many usages of `File::open` and reading or writing
with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code
complexity, and will improve performance for most reads, since the
functions allocate the buffer to be the size of the file.

I believe that this commit will not impact behavior in any way, so some
matches will check the error kind in case the file was not valid UTF-8.
Some of these cases may not actually care about the error.
Diffstat (limited to 'src/librustc_codegen_utils')
-rw-r--r--src/librustc_codegen_utils/codegen_backend.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs
index b328873800e..74718460f56 100644
--- a/src/librustc_codegen_utils/codegen_backend.rs
+++ b/src/librustc_codegen_utils/codegen_backend.rs
@@ -22,8 +22,8 @@
 #![feature(box_syntax)]
 
 use std::any::Any;
-use std::io::{self, Write};
-use std::fs::File;
+use std::io::Write;
+use std::fs;
 use std::path::Path;
 use std::sync::{mpsc, Arc};
 
@@ -81,11 +81,7 @@ pub struct NoLlvmMetadataLoader;
 
 impl MetadataLoader for NoLlvmMetadataLoader {
     fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
-        let mut file = File::open(filename)
-            .map_err(|e| format!("metadata file open err: {:?}", e))?;
-
-        let mut buf = Vec::new();
-        io::copy(&mut file, &mut buf).unwrap();
+        let buf = fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
         let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
         Ok(rustc_erase_owner!(buf.map_owner_box()))
     }
@@ -209,8 +205,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
             } else {
                 &ongoing_codegen.metadata.raw_data
             };
-            let mut file = File::create(&output_name).unwrap();
-            file.write_all(metadata).unwrap();
+            fs::write(&output_name, metadata).unwrap();
         }
 
         sess.abort_if_errors();