diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-10 11:28:12 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-10 11:28:12 +0200 |
| commit | 8207c31aec6336b773fbf4661fdb87625c8b584e (patch) | |
| tree | c1642033478081bec6c3eed693e92a469f0500e1 /src/eval/mod.rs | |
| parent | 3932bb2cb93be95d67fc56998423eb9ce047fdfa (diff) | |
Minor refactorings
- Reorder parser methods and use `Pos` everywhere
- Remove tab special handling for columns and adapt heading/list/enum indent handling
- Don't panic when a file has an empty path
Diffstat (limited to 'src/eval/mod.rs')
| -rw-r--r-- | src/eval/mod.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 22c7c0b4..e911596d 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -23,7 +23,7 @@ pub use value::*; use std::collections::HashMap; use std::io; use std::mem; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::rc::Rc; use crate::diag::{Error, StrResult, Tracepoint, TypResult}; @@ -107,7 +107,7 @@ impl<'a> EvalContext<'a> { /// Process an import of a module relative to the current location. pub fn import(&mut self, path: &str, span: Span) -> TypResult<SourceId> { // Load the source file. - let full = self.relpath(path); + let full = self.make_path(path); let id = self.sources.load(&full).map_err(|err| { Error::boxed(self.source, span, match err.kind() { io::ErrorKind::NotFound => "file not found".into(), @@ -157,15 +157,14 @@ impl<'a> EvalContext<'a> { Ok(id) } - /// Complete a path that is relative to the current file to be relative to - /// the environment's current directory. - pub fn relpath(&self, path: impl AsRef<Path>) -> PathBuf { - self.sources - .get(self.source) - .path() - .parent() - .expect("is a file") - .join(path) + /// Complete a user-entered path (relative to the source file) to be + /// relative to the compilation environment's root. + pub fn make_path(&self, path: &str) -> PathBuf { + if let Some(dir) = self.sources.get(self.source).path().parent() { + dir.join(path) + } else { + path.into() + } } } |
