Skip to content

Commit 63396b3

Browse files
committed
Allow binary files to go through the FileLoader
1 parent 816f958 commit 63396b3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/rustc_span/src/source_map.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub trait FileLoader {
100100

101101
/// Read the contents of a UTF-8 file into memory.
102102
fn read_file(&self, path: &Path) -> io::Result<String>;
103+
104+
/// Read the contents of a potentially non-UTF-8 file into memory.
105+
fn read_binary_file(&self, path: &Path) -> io::Result<Vec<u8>>;
103106
}
104107

105108
/// A FileLoader that uses std::fs to load real files.
@@ -113,6 +116,10 @@ impl FileLoader for RealFileLoader {
113116
fn read_file(&self, path: &Path) -> io::Result<String> {
114117
fs::read_to_string(path)
115118
}
119+
120+
fn read_binary_file(&self, path: &Path) -> io::Result<Vec<u8>> {
121+
fs::read(path)
122+
}
116123
}
117124

118125
/// This is a [SourceFile] identifier that is used to correlate source files between
@@ -220,9 +227,7 @@ impl SourceMap {
220227
/// Unlike `load_file`, guarantees that no normalization like BOM-removal
221228
/// takes place.
222229
pub fn load_binary_file(&self, path: &Path) -> io::Result<Vec<u8>> {
223-
// Ideally, this should use `self.file_loader`, but it can't
224-
// deal with binary files yet.
225-
let bytes = fs::read(path)?;
230+
let bytes = self.file_loader.read_binary_file(path)?;
226231

227232
// We need to add file to the `SourceMap`, so that it is present
228233
// in dep-info. There's also an edge case that file might be both

0 commit comments

Comments
 (0)