diff --git a/error/src/lib.rs b/error/src/lib.rs index 8ab18fcd..fb950210 100644 --- a/error/src/lib.rs +++ b/error/src/lib.rs @@ -103,7 +103,9 @@ impl ErrKind { pub struct Error { kind: ErrKind, msg: Option, - loc: Option, + // We box the `SpanTuple` here to reduce the size of the `Error` enum. + // This makes clippy happy. + loc: Option>, hints: Vec, } @@ -265,12 +267,15 @@ impl Error { // FIXME: Should this really take an Option? #[deprecated] pub fn with_opt_loc(self, loc: Option) -> 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 } } diff --git a/include_code/src/lib.rs b/include_code/src/lib.rs index 976c5c24..2c2b1812 100644 --- a/include_code/src/lib.rs +++ b/include_code/src/lib.rs @@ -74,7 +74,7 @@ pub fn get_final_path( base: &Path, location: &SpanTuple, path: &Path, -) -> Result { +) -> Result> { // Check the local path first let local_err = match load_local_library(base, location, path) { Ok(path) => return Ok(path), @@ -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 { @@ -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)); } }; diff --git a/src/context.rs b/src/context.rs index dc0b3751..f716c750 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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 diff --git a/src/error.rs b/src/error.rs index 027515a4..e6bcce30 100644 --- a/src/error.rs +++ b/src/error.rs @@ -91,7 +91,8 @@ impl ErrKind { pub struct Error { kind: ErrKind, msg: Option, - loc: Option, + // Boxing to reduce the error's size to make clippy happy. This will eventually be removed anyway. + loc: Option>, hints: Vec, } @@ -224,7 +225,10 @@ impl Error { // FIXME: Should this really take an Option? pub fn with_loc(self, loc: Option) -> Error { - Error { loc, ..self } + Error { + loc: loc.map(Box::new), + ..self + } } // Add a hint to emit alongside the error diff --git a/src/instruction/incl.rs b/src/instruction/incl.rs index 85320865..5d52e6a1 100644 --- a/src/instruction/incl.rs +++ b/src/instruction/incl.rs @@ -118,7 +118,7 @@ impl Incl { self.check_base(base) } - pub fn get_final_path(&self, base: &Path) -> Result { + pub fn get_final_path(&self, base: &Path) -> Result> { // Check the local path first let local_err = match self.load_local_library(base) { Ok(path) => return Ok(path), @@ -130,7 +130,7 @@ impl Incl { Err(e) => e, }; - Err((local_err, home_err)) + Err(Box::new((local_err, home_err))) } } @@ -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)); } };