Skip to content

Commit b18bf8e

Browse files
committed
fix clippy
1 parent 8141d12 commit b18bf8e

4 files changed

Lines changed: 29 additions & 34 deletions

File tree

src/ast.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,12 @@ impl Program {
797797
let mut main_seen = false;
798798
for (item, mut warnings) in items {
799799
all_warnings.append(&mut warnings);
800-
match item {
801-
Item::Function(Function::Main(expr)) => {
802-
if main_seen {
803-
return Err(Error::FunctionRedefined(FunctionName::main())).with_span(from);
804-
}
805-
main_seen = true;
806-
main_expr = Some(expr);
800+
if let Item::Function(Function::Main(expr)) = item {
801+
if main_seen {
802+
return Err(Error::FunctionRedefined(FunctionName::main())).with_span(from);
807803
}
808-
_ => {}
804+
main_seen = true;
805+
main_expr = Some(expr);
809806
}
810807
}
811808
let main = main_expr.ok_or(Error::MainRequired).with_span(from)?;
@@ -1506,9 +1503,8 @@ impl AbstractSyntaxTree for CallName {
15061503
if function.params().len() != 2 || function.params()[1].ty() != function.body().ty()
15071504
{
15081505
return Err(Error::FunctionNotFoldable(name.clone())).with_span(from);
1509-
} else {
1510-
Self::ArrayFold(function, *size)
15111506
}
1507+
Self::ArrayFold(function, *size)
15121508
}
15131509
parse::CallName::Fold(name, bound) => {
15141510
let function = scope
@@ -1521,9 +1517,8 @@ impl AbstractSyntaxTree for CallName {
15211517
if function.params().len() != 2 || function.params()[1].ty() != function.body().ty()
15221518
{
15231519
return Err(Error::FunctionNotFoldable(name.clone())).with_span(from);
1524-
} else {
1525-
Self::Fold(function, *bound)
15261520
}
1521+
Self::Fold(function, *bound)
15271522
}
15281523
parse::CallName::ForWhile(name) => {
15291524
let function = scope

src/error.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<T> WithFilePath<T> for Result<T, RichError> {
149149
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
150150
pub struct RichError {
151151
/// The error that occurred.
152-
error: Error,
152+
error: Box<Error>,
153153
/// Area that the error spans inside the file.
154154
span: Span,
155155
/// File contents in which the error occurred.
@@ -164,7 +164,7 @@ impl RichError {
164164
/// Create a new error with context.
165165
pub fn new(error: Error, span: Span) -> RichError {
166166
RichError {
167-
error,
167+
error: Box::new(error),
168168
span,
169169
file: None,
170170
file_path: None,
@@ -193,7 +193,7 @@ impl RichError {
193193
/// a problem on the parsing side.
194194
pub fn parsing_error(reason: &str) -> Self {
195195
Self {
196-
error: Error::CannotParse(reason.to_string()),
196+
error: Box::new(Error::CannotParse(reason.to_string())),
197197
span: Span::new(0, 0),
198198
file: None,
199199
file_path: None,
@@ -315,7 +315,7 @@ impl std::error::Error for RichError {}
315315

316316
impl From<RichError> for Error {
317317
fn from(error: RichError) -> Self {
318-
error.error
318+
*error.error
319319
}
320320
}
321321

@@ -331,7 +331,7 @@ where
331331
I: ValueInput<'tokens, Token = Token<'src>, Span = Span>,
332332
{
333333
fn merge(self, other: Self) -> Self {
334-
match (&self.error, &other.error) {
334+
match (self.error.as_ref(), other.error.as_ref()) {
335335
(Error::Grammar(_), Error::Grammar(_)) => other,
336336
(Error::Grammar(_), _) => other,
337337
(_, Error::Grammar(_)) => self,
@@ -367,11 +367,11 @@ where
367367
let found_string = found.map(|t| t.to_string());
368368

369369
Self {
370-
error: Error::Syntax {
370+
error: Box::new(Error::Syntax {
371371
expected: expected_tokens,
372372
label: None,
373373
found: found_string,
374-
},
374+
}),
375375
span,
376376
file: None,
377377
file_path: None,
@@ -395,11 +395,11 @@ where
395395
let found_string = found.map(|t| t.to_string());
396396

397397
Self {
398-
error: Error::Syntax {
398+
error: Box::new(Error::Syntax {
399399
expected: expected_strings,
400400
label: None,
401401
found: found_string,
402-
},
402+
}),
403403
span,
404404
file: None,
405405
file_path: None,
@@ -409,7 +409,7 @@ where
409409
fn label_with(&mut self, label: &'tokens str) {
410410
if let Error::Syntax {
411411
label: ref mut l, ..
412-
} = &mut self.error
412+
} = self.error.as_mut()
413413
{
414414
*l = Some(label.to_string());
415415
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,8 @@ fn main() {
894894
let names = warning_names(prog);
895895
let unused: Vec<&str> = names
896896
.iter()
897-
.filter_map(|w| match w {
898-
WarningName::UnusedVariable(id) => Some(id.as_inner()),
897+
.map(|w| match w {
898+
WarningName::UnusedVariable(id) => id.as_inner(),
899899
})
900900
.collect();
901901
assert_eq!(

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
135135

136136
let deny_warnings = matches.get_flag("deny_warnings");
137137

138-
fn parse_warn_category(s: &str) -> Result<WarnCategory, String> {
139-
match s {
140-
"unused-variable" => Ok(WarnCategory::UnusedVariable),
141-
other => Err(format!(
142-
"unknown warning category `{other}`; valid categories: unused-variable"
143-
)),
144-
}
145-
}
146-
147138
let deny_categories: Vec<WarnCategory> = matches
148139
.get_many::<String>("deny_warning")
149140
.unwrap_or_default()
@@ -178,7 +169,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
178169

179170
let template = deny_categories
180171
.iter()
181-
.fold(Ok(template), |t, &cat| t.and_then(|t| t.deny_warning(cat)))
172+
.try_fold(template, |t, &cat| t.deny_warning(cat))
182173
.unwrap_or_else(|e| {
183174
eprintln!("{e}");
184175
std::process::exit(1);
@@ -268,3 +259,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
268259

269260
Ok(())
270261
}
262+
263+
fn parse_warn_category(s: &str) -> Result<WarnCategory, String> {
264+
match s {
265+
"unused-variable" => Ok(WarnCategory::UnusedVariable),
266+
other => Err(format!(
267+
"unknown warning category `{other}`; valid categories: unused-variable"
268+
)),
269+
}
270+
}

0 commit comments

Comments
 (0)