about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-17 23:30:37 +0000
committerbors <bors@rust-lang.org>2019-06-17 23:30:37 +0000
commit9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f (patch)
treef1dc22e419adbdb3e281ab35975a513846fdde2e /src/libsyntax
parentb25ee644971a168287ee166edbd11642dbcfeab8 (diff)
parent6fe265315626be4f5c3116217dfebd4435fbc14e (diff)
downloadrust-9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f.tar.gz
rust-9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f.zip
Auto merge of #61915 - Centril:rollup-oire3i8, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #61702 (test more variants of enum-int-casting)
 - #61836 (Replace some uses of NodeId with HirId)
 - #61885 (Help LLVM better optimize slice::Iter(Mut)::len)
 - #61893 (make `Weak::ptr_eq`s into methods)
 - #61908 (don't ICE on large files)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/source_map.rs19
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