From 06d603af21c48050523e7c87e926ed2607d82a05 Mon Sep 17 00:00:00 2001 From: Ulrich Hornung Date: Wed, 10 Jan 2024 23:00:40 +0100 Subject: [PATCH] remove direct dependency between ParserError and subst::error. --- src/uu/env/src/parse_error.rs | 2 +- src/uu/env/src/split_iterator.rs | 2 +- submodules/subst/src/error.rs | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/uu/env/src/parse_error.rs b/src/uu/env/src/parse_error.rs index 7c505655bf1..5a4ed2e4ba7 100644 --- a/src/uu/env/src/parse_error.rs +++ b/src/uu/env/src/parse_error.rs @@ -27,7 +27,7 @@ pub enum ParseError { }, ParsingOfVariableNameFailed { pos: usize, - sub_err: subst::Error, + sub_err: String, }, InternalError { pos: usize, diff --git a/src/uu/env/src/split_iterator.rs b/src/uu/env/src/split_iterator.rs index f52a6400f41..704d951b6a2 100644 --- a/src/uu/env/src/split_iterator.rs +++ b/src/uu/env/src/split_iterator.rs @@ -148,7 +148,7 @@ impl<'a> SplitIterator<'a> { Err(subst::Error::MissingVariableName(_)) => self.take_one(), // no variable name, take the $ char Err(e) => Err(ParseError::ParsingOfVariableNameFailed { pos: self.raw_parser.get_look_at_pos(), - sub_err: e, + sub_err: e.to_string(), }), } } diff --git a/submodules/subst/src/error.rs b/submodules/subst/src/error.rs index c49d6e1579a..6c568f2c003 100644 --- a/submodules/subst/src/error.rs +++ b/submodules/subst/src/error.rs @@ -1,7 +1,8 @@ //! Module containing error details. /// An error that can occur during variable substitution. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub enum Error { /// The input string contains an invalid escape sequence. InvalidEscapeSequence(InvalidEscapeSequence), @@ -138,7 +139,8 @@ impl std::fmt::Display for CharOrByte { } /// The input string contains an invalid escape sequence. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct InvalidEscapeSequence { /// The byte offset within the input where the error occurs. /// @@ -168,7 +170,8 @@ impl std::fmt::Display for InvalidEscapeSequence { } /// The input string contains a variable placeholder without a variable name (`"${}"`). -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct MissingVariableName { /// The byte offset within the input where the error occurs. /// @@ -189,7 +192,8 @@ impl std::fmt::Display for MissingVariableName { } /// The input string contains an unexpected character. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct UnexpectedCharacter { /// The byte offset within the input where the error occurs. /// @@ -221,7 +225,8 @@ impl std::fmt::Display for UnexpectedCharacter { } /// A struct to describe what was expected instead of the unexpected character. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct ExpectedCharacter { /// A human readable message to describe what is expected. pub(crate) message: &'static str, @@ -236,7 +241,8 @@ impl ExpectedCharacter { } /// The input string contains an unclosed variable placeholder. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct MissingClosingBrace { /// The byte offset within the input where the error occurs. /// @@ -254,7 +260,8 @@ impl std::fmt::Display for MissingClosingBrace { } /// The input string contains a placeholder for a variable that is not in the variable map. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] +#[cfg_attr(test, derive(Eq, PartialEq))] pub struct NoSuchVariable { /// The byte offset within the input where the error occurs. ///