Skip to content

Commit 29544d2

Browse files
committed
clippy: Reduce the size of the Error(s) enums
1 parent 526f964 commit 29544d2

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

error/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl ErrKind {
103103
pub struct Error {
104104
kind: ErrKind,
105105
msg: Option<String>,
106-
loc: Option<SpanTuple>,
106+
// We box the `SpanTuple` here to reduce the size of the `Error` enum.
107+
// This makes clippy happy.
108+
loc: Option<Box<SpanTuple>>,
107109
hints: Vec<Error>,
108110
}
109111

@@ -265,12 +267,15 @@ impl Error {
265267
// FIXME: Should this really take an Option<Location>?
266268
#[deprecated]
267269
pub fn with_opt_loc(self, loc: Option<SpanTuple>) -> Error {
268-
Error { loc, ..self }
270+
Error {
271+
loc: loc.map(Box::new),
272+
..self
273+
}
269274
}
270275

271276
pub fn with_loc(self, loc: SpanTuple) -> Error {
272277
Error {
273-
loc: Some(loc),
278+
loc: Some(Box::new(loc)),
274279
..self
275280
}
276281
}

include_code/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn get_final_path(
7474
base: &Path,
7575
location: &SpanTuple,
7676
path: &Path,
77-
) -> Result<PathBuf, (Error, Error)> {
77+
) -> Result<PathBuf, Box<(Error, Error)>> {
7878
// Check the local path first
7979
let local_err = match load_local_library(base, location, path) {
8080
Ok(path) => return Ok(path),
@@ -86,7 +86,7 @@ pub fn get_final_path(
8686
Err(e) => e,
8787
};
8888

89-
Err((local_err, home_err))
89+
Err(Box::new((local_err, home_err)))
9090
}
9191

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

124124
let final_path = match get_final_path(&base, &location, &to_include) {
125125
Ok(path) => path,
126-
Err((e1, e2)) => {
127-
e1.emit();
128-
e2.emit();
126+
Err(errs) => {
127+
errs.0.emit();
128+
errs.1.emit();
129129
return Err(Error::new(ErrKind::Include));
130130
}
131131
};

src/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ impl ErrKind {
9191
pub struct Error {
9292
kind: ErrKind,
9393
msg: Option<String>,
94-
loc: Option<SpanTuple>,
94+
// Boxing to reduce the error's size to make clippy happy. This will eventually be removed anyway.
95+
loc: Option<Box<SpanTuple>>,
9596
hints: Vec<Error>,
9697
}
9798

@@ -224,7 +225,10 @@ impl Error {
224225

225226
// FIXME: Should this really take an Option<Location>?
226227
pub fn with_loc(self, loc: Option<SpanTuple>) -> Error {
227-
Error { loc, ..self }
228+
Error {
229+
loc: loc.map(Box::new),
230+
..self
231+
}
228232
}
229233

230234
// Add a hint to emit alongside the error

src/instruction/incl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Incl {
118118
self.check_base(base)
119119
}
120120

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

133-
Err((local_err, home_err))
133+
Err(Box::new((local_err, home_err)))
134134
}
135135
}
136136

@@ -188,9 +188,9 @@ impl TypeCheck for Incl {
188188

189189
let final_path = match self.get_final_path(&base) {
190190
Ok(path) => path,
191-
Err((e1, e2)) => {
192-
ctx.error(e1);
193-
ctx.error(e2);
191+
Err(errs) => {
192+
ctx.error(errs.0);
193+
ctx.error(errs.1);
194194
return Err(Error::new(ErrKind::TypeChecker));
195195
}
196196
};

0 commit comments

Comments
 (0)