about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorNika Layzell <nika@thelayzells.com>2019-10-19 13:05:46 -0400
committerNika Layzell <nika@thelayzells.com>2019-10-19 15:06:08 -0400
commit9be0bd8aa110bc580fb5d0f59e4f4fc96068c616 (patch)
tree34f73e42320000709100a9eb7da3315e444071d0 /src/libsyntax_ext
parente5b8c118a38e8f3319813de56386bf43751582d7 (diff)
downloadrust-9be0bd8aa110bc580fb5d0f59e4f4fc96068c616.tar.gz
rust-9be0bd8aa110bc580fb5d0f59e4f4fc96068c616.zip
Avoid ICE when include! is used by stdin crate
This should also eliminate the ICE when using `include_bytes!`, `include_str!`
and `#[doc(include = "...")]`.

Fixes #63900
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/source_util.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs
index 438e199ebdb..f6c58fcdfa1 100644
--- a/src/libsyntax_ext/source_util.rs
+++ b/src/libsyntax_ext/source_util.rs
@@ -76,7 +76,13 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
         None => return DummyResult::any(sp),
     };
     // The file will be added to the code map by the parser
-    let file = cx.resolve_path(file, sp);
+    let file = match cx.resolve_path(file, sp) {
+        Ok(f) => f,
+        Err(mut err) => {
+            err.emit();
+            return DummyResult::any(sp);
+        },
+    };
     let directory_ownership = DirectoryOwnership::Owned { relative: None };
     let p = parse::new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp);
 
@@ -122,7 +128,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
         Some(f) => f,
         None => return DummyResult::any(sp)
     };
-    let file = cx.resolve_path(file, sp);
+    let file = match cx.resolve_path(file, sp) {
+        Ok(f) => f,
+        Err(mut err) => {
+            err.emit();
+            return DummyResult::any(sp);
+        },
+    };
     match cx.source_map().load_binary_file(&file) {
         Ok(bytes) => match std::str::from_utf8(&bytes) {
             Ok(src) => {
@@ -147,7 +159,13 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream)
         Some(f) => f,
         None => return DummyResult::any(sp)
     };
-    let file = cx.resolve_path(file, sp);
+    let file = match cx.resolve_path(file, sp) {
+        Ok(f) => f,
+        Err(mut err) => {
+            err.emit();
+            return DummyResult::any(sp);
+        },
+    };
     match cx.source_map().load_binary_file(&file) {
         Ok(bytes) => {
             base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes))))