diff --git a/bin/generate-book/src/main.rs b/bin/generate-book/src/main.rs index 4dc9cac..bb05954 100644 --- a/bin/generate-book/src/main.rs +++ b/bin/generate-book/src/main.rs @@ -1,7 +1,7 @@ use { pulldown_cmark::{CowStr, Event, HeadingLevel, Options, Parser, Tag}, pulldown_cmark_to_cmark::cmark, - std::{collections::BTreeMap, error::Error, fs, ops::Deref}, + std::{collections::BTreeMap, error::Error, fmt::Write, fs, ops::Deref}, }; type Result = std::result::Result>; @@ -174,12 +174,13 @@ fn main() -> Result { HeadingLevel::H5 => 4, HeadingLevel::H6 => 5, }; - summary.push_str(&format!( - "{}- [{}](chapter_{}.md)\n", + writeln!( + summary, + "{}- [{}](chapter_{}.md)", " ".repeat(indent * 4), chapter.title(), chapter.number() - )); + )?; } fs::write(format!("{}/SUMMARY.md", src), summary).unwrap(); diff --git a/src/color_display.rs b/src/color_display.rs index 4729621..384a724 100644 --- a/src/color_display.rs +++ b/src/color_display.rs @@ -1,7 +1,7 @@ use super::*; pub(crate) trait ColorDisplay { - fn color_display<'a>(&'a self, color: Color) -> Wrapper<'a> + fn color_display(&self, color: Color) -> Wrapper where Self: Sized, { diff --git a/src/config.rs b/src/config.rs index 2a1085f..f27b98e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -605,7 +605,7 @@ impl Config { } } - pub(crate) fn run<'src>(self, loader: &'src Loader) -> Result<(), Error<'src>> { + pub(crate) fn run(self, loader: &Loader) -> Result<(), Error> { if let Err(error) = InterruptHandler::install(self.verbosity) { warn!("Failed to set CTRL-C handler: {}", error); } diff --git a/src/lib.rs b/src/lib.rs index 667e04b..4aa7ead 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,8 @@ #![deny(clippy::all, clippy::pedantic)] #![allow( clippy::doc_markdown, - clippy::empty_enum, clippy::enum_glob_use, - clippy::if_not_else, clippy::missing_errors_doc, - clippy::needless_lifetimes, clippy::needless_pass_by_value, clippy::non_ascii_literal, clippy::shadow_unrelated, diff --git a/src/parser.rs b/src/parser.rs index cb197e0..ac6324e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -179,14 +179,14 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { "Presumed next token would have kind {}, but found {}", Identifier, next.kind ))?) - } else if keyword != next.lexeme() { + } else if keyword == next.lexeme() { + Ok(()) + } else { Err(self.internal_error(format!( "Presumed next token would have lexeme \"{}\", but found \"{}\"", keyword, next.lexeme(), ))?) - } else { - Ok(()) } } @@ -194,27 +194,27 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { fn presume(&mut self, kind: TokenKind) -> CompileResult<'src, Token<'src>> { let next = self.advance()?; - if next.kind != kind { + if next.kind == kind { + Ok(next) + } else { Err(self.internal_error(format!( "Presumed next token would have kind {:?}, but found {:?}", kind, next.kind ))?) - } else { - Ok(next) } } /// Return an internal error if the next token is not one of kinds `kinds`. fn presume_any(&mut self, kinds: &[TokenKind]) -> CompileResult<'src, Token<'src>> { let next = self.advance()?; - if !kinds.contains(&next.kind) { + if kinds.contains(&next.kind) { + Ok(next) + } else { Err(self.internal_error(format!( "Presumed next token would be {}, but found {}", List::or(kinds), next.kind ))?) - } else { - Ok(next) } } @@ -357,16 +357,16 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { } } - if self.next != self.tokens.len() { - Err(self.internal_error(format!( - "Parse completed with {} unparsed tokens", - self.tokens.len() - self.next, - ))?) - } else { + if self.next == self.tokens.len() { Ok(Ast { warnings: Vec::new(), items, }) + } else { + Err(self.internal_error(format!( + "Parse completed with {} unparsed tokens", + self.tokens.len() - self.next, + ))?) } } diff --git a/src/positional.rs b/src/positional.rs index 79b318e..a74a474 100644 --- a/src/positional.rs +++ b/src/positional.rs @@ -26,7 +26,7 @@ use super::*; /// /// For modes that do take other arguments, the search argument is simply /// prepended to rest. -#[cfg_attr(test, derive(PartialEq, Debug))] +#[cfg_attr(test, derive(PartialEq, Eq, Debug))] pub struct Positional { /// Overrides from values of the form `[a-zA-Z_][a-zA-Z0-9_-]*=.*` pub overrides: Vec<(String, String)>, diff --git a/src/subcommand.rs b/src/subcommand.rs index 60ab95c..7174f36 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -356,7 +356,9 @@ impl Subcommand { let formatted = ast.to_string(); if config.check { - return if formatted != src { + return if formatted == src { + Ok(()) + } else { use similar::{ChangeTag, TextDiff}; let diff = TextDiff::configure() @@ -376,8 +378,6 @@ impl Subcommand { } Err(Error::FormatCheckFoundDiff) - } else { - Ok(()) }; } @@ -421,11 +421,11 @@ impl Subcommand { continue; } - if !recipe_aliases.contains_key(alias.target.name.lexeme()) { - recipe_aliases.insert(alias.target.name.lexeme(), vec![alias.name.lexeme()]); - } else { + if recipe_aliases.contains_key(alias.target.name.lexeme()) { let aliases = recipe_aliases.get_mut(alias.target.name.lexeme()).unwrap(); aliases.push(alias.name.lexeme()); + } else { + recipe_aliases.insert(alias.target.name.lexeme(), vec![alias.name.lexeme()]); } }