diff options
| author | Nika Layzell <nika@thelayzells.com> | 2019-10-19 13:05:46 -0400 |
|---|---|---|
| committer | Nika Layzell <nika@thelayzells.com> | 2019-10-19 15:06:08 -0400 |
| commit | 9be0bd8aa110bc580fb5d0f59e4f4fc96068c616 (patch) | |
| tree | 34f73e42320000709100a9eb7da3315e444071d0 /src/libsyntax_expand | |
| parent | e5b8c118a38e8f3319813de56386bf43751582d7 (diff) | |
| download | rust-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_expand')
| -rw-r--r-- | src/libsyntax_expand/base.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax_expand/expand.rs | 9 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index c222e7357ac..58edf23a5b1 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -1072,7 +1072,11 @@ impl<'a> ExtCtxt<'a> { /// This unifies the logic used for resolving `include_X!`, and `#[doc(include)]` file paths. /// /// Returns an absolute path to the file that `path` refers to. - pub fn resolve_path(&self, path: impl Into<PathBuf>, span: Span) -> PathBuf { + pub fn resolve_path( + &self, + path: impl Into<PathBuf>, + span: Span, + ) -> Result<PathBuf, DiagnosticBuilder<'a>> { let path = path.into(); // Relative paths are resolved relative to the file in which they are found @@ -1082,13 +1086,16 @@ impl<'a> ExtCtxt<'a> { let mut result = match self.source_map().span_to_unmapped_path(callsite) { FileName::Real(path) => path, FileName::DocTest(path, _) => path, - other => panic!("cannot resolve relative path in non-file source `{}`", other), + other => return Err(self.struct_span_err( + span, + &format!("cannot resolve relative path in non-file source `{}`", other), + )), }; result.pop(); result.push(path); - result + Ok(result) } else { - path + Ok(path) } } } diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index f03d464eafb..fc521e5edc0 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -1418,7 +1418,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { return noop_visit_attribute(at, self); } - let filename = self.cx.resolve_path(&*file.as_str(), it.span()); + let filename = match self.cx.resolve_path(&*file.as_str(), it.span()) { + Ok(filename) => filename, + Err(mut err) => { + err.emit(); + continue; + } + }; + match self.cx.source_map().load_file(&filename) { Ok(source_file) => { let src = source_file.src.as_ref() |
