From 8d85d5ef79e603ac27659a370ad398b4c57b72a0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 22 Feb 2025 19:42:24 -0500 Subject: [PATCH] Fix clippy. --- src/context/src_block.rs | 2 +- src/intermediate/footnote_definition.rs | 1 + src/intermediate/macros.rs | 1 + src/intermediate/paragraph.rs | 17 +++++++++-------- src/intermediate/registry.rs | 1 + src/intermediate/regular_link.rs | 9 ++++----- src/intermediate/src_block.rs | 4 ++-- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/context/src_block.rs b/src/context/src_block.rs index 58c06fd..cfc98dc 100644 --- a/src/context/src_block.rs +++ b/src/context/src_block.rs @@ -55,7 +55,7 @@ render!(RenderSrcBlock, ISrcBlock, original, render_context, { RenderSrcLine { children } }) .collect(); - match original.language.as_ref().map(String::as_str) { + match original.language.as_deref() { Some("bash") => { render_context .dependency_manager diff --git a/src/intermediate/footnote_definition.rs b/src/intermediate/footnote_definition.rs index 38085bf..f82753e 100644 --- a/src/intermediate/footnote_definition.rs +++ b/src/intermediate/footnote_definition.rs @@ -32,6 +32,7 @@ pub(crate) struct IRealFootnoteDefinition { } impl IRealFootnoteDefinition { + #[allow(clippy::needless_lifetimes)] pub(crate) async fn new<'orig, 'parse>( _intermediate_context: IntermediateContext<'orig, 'parse>, footnote_id: usize, diff --git a/src/intermediate/macros.rs b/src/intermediate/macros.rs index 54f877e..203355d 100644 --- a/src/intermediate/macros.rs +++ b/src/intermediate/macros.rs @@ -9,6 +9,7 @@ macro_rules! inoop { } impl $istruct { + #[allow(clippy::extra_unused_lifetimes)] pub(crate) async fn new<'reg, 'orig, 'parse>( _intermediate_context: crate::intermediate::IntermediateContext<'orig, 'parse>, original: &'orig organic::types::$pstruct<'parse>, diff --git a/src/intermediate/paragraph.rs b/src/intermediate/paragraph.rs index bf57a4a..6b022b6 100644 --- a/src/intermediate/paragraph.rs +++ b/src/intermediate/paragraph.rs @@ -31,6 +31,7 @@ intermediate!( ); impl IParagraph { + #[allow(clippy::needless_lifetimes)] pub(crate) async fn artificial<'orig, 'parse>( _intermediate_context: crate::intermediate::IntermediateContext<'orig, 'parse>, children: Vec, @@ -50,19 +51,19 @@ impl IParagraph { .children .iter() .filter(|c| match c { - IObject::RegularLink(iregular_link) => match &iregular_link.target { - super::LinkTarget::Image { src: _, alt: _ } => true, - _ => false, - }, + IObject::RegularLink(iregular_link) => matches!( + &iregular_link.target, + super::LinkTarget::Image { src: _, alt: _ } + ), _ => false, }) .count(); num_images == 1 && self.children.iter().all(|c| match c { - IObject::RegularLink(iregular_link) => match &iregular_link.target { - super::LinkTarget::Image { src: _, alt: _ } => true, - _ => false, - }, + IObject::RegularLink(iregular_link) => matches!( + &iregular_link.target, + super::LinkTarget::Image { src: _, alt: _ } + ), IObject::PlainText(iplain_text) => { iplain_text.source.chars().all(|c| c.is_ascii_whitespace()) } diff --git a/src/intermediate/registry.rs b/src/intermediate/registry.rs index f9335b7..30d5830 100644 --- a/src/intermediate/registry.rs +++ b/src/intermediate/registry.rs @@ -180,6 +180,7 @@ async fn convert_definition_contents<'orig, 'parse>( } /// Take a footnote definition that has not yet received a reference and move it into the active footnotes. +#[allow(clippy::needless_lifetimes)] pub(crate) async fn promote_footnote_definition<'orig, 'parse>( intermediate_context: IntermediateContext<'orig, 'parse>, label: &'parse str, diff --git a/src/intermediate/regular_link.rs b/src/intermediate/regular_link.rs index 63544e0..8f384b6 100644 --- a/src/intermediate/regular_link.rs +++ b/src/intermediate/regular_link.rs @@ -186,7 +186,7 @@ impl LinkTarget { if path.is_absolute() { return Ok(format!("file://{}", input)); } - return Ok(input.into_owned()); + Ok(input.into_owned()) } /// Get file name from the last segment of an image path. @@ -199,7 +199,7 @@ impl LinkTarget { let path = Path::new(input.as_ref()); match path .components() - .last() + .next_back() .ok_or("Images should have at least one component in their path.")? { std::path::Component::Prefix(_) => { @@ -209,9 +209,7 @@ impl LinkTarget { std::path::Component::RootDir | std::path::Component::CurDir | std::path::Component::ParentDir => { - return Err( - "Final component of an image path should be a normal component.".into(), - ); + Err("Final component of an image path should be a normal component.".into()) } std::path::Component::Normal(file_name) => Ok(file_name .to_str() @@ -236,6 +234,7 @@ mod tests { let registry = Registry::new(); let registry = Arc::new(Mutex::new(registry)); let intermediate_context = IntermediateContext::new(registry)?; + #[allow(clippy::single_element_loop)] for (inp, typ) in [( "https://test.example/foo", LinkType::Protocol(Cow::from("https")), diff --git a/src/intermediate/src_block.rs b/src/intermediate/src_block.rs index 39c018d..e13c518 100644 --- a/src/intermediate/src_block.rs +++ b/src/intermediate/src_block.rs @@ -77,7 +77,7 @@ intermediate!( .collect(); let language = original.language.map(str::to_owned); - match language.as_ref().map(String::as_str) { + match language.as_deref() { Some(lang @ "bash") => { let highlighted = highlight_bash(&lines); if let Ok(highlighted) = highlighted { @@ -151,7 +151,7 @@ where std::string::String: for<'a> From<&'a L>, { Ok(lines - .into_iter() + .iter() .map(|l| { let mut line = ISrcLine::new(); line.children.push(ISrcSegment::RawText(l.into()));