Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ impl ErrKind {
pub struct Error {
kind: ErrKind,
msg: Option<String>,
loc: Option<SpanTuple>,
// We box the `SpanTuple` here to reduce the size of the `Error` enum.
// This makes clippy happy.
loc: Option<Box<SpanTuple>>,
hints: Vec<Error>,
}

Expand Down Expand Up @@ -265,12 +267,15 @@ impl Error {
// FIXME: Should this really take an Option<Location>?
#[deprecated]
pub fn with_opt_loc(self, loc: Option<SpanTuple>) -> Error {
Error { loc, ..self }
Error {
loc: loc.map(Box::new),
..self
}
}

pub fn with_loc(self, loc: SpanTuple) -> Error {
Error {
loc: Some(loc),
loc: Some(Box::new(loc)),
..self
}
}
Expand Down
10 changes: 5 additions & 5 deletions include_code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn get_final_path(
base: &Path,
location: &SpanTuple,
path: &Path,
) -> Result<PathBuf, (Error, Error)> {
) -> Result<PathBuf, Box<(Error, Error)>> {
// Check the local path first
let local_err = match load_local_library(base, location, path) {
Ok(path) => return Ok(path),
Expand All @@ -86,7 +86,7 @@ pub fn get_final_path(
Err(e) => e,
};

Err((local_err, home_err))
Err(Box::new((local_err, home_err)))
}

fn get_base(location: &SpanTuple) -> PathBuf {
Expand Down Expand Up @@ -123,9 +123,9 @@ impl Visitor for IncludeCtx {

let final_path = match get_final_path(&base, &location, &to_include) {
Ok(path) => path,
Err((e1, e2)) => {
e1.emit();
e2.emit();
Err(errs) => {
errs.0.emit();
errs.1.emit();
return Err(Error::new(ErrKind::Include));
}
};
Expand Down
9 changes: 3 additions & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,9 @@ impl Context {
self.error_handler
.set_path(self.path.clone().unwrap_or_default());

match &self.path {
Some(p) => {
self.included.insert(p.clone());
}
None => {}
};
if let Some(p) = &self.path {
self.included.insert(p.clone());
}
}

/// Add an error to the context
Expand Down
8 changes: 6 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl ErrKind {
pub struct Error {
kind: ErrKind,
msg: Option<String>,
loc: Option<SpanTuple>,
// Boxing to reduce the error's size to make clippy happy. This will eventually be removed anyway.
loc: Option<Box<SpanTuple>>,
hints: Vec<Error>,
}

Expand Down Expand Up @@ -224,7 +225,10 @@ impl Error {

// FIXME: Should this really take an Option<Location>?
pub fn with_loc(self, loc: Option<SpanTuple>) -> Error {
Error { loc, ..self }
Error {
loc: loc.map(Box::new),
..self
}
}

// Add a hint to emit alongside the error
Expand Down
10 changes: 5 additions & 5 deletions src/instruction/incl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Incl {
self.check_base(base)
}

pub fn get_final_path(&self, base: &Path) -> Result<PathBuf, (Error, Error)> {
pub fn get_final_path(&self, base: &Path) -> Result<PathBuf, Box<(Error, Error)>> {
// Check the local path first
let local_err = match self.load_local_library(base) {
Ok(path) => return Ok(path),
Expand All @@ -130,7 +130,7 @@ impl Incl {
Err(e) => e,
};

Err((local_err, home_err))
Err(Box::new((local_err, home_err)))
}
}

Expand Down Expand Up @@ -188,9 +188,9 @@ impl TypeCheck for Incl {

let final_path = match self.get_final_path(&base) {
Ok(path) => path,
Err((e1, e2)) => {
ctx.error(e1);
ctx.error(e2);
Err(errs) => {
ctx.error(errs.0);
ctx.error(errs.1);
return Err(Error::new(ErrKind::TypeChecker));
}
};
Expand Down
Loading