From 2dd5246506bbc74655c752c3c18369b1083dac63 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 17:03:16 -0400 Subject: [PATCH] Apply more suggestions. --- src/compare/compare_field.rs | 4 +--- src/parser/radio_link.rs | 5 ++--- src/parser/subscript_and_superscript.rs | 4 ++-- src/parser/table.rs | 2 +- src/parser/target.rs | 2 +- src/parser/text_markup.rs | 27 +++++++++++-------------- src/parser/timestamp.rs | 3 ++- src/parser/util.rs | 5 +---- src/types/util.rs | 14 ++++++------- 9 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 47e6c9ed..a5592433 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -69,9 +69,7 @@ pub(crate) fn compare_noop<'b, 's, 'x, R, RG>( /// Do no comparison. /// /// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values. -pub(crate) fn compare_identity() -> () { - () -} +pub(crate) fn compare_identity() {} /// Assert that the emacs value is always nil or absent. /// diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 4dde382d..499020dc 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -232,8 +232,7 @@ mod tests { let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let paragraph_matcher = parser_with_context!(element(true))(&initial_context); - let (remaining, first_paragraph) = - paragraph_matcher(input.into()).expect("Parse first paragraph"); + let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph"); let first_paragraph = match first_paragraph { Element::Paragraph(paragraph) => paragraph, _ => panic!("Should be a paragraph!"), @@ -255,7 +254,7 @@ mod tests { source: "*bar* ", children: vec![Object::PlainText(PlainText { source: "bar" })] })], - path: "*bar* ".into() + path: "*bar* " }) ); } diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 0736bc3f..66783ecd 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -233,7 +233,7 @@ fn _script_with_braces_end<'b, 'g, 'r, 's>( if current_depth > 0 { // Its impossible for the next character to end the subscript or superscript if we're any amount of braces deep return Err(nom::Err::Error(CustomError::MyError(MyError( - "Not a valid end for subscript or superscript.".into(), + "Not a valid end for subscript or superscript.", )))); } if current_depth < 0 { @@ -288,6 +288,6 @@ fn _script_with_parenthesis_end<'s>( } } Err(nom::Err::Error(CustomError::MyError(MyError( - "No script parenthesis end.".into(), + "No script parenthesis end.", )))) } diff --git a/src/parser/table.rs b/src/parser/table.rs index e1079dbb..775b4c62 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -197,7 +197,7 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>( let (remaining, (children, _exit_contents)) = verify( many_till(table_cell_set_object_matcher, exit_matcher), |(children, exit_contents)| { - !children.is_empty() || Into::<&str>::into(exit_contents).ends_with("|") + !children.is_empty() || Into::<&str>::into(exit_contents).ends_with('|') }, )(remaining)?; diff --git a/src/parser/target.rs b/src/parser/target.rs index 187721cf..6ab0e61d 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -43,7 +43,7 @@ pub(crate) fn target<'b, 'g, 'r, 's>( .expect("We cannot be at the start of the file because we are inside a target."); if preceding_character.is_whitespace() { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Targets cannot end with whitespace.".into(), + "Targets cannot end with whitespace.", )))); } let (remaining, _) = tag(">>")(remaining)?; diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index c771ba9c..6606ad55 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -183,13 +183,13 @@ fn code<'b, 'g, 'r, 's>( )) } -fn text_markup_object<'c>( - marker_symbol: &'c str, +fn text_markup_object( + marker_symbol: &str, ) -> impl for<'b, 'g, 'r, 's> Fn( RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, ) -> Res, Vec>> - + 'c { + + '_ { move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol) } @@ -235,7 +235,7 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>( let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Parent exit matcher is triggering.".into(), + "Parent exit matcher is triggering.", )))); } } @@ -246,13 +246,13 @@ fn _text_markup_object<'b, 'g, 'r, 's, 'c>( Ok((remaining, children)) } -fn text_markup_string<'c>( - marker_symbol: &'c str, +fn text_markup_string( + marker_symbol: &str, ) -> impl for<'b, 'g, 'r, 's> Fn( RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, ) -> Res, OrgSource<'s>> - + 'c { + + '_ { move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol) } @@ -291,7 +291,7 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>( let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Parent exit matcher is triggering.".into(), + "Parent exit matcher is triggering.", )))); } } @@ -322,7 +322,7 @@ fn pre<'b, 'g, 'r, 's>( Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {} Some(_) => { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Not a valid pre character for text markup.".into(), + "Not a valid pre character for text markup.", )))); } None => unreachable!(), // None is for start of file, which should already be handled by the start_of_line matcher above. @@ -343,10 +343,7 @@ fn post<'b, 'g, 'r, 's>( Ok((remaining, ())) } -fn text_markup_end<'c>( - marker_symbol: &'c str, - contents_start_offset: usize, -) -> impl ContextMatcher + 'c { +fn text_markup_end(marker_symbol: &str, contents_start_offset: usize) -> impl ContextMatcher + '_ { move |context, input: OrgSource<'_>| { _text_markup_end(context, input, marker_symbol, contents_start_offset) } @@ -364,7 +361,7 @@ fn _text_markup_end<'b, 'g, 'r, 's, 'c>( ) -> Res, OrgSource<'s>> { if input.get_byte_offset() == contents_start_offset { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Text markup cannot be empty".into(), + "Text markup cannot be empty", )))); } not(preceded_by_whitespace(false))(input)?; @@ -499,7 +496,7 @@ fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>( let _enter = span.enter(); if exit_matcher_parser(context, remaining).is_ok() { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Parent exit matcher is triggering.".into(), + "Parent exit matcher is triggering.", )))); } } diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index e70e6721..926e9694 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -486,7 +486,7 @@ fn dayname_end<'b, 'g, 'r, 's>( }))(input) } -const fn time<'c>( +const fn time( allow_rest: bool, ) -> impl for<'b, 'g, 'r, 's> Fn(RefContext<'b, 'g, 'r, 's>, OrgSource<'s>) -> Res, Time<'s>> { @@ -590,6 +590,7 @@ fn time_range_rest_end<'b, 'g, 'r, 's>( tag("-"), parser_with_context!(time(true))(&parent_node), )))(input); + #[allow(clippy::let_and_return)] // otherwise parent_node does not live long enough. exit_contents } diff --git a/src/parser/util.rs b/src/parser/util.rs index 75744099..95155a6d 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -28,10 +28,7 @@ pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; /// Check if we are below a section of the given section type regardless of depth -pub(crate) fn in_section<'b, 'g, 'r, 's, 'x>( - context: RefContext<'b, 'g, 'r, 's>, - section_name: &'x str, -) -> bool { +pub(crate) fn in_section(context: RefContext<'_, '_, '_, '_>, section_name: &str) -> bool { for thing in context.iter() { match thing { ContextElement::Context(name) if *name == section_name => return true, diff --git a/src/types/util.rs b/src/types/util.rs index 833ee422..5592be75 100644 --- a/src/types/util.rs +++ b/src/types/util.rs @@ -120,15 +120,13 @@ pub(crate) fn coalesce_whitespace_if_line_break(input: &str) -> Cow<'_, str> { ret.push(c); } // Do nothing if preceding character was whitespace and this character also is whitespace. + } else if c.is_ascii_whitespace() { + // Preceding character was not whitespace but this is. + sub_loop_in_whitespace = true; + ret.push(' '); } else { - if c.is_ascii_whitespace() { - // Preceding character was not whitespace but this is. - sub_loop_in_whitespace = true; - ret.push(' '); - } else { - // Preceding character was not whitespace and this is not either. - ret.push(c); - } + // Preceding character was not whitespace and this is not either. + ret.push(c); } } if !*in_whitespace {