about summary refs log tree commit diff
path: root/src/libsyntax/source_map.rs
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/libsyntax/source_map.rs
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/libsyntax/source_map.rs')
-rw-r--r--src/libsyntax/source_map.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs
index ee60d2dd615..45008129e83 100644
--- a/src/libsyntax/source_map.rs
+++ b/src/libsyntax/source_map.rs
@@ -31,7 +31,7 @@ use std::path::{Path, PathBuf};
 
 use std::env;
 use std::fs;
-use std::io::{self, Read};
+use std::io;
 use errors::SourceMapper;
 
 /// Return the span itself if it doesn't come from a macro expansion,
@@ -96,9 +96,7 @@ impl FileLoader for RealFileLoader {
     }
 
     fn read_file(&self, path: &Path) -> io::Result<String> {
-        let mut src = String::new();
-        fs::File::open(path)?.read_to_string(&mut src)?;
-        Ok(src)
+        fs::read_to_string(path)
     }
 }