From 8207c31aec6336b773fbf4661fdb87625c8b584e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 10 Aug 2021 11:28:12 +0200 Subject: 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 --- src/eval/mod.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/eval') 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 { // 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) -> 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() + } } } -- cgit v1.2.3