summaryrefslogtreecommitdiff
path: root/src/diag.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/diag.rs')
-rw-r--r--src/diag.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/diag.rs b/src/diag.rs
index 397a833f..0fcdef17 100644
--- a/src/diag.rs
+++ b/src/diag.rs
@@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};
-use crate::loading::FileId;
+use crate::source::SourceId;
use crate::syntax::Span;
/// The result type for typesetting and all its subpasses.
@@ -14,14 +14,14 @@ pub type StrResult<T> = Result<T, String>;
/// An error in a source file.
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub struct Error {
- /// The file that contains the error.
- pub file: FileId,
+ /// The id of the source file that contains the error.
+ pub source: SourceId,
/// The erroneous location in the source code.
pub span: Span,
/// A diagnostic message describing the problem.
pub message: String,
/// The trace of function calls leading to the error.
- pub trace: Vec<(FileId, Span, Tracepoint)>,
+ pub trace: Vec<(SourceId, Span, Tracepoint)>,
}
/// A part of an error's [trace](Error::trace).
@@ -35,9 +35,13 @@ pub enum Tracepoint {
impl Error {
/// Create a new, bare error.
- pub fn new(file: FileId, span: impl Into<Span>, message: impl Into<String>) -> Self {
+ pub fn new(
+ source: SourceId,
+ span: impl Into<Span>,
+ message: impl Into<String>,
+ ) -> Self {
Self {
- file,
+ source,
span: span.into(),
trace: vec![],
message: message.into(),
@@ -47,11 +51,11 @@ impl Error {
/// Create a boxed vector containing one error. The return value is suitable
/// as the `Err` variant of a [`TypResult`].
pub fn boxed(
- file: FileId,
+ source: SourceId,
span: impl Into<Span>,
message: impl Into<String>,
) -> Box<Vec<Self>> {
- Box::new(vec![Self::new(file, span, message)])
+ Box::new(vec![Self::new(source, span, message)])
}
/// Partially build a vec-boxed error, returning a function that just needs
@@ -60,23 +64,23 @@ impl Error {
/// This is useful in to convert from [`StrResult`] to a [`TypResult`] using
/// [`map_err`](Result::map_err).
pub fn partial(
- file: FileId,
+ source: SourceId,
span: impl Into<Span>,
) -> impl FnOnce(String) -> Box<Vec<Self>> {
- move |message| Self::boxed(file, span, message)
+ move |message| Self::boxed(source, span, message)
}
}
/// Early-return with a vec-boxed [`Error`].
#[macro_export]
macro_rules! bail {
- ($file:expr, $span:expr, $message:expr $(,)?) => {
+ ($source:expr, $span:expr, $message:expr $(,)?) => {
return Err(Box::new(vec![$crate::diag::Error::new(
- $file, $span, $message,
+ $source, $span, $message,
)]));
};
- ($file:expr, $span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => {
- $crate::bail!($file, $span, format!($fmt, $($arg),+));
+ ($source:expr, $span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => {
+ $crate::bail!($source, $span, format!($fmt, $($arg),+));
};
}