Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fewer lints #1340

Merged
merged 7 commits into from
Sep 11, 2022
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
9 changes: 5 additions & 4 deletions bin/generate-book/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<T = ()> = std::result::Result<T, Box<dyn Error>>;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/color_display.rs
Original file line number Diff line number Diff line change
@@ -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,
{
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
30 changes: 15 additions & 15 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,42 +179,42 @@ 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(())
}
}

/// Return an internal error if the next token is not of kind `kind`.
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)
}
}

Expand Down Expand Up @@ -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,
))?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>,
Expand Down
12 changes: 6 additions & 6 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -376,8 +378,6 @@ impl Subcommand {
}

Err(Error::FormatCheckFoundDiff)
} else {
Ok(())
};
}

Expand Down Expand Up @@ -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()]);
}
}

Expand Down