diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-17 20:56:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-17 20:56:01 +0200 |
| commit | 6fe265315626be4f5c3116217dfebd4435fbc14e (patch) | |
| tree | 357994a3b563d23320b0ead83a5c1560ba042f60 /src/libsyntax | |
| parent | 04d653902569b398e584692f45a2996f7437d5af (diff) | |
| parent | ccb2dfbfec812d1502626992a8856df27c4fa950 (diff) | |
| download | rust-6fe265315626be4f5c3116217dfebd4435fbc14e.tar.gz rust-6fe265315626be4f5c3116217dfebd4435fbc14e.zip | |
Rollup merge of #61908 - matklad:overflow, r=petrochenkov
don't ICE on large files This is an extremely marginal error, so the cost of properly threading `Handler` everywhere just not seemed justified. However, it's useful to panic when we create a file, and not when we slice strings with overflown indexes somewhere in the guts of the compiler. For this reason, while we provide safe `try_new_source_file`, we don't change the existing public interface and just panic more or less cleanly. closes #61904 r? @petrochenkov
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/source_map.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index a21d2df4162..c0307263387 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -191,6 +191,18 @@ impl SourceMap { /// If a file already exists in the source_map with the same id, that file is returned /// 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"); + errors::FatalError.raise() + }) + } + + fn try_new_source_file( + &self, + filename: FileName, + src: String + ) -> Result<Lrc<SourceFile>, OffsetOverflowError> { let start_pos = self.next_start_pos(); // The path is used to determine the directory for loading submodules and @@ -212,7 +224,7 @@ impl SourceMap { was_remapped, Some(&unmapped_path)); - return match self.source_file_by_stable_id(file_id) { + let lrc_sf = match self.source_file_by_stable_id(file_id) { Some(lrc_sf) => lrc_sf, None => { let source_file = Lrc::new(SourceFile::new( @@ -221,7 +233,7 @@ impl SourceMap { unmapped_path, src, Pos::from_usize(start_pos), - )); + )?); let mut files = self.files.borrow_mut(); @@ -230,7 +242,8 @@ impl SourceMap { source_file } - } + }; + Ok(lrc_sf) } /// Allocates a new SourceFile representing a source file from an external |
