From 9b5a4a385ad8892d02d9b37abbb300f7753a224a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Gr=C3=BCbel?= Date: Tue, 9 Apr 2024 01:39:08 +0900 Subject: [PATCH] chore: update winnow to 0.6+ and vecmap-rs to 0.2+ (#324) * update winnow to 0.6+ and vecmap-rs to 0.2+ * fix clippy warnings --- Cargo.lock | 8 +++--- crates/hcl-edit/Cargo.toml | 8 +++--- crates/hcl-edit/src/parser/expr.rs | 37 +++++++++++++------------ crates/hcl-edit/src/parser/string.rs | 24 ++++++++-------- crates/hcl-edit/src/parser/structure.rs | 2 +- crates/hcl-edit/src/parser/trivia.rs | 10 +++---- crates/hcl-rs/Cargo.toml | 2 +- crates/hcl-rs/src/eval/expr.rs | 1 + crates/hcl-rs/src/eval/impls.rs | 2 +- crates/hcl-rs/src/expr/de.rs | 1 + crates/hcl-rs/src/ser/mod.rs | 2 +- 11 files changed, 50 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32c92a19..28721a46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -749,9 +749,9 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "vecmap-rs" -version = "0.1.12" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad664eb33a8dd1f8d70a8fdab8f65ec0cca43b3b0151b3ff8a1e19f5f2a1d57" +checksum = "67d9c76f2c769d47dec11c6f4a9cd3be5e5e025a6bce297b07a311a3514ca97d" dependencies = [ "serde", ] @@ -942,9 +942,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.5.15" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" dependencies = [ "memchr", ] diff --git a/crates/hcl-edit/Cargo.toml b/crates/hcl-edit/Cargo.toml index 5dd0fa66..cb128fff 100644 --- a/crates/hcl-edit/Cargo.toml +++ b/crates/hcl-edit/Cargo.toml @@ -30,14 +30,14 @@ default = [] perf = ["hcl-primitives/perf"] [dependencies] -fnv = "1.0.7" +fnv = "1.0" hcl-primitives = { version = "0.1.2", path = "../hcl-primitives" } -vecmap-rs = "0.1.12" -winnow = "0.5.15" +vecmap-rs = "0.2" +winnow = "0.6" [dev-dependencies] indoc = "2.0" -pretty_assertions = "1.4.0" +pretty_assertions = "1.4" testdata = { path = "../testdata" } [[example]] diff --git a/crates/hcl-edit/src/parser/expr.rs b/crates/hcl-edit/src/parser/expr.rs index d2a34911..7d086e59 100644 --- a/crates/hcl-edit/src/parser/expr.rs +++ b/crates/hcl-edit/src/parser/expr.rs @@ -21,8 +21,8 @@ use crate::{Decorate, Decorated, Formatted, Ident, RawString, SetSpan, Spanned}; use std::cell::RefCell; use winnow::ascii::{crlf, dec_uint, line_ending, newline, space0}; use winnow::combinator::{ - alt, cut_err, delimited, fail, not, opt, peek, preceded, repeat, separated0, separated1, - separated_pair, success, terminated, + alt, cut_err, delimited, empty, fail, not, opt, peek, preceded, repeat, separated, + separated_pair, terminated, }; use winnow::token::{any, none_of, one_of, take}; @@ -56,7 +56,7 @@ fn expr_inner<'i, 's>( // `//` and `/*` are comment starts. Do not mistakenly parse a `/` as binary // division operator. Ok(b"//" | b"/*" | b"..") => { - input.reset(checkpoint); + input.reset(&checkpoint); return Ok(()); } // Traversal operator. @@ -86,7 +86,7 @@ fn expr_inner<'i, 's>( } // None of the above matched or we hit the end of input. _ => { - input.reset(checkpoint); + input.reset(&checkpoint); return Ok(()); } } @@ -236,8 +236,8 @@ fn unary_op<'i, 's>( fn unary_operator(input: &mut Input) -> PResult { dispatch! {any; - b'-' => success(UnaryOperator::Neg), - b'!' => success(UnaryOperator::Not), + b'-' => empty.value(UnaryOperator::Neg), + b'!' => empty.value(UnaryOperator::Not), _ => fail, } .parse_next(input) @@ -262,17 +262,17 @@ fn binary_operator(input: &mut Input) -> PResult { b'!' => b'='.value(BinaryOperator::NotEq), b'<' => alt(( b'='.value(BinaryOperator::LessEq), - success(BinaryOperator::Less), + empty.value(BinaryOperator::Less), )), b'>' => alt(( b'='.value(BinaryOperator::GreaterEq), - success(BinaryOperator::Greater), + empty.value(BinaryOperator::Greater), )), - b'+' => success(BinaryOperator::Plus), - b'-' => success(BinaryOperator::Minus), - b'*' => success(BinaryOperator::Mul), - b'/' => success(BinaryOperator::Div), - b'%' => success(BinaryOperator::Mod), + b'+' => empty.value(BinaryOperator::Plus), + b'-' => empty.value(BinaryOperator::Minus), + b'*' => empty.value(BinaryOperator::Mul), + b'/' => empty.value(BinaryOperator::Div), + b'%' => empty.value(BinaryOperator::Mod), b'&' => b'&'.value(BinaryOperator::And), b'|' => b'|'.value(BinaryOperator::Or), _ => fail, @@ -327,7 +327,7 @@ fn array_items<'i, 's>( state: &'s RefCell, ) -> impl Parser, (), ContextError> + 's { move |input: &mut Input<'i>| { - let values = separated0(decorated(ws, preceded(not(b']'), expr), ws), b','); + let values = separated(0.., decorated(ws, preceded(not(b']'), expr), ws), b','); (values, opt(b','), raw_string(ws)) .map(|(values, comma, trailing)| { @@ -489,8 +489,8 @@ fn object_value(input: &mut Input) -> PResult { fn object_value_assignment(input: &mut Input) -> PResult { dispatch! {any; - b'=' => success(ObjectValueAssignment::Equals), - b':' => success(ObjectValueAssignment::Colon), + b'=' => empty.value(ObjectValueAssignment::Equals), + b':' => empty.value(ObjectValueAssignment::Colon), _ => cut_err(fail) .context(StrContext::Label("object value assignment")) .context(StrContext::Expected(StrContextValue::CharLiteral('='))) @@ -644,13 +644,14 @@ fn func_args(input: &mut Input) -> PResult { Ellipsis, } - let args = separated1( + let args = separated( + 1.., decorated(ws, preceded(peek(none_of(b",.)")), expr), ws), b',', ); let trailer = dispatch! {any; - b',' => success(Trailer::Comma), + b',' => empty.value(Trailer::Comma), b'.' => cut_tag("..").value(Trailer::Ellipsis), _ => fail, }; diff --git a/crates/hcl-edit/src/parser/string.rs b/crates/hcl-edit/src/parser/string.rs index 9632d1be..e35829a6 100644 --- a/crates/hcl-edit/src/parser/string.rs +++ b/crates/hcl-edit/src/parser/string.rs @@ -5,7 +5,7 @@ use super::trivia::void; use crate::{Decorated, Ident, RawString}; use std::borrow::Cow; -use winnow::combinator::{alt, cut_err, delimited, fail, not, opt, preceded, repeat, success}; +use winnow::combinator::{alt, cut_err, delimited, empty, fail, not, opt, preceded, repeat}; use winnow::stream::AsChar; use winnow::token::{any, one_of, take, take_while}; @@ -102,7 +102,7 @@ where /// interpolation/directive start markers. fn string_literal<'a>(input: &mut Input<'a>) -> PResult<&'a str> { let literal_end = dispatch! {any; - b'\"' | b'\\' => success(true), + b'\"' | b'\\' => empty.value(true), b'$' | b'%' => b'{'.value(true), _ => fail, }; @@ -124,8 +124,8 @@ where /// Parse an escaped start marker for a template interpolation or directive. fn escaped_marker(input: &mut Input) -> PResult { dispatch! {take::<_, Input, _>(3usize); - b"$${" => success(EscapedMarker::Interpolation), - b"%%{" => success(EscapedMarker::Directive), + b"$${" => empty.value(EscapedMarker::Interpolation), + b"%%{" => empty.value(EscapedMarker::Directive), _ => fail, } .parse_next(input) @@ -136,14 +136,14 @@ fn escaped_char(input: &mut Input) -> PResult { b'\\'.parse_next(input)?; dispatch! {any; - b'n' => success('\n'), - b'r' => success('\r'), - b't' => success('\t'), - b'\\' => success('\\'), - b'"' => success('"'), - b'/' => success('/'), - b'b' => success('\u{08}'), - b'f' => success('\u{0C}'), + b'n' => empty.value('\n'), + b'r' => empty.value('\r'), + b't' => empty.value('\t'), + b'\\' => empty.value('\\'), + b'"' => empty.value('"'), + b'/' => empty.value('/'), + b'b' => empty.value('\u{08}'), + b'f' => empty.value('\u{0C}'), b'u' => cut_err(hexescape::<4>) .context(StrContext::Label("unicode 4-digit hex code")), b'U' => cut_err(hexescape::<8>) diff --git a/crates/hcl-edit/src/parser/structure.rs b/crates/hcl-edit/src/parser/structure.rs index 3f149a89..b855d1fc 100644 --- a/crates/hcl-edit/src/parser/structure.rs +++ b/crates/hcl-edit/src/parser/structure.rs @@ -66,7 +66,7 @@ fn structure<'i, 's>( let mut structure = match peek(any).parse_next(input)? { b'=' => { if state.borrow_mut().is_redefined(ident) { - input.reset(checkpoint); + input.reset(&checkpoint); return cut_err(fail) .context(StrContext::Label("attribute")) .context(StrContext::Expected(StrContextValue::Description( diff --git a/crates/hcl-edit/src/parser/trivia.rs b/crates/hcl-edit/src/parser/trivia.rs index d9a77c0e..3a08b0e6 100644 --- a/crates/hcl-edit/src/parser/trivia.rs +++ b/crates/hcl-edit/src/parser/trivia.rs @@ -1,8 +1,8 @@ use super::prelude::*; -use winnow::ascii::{multispace0, not_line_ending, space0}; +use winnow::ascii::{multispace0, space0, till_line_ending}; use winnow::combinator::{alt, delimited, fail, peek, preceded, repeat}; -use winnow::token::{any, take_until0}; +use winnow::token::{any, take_until}; pub(super) fn ws(input: &mut Input) -> PResult<()> { ( @@ -41,15 +41,15 @@ pub(super) fn line_comment(input: &mut Input) -> PResult<()> { } fn hash_line_comment(input: &mut Input) -> PResult<()> { - preceded(b'#', not_line_ending).void().parse_next(input) + preceded(b'#', till_line_ending).void().parse_next(input) } fn double_slash_line_comment(input: &mut Input) -> PResult<()> { - preceded(b"//", not_line_ending).void().parse_next(input) + preceded(b"//", till_line_ending).void().parse_next(input) } fn inline_comment(input: &mut Input) -> PResult<()> { - delimited(b"/*", take_until0("*/"), b"*/") + delimited(b"/*", take_until(0.., "*/"), b"*/") .void() .parse_next(input) } diff --git a/crates/hcl-rs/Cargo.toml b/crates/hcl-rs/Cargo.toml index 04ef1258..da36271b 100644 --- a/crates/hcl-rs/Cargo.toml +++ b/crates/hcl-rs/Cargo.toml @@ -39,7 +39,7 @@ itoa = "1.0.9" hcl-edit = { version = "0.7.5", path = "../hcl-edit" } hcl-primitives = { version = "0.1.2", path = "../hcl-primitives", features = ["serde"] } serde = { version = "1.0.188", features = ["derive"] } -vecmap-rs = { version = "0.1.12", features = ["serde"] } +vecmap-rs = { version = "0.2", features = ["serde"] } [dev-dependencies] indoc = "2.0" diff --git a/crates/hcl-rs/src/eval/expr.rs b/crates/hcl-rs/src/eval/expr.rs index 61507bb2..ff18d5eb 100644 --- a/crates/hcl-rs/src/eval/expr.rs +++ b/crates/hcl-rs/src/eval/expr.rs @@ -138,6 +138,7 @@ pub(super) struct Collection<'a> { key_var: Option<&'a Identifier>, value_var: &'a Identifier, cond_expr: Option<&'a Expression>, + #[allow(clippy::struct_field_names)] collection: Vec<(Value, Value)>, } diff --git a/crates/hcl-rs/src/eval/impls.rs b/crates/hcl-rs/src/eval/impls.rs index 82c1e153..98fa16b1 100644 --- a/crates/hcl-rs/src/eval/impls.rs +++ b/crates/hcl-rs/src/eval/impls.rs @@ -230,7 +230,7 @@ impl Evaluate for TemplateExpr { // spec: // // https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#template-interpolation-unwrapping - match elements.get(0) { + match elements.first() { Some(Element::Interpolation(interp)) if elements.len() == 1 => { interp.expr.evaluate(ctx) } diff --git a/crates/hcl-rs/src/expr/de.rs b/crates/hcl-rs/src/expr/de.rs index 124877c1..abb71dd1 100644 --- a/crates/hcl-rs/src/expr/de.rs +++ b/crates/hcl-rs/src/expr/de.rs @@ -779,6 +779,7 @@ impl<'de> de::MapAccess<'de> for FuncCallAccess { } } +#[allow(clippy::struct_field_names)] pub struct ConditionalAccess { cond_expr: Option, true_expr: Option, diff --git a/crates/hcl-rs/src/ser/mod.rs b/crates/hcl-rs/src/ser/mod.rs index 6c3a1746..58fc9bd3 100644 --- a/crates/hcl-rs/src/ser/mod.rs +++ b/crates/hcl-rs/src/ser/mod.rs @@ -280,7 +280,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; pub use crate::expr::to_expression; thread_local! { - static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false); + static INTERNAL_SERIALIZATION: AtomicBool = const { AtomicBool::new(false) }; } pub(crate) fn in_internal_serialization() -> bool {