diff options
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index e74a5c2d8fe..55e106b661b 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -115,6 +115,12 @@ impl FileLoader for RealFileLoader { } fn read_file(&self, path: &Path) -> io::Result<String> { + if path.metadata().is_ok_and(|metadata| metadata.len() > SourceFile::MAX_FILE_SIZE.into()) { + return Err(io::Error::other(format!( + "text files larger than {} bytes are unsupported", + SourceFile::MAX_FILE_SIZE + ))); + } fs::read_to_string(path) } @@ -297,7 +303,10 @@ impl SourceMap { /// unmodified. pub fn new_source_file(&self, filename: FileName, src: String) -> Lrc<SourceFile> { self.try_new_source_file(filename, src).unwrap_or_else(|OffsetOverflowError| { - eprintln!("fatal error: rustc does not support files larger than 4GB"); + eprintln!( + "fatal error: rustc does not support text files larger than {} bytes", + SourceFile::MAX_FILE_SIZE + ); crate::fatal_error::FatalError.raise() }) } |
