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

Fix clippy warnings #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions eipw-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ enum Source<'a> {
File(&'a Path),
}

impl<'a> Source<'a> {
impl Source<'_> {
fn origin(&self) -> Option<&Path> {
match self {
Self::String {
Expand All @@ -509,8 +509,7 @@ impl<'a> Source<'a> {
Self::File(f) => fetch
.fetch(f.to_path_buf())
.await
.with_context(|_| IoSnafu { path: f.to_owned() })
.map_err(Into::into),
.with_context(|_| IoSnafu { path: f.to_owned() }),
Self::String { src, .. } => Ok((*src).to_owned()),
}
}
Expand Down Expand Up @@ -565,6 +564,10 @@ impl<M, L> Default for Options<M, L> {
}
}

// Type aliases for the iterators with lifetime annotations
type ModifierIterator<'a> = dyn Iterator<Item = Box<dyn Modifier>> + 'a;
type LintIterator<'a> = dyn Iterator<Item = (&'a str, Box<dyn Lint>)> + 'a;

impl<M, L, K> Options<Vec<M>, HashMap<K, L>>
where
M: 'static + Clone + Modifier,
Expand All @@ -574,17 +577,19 @@ where
pub fn to_iters(
&self,
) -> Options<
impl Iterator<Item = Box<dyn Modifier>> + '_,
impl Iterator<Item = (&'_ str, Box<dyn Lint>)>,
Box<ModifierIterator<'_>>, // Use boxed trait objects
Box<LintIterator<'_>>, // Use boxed trait objects
> {
let modifiers = self
.modifiers
.as_ref()
.map(|m| m.iter().map(|n| Box::new(n.clone()) as Box<dyn Modifier>));
let modifiers = self.modifiers.as_ref().map(|m| {
Box::new(m.iter().map(|n| Box::new(n.clone()) as Box<dyn Modifier>))
as Box<dyn Iterator<Item = Box<dyn Modifier>>>
});

let lints = self.lints.as_ref().map(|l| {
l.iter()
.map(|(k, v)| (k.as_ref(), Box::new(v.clone()) as Box<dyn Lint>))
Box::new(
l.iter()
.map(|(k, v)| (k.as_ref(), Box::new(v.clone()) as Box<dyn Lint>)),
) as Box<dyn Iterator<Item = (&'_ str, Box<dyn Lint>)>>
});

Options {
Expand Down Expand Up @@ -612,7 +617,7 @@ pub struct Linter<'a, R> {
fetch: Box<dyn fetch::Fetch>,
}

impl<'a, R> Default for Linter<'a, R>
impl<R> Default for Linter<'_, R>
where
R: Default,
{
Expand Down Expand Up @@ -927,7 +932,7 @@ fn process<'a>(
) -> Result<Option<InnerContext<'a>>, Error> {
let (preamble_source, body_source) = match Preamble::split(source) {
Ok(v) => v,
Err(SplitError::MissingStart { .. }) | Err(SplitError::LeadingGarbage { .. }) => {
Err(SplitError::MissingStart) | Err(SplitError::LeadingGarbage) => {
let mut footer = Vec::new();
if source.as_bytes().get(3) == Some(&b'\r') {
footer.push(Level::Help.title(
Expand All @@ -952,7 +957,7 @@ fn process<'a>(
})?;
return Ok(None);
}
Err(SplitError::MissingEnd { .. }) => {
Err(SplitError::MissingEnd) => {
reporter
.report(
Level::Error
Expand Down
2 changes: 1 addition & 1 deletion eipw-lint/src/lints/markdown/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct Visitor<'a, 'b, 'c> {
schema: Validator,
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_code_block(&mut self, ast: &Ast, node: &NodeCodeBlock) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/link_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Visitor<'a, 'b, 'c> {
own_number: Option<u32>,
}

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
impl Visitor<'_, '_, '_> {
fn check(&self, ast: &Ast, text: &str) -> Result<Next, Error> {
for matched in self.re.captures_iter(text) {
let self_reference = match self.own_number {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_front_matter(&mut self, _: &Ast, _: &str) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/no_backticks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Visitor<'a, 'b, 'c> {
slug: &'c str,
}

impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
impl Visitor<'_, '_, '_> {
fn check(&mut self, ast: &Ast, text: &str) -> Result<Next, Error> {
if !self.re.is_match(text) {
return Ok(Next::TraverseChildren);
Expand All @@ -74,7 +74,7 @@ impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
impl tree::Visitor for Visitor<'_, '_, '_> {
type Error = Error;

fn enter_code(&mut self, ast: &Ast, code: &NodeCode) -> Result<Next, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions eipw-lint/src/lints/markdown/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct ExcludesVisitor<'a, 'b, 'c> {
message: &'c str,
}

impl<'a, 'b, 'c> ExcludesVisitor<'a, 'b, 'c> {
impl ExcludesVisitor<'_, '_, '_> {
fn check(&self, ast: &Ast, buf: &str) -> Result<Next, Error> {
if !self.re.is_match(buf) {
return Ok(Next::TraverseChildren);
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a, 'b, 'c> ExcludesVisitor<'a, 'b, 'c> {
}
}

impl<'a, 'b, 'c> tree::Visitor for ExcludesVisitor<'a, 'b, 'c> {
impl tree::Visitor for ExcludesVisitor<'_, '_, '_> {
type Error = Error;

fn enter_front_matter(&mut self, _: &Ast, _: &str) -> Result<Next, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion eipw-lint/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub trait TraverseExt {
V: Visitor;
}

impl<'a> TraverseExt for Traverse<'a, RefCell<Ast>> {
impl TraverseExt for Traverse<'_, RefCell<Ast>> {
fn visit<V>(self, visitor: &mut V) -> Result<(), V::Error>
where
V: Visitor,
Expand Down