Skip to content

Commit

Permalink
Merge pull request #705 from epage/error
Browse files Browse the repository at this point in the history
feat(error): Add inherent ParserError::append
  • Loading branch information
epage authored Jan 22, 2025
2 parents 22862c5 + 9bc062d commit 499722c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 56 deletions.
4 changes: 0 additions & 4 deletions examples/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ impl<I: Stream + Clone> ParserError<I> for CustomError<I> {
fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
CustomError::Winnow(input.clone(), kind)
}

fn append(self, _: &I, _: &<I as Stream>::Checkpoint, _: ErrorKind) -> Self {
self
}
}

impl<C, I: Stream> AddContext<I, C> for CustomError<I> {
Expand Down
7 changes: 0 additions & 7 deletions src/combinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ impl<I: Stream> ParserError<I> for CustomError {
fn from_error_kind(_: &I, _: ErrorKind) -> Self {
CustomError
}

fn append(self, _: &I, _: &<I as Stream>::Checkpoint, _: ErrorKind) -> Self {
CustomError
}
}

struct CustomError;
Expand Down Expand Up @@ -3464,9 +3460,6 @@ impl<I: Stream> ParserError<I> for NilError {
fn from_error_kind(_: &I, _: ErrorKind) -> NilError {
NilError
}
fn append(self, _: &I, _: &<I as Stream>::Checkpoint, _: ErrorKind) -> NilError {
NilError
}
}

#[test]
Expand Down
54 changes: 9 additions & 45 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ pub trait ParserError<I: Stream>: Sized {
///
/// This is useful when backtracking through a parse tree, accumulating error context on the
/// way.
fn append(self, input: &I, token_start: &<I as Stream>::Checkpoint, kind: ErrorKind) -> Self;
#[inline]
fn append(
self,
_input: &I,
_token_start: &<I as Stream>::Checkpoint,
_kind: ErrorKind,
) -> Self {
self
}

/// Combines errors from two different parse branches.
///
Expand Down Expand Up @@ -407,16 +415,6 @@ impl<I: Stream + Clone> ParserError<I> for InputError<I> {
kind,
}
}

#[inline]
fn append(
self,
_input: &I,
_token_start: &<I as Stream>::Checkpoint,
_kind: ErrorKind,
) -> Self {
self
}
}

impl<I: Stream + Clone, C> AddContext<I, C> for InputError<I> {}
Expand Down Expand Up @@ -487,15 +485,6 @@ impl<I: Clone + fmt::Debug + fmt::Display + Sync + Send + 'static> std::error::E
impl<I: Stream> ParserError<I> for () {
#[inline]
fn from_error_kind(_: &I, _: ErrorKind) -> Self {}

#[inline]
fn append(
self,
_input: &I,
_token_start: &<I as Stream>::Checkpoint,
_kind: ErrorKind,
) -> Self {
}
}

impl<I: Stream, C> AddContext<I, C> for () {}
Expand Down Expand Up @@ -582,21 +571,6 @@ impl<I: Stream, C> ParserError<I> for ContextError<C> {
fn from_error_kind(_input: &I, _kind: ErrorKind) -> Self {
Self::new()
}

#[inline]
fn append(
self,
_input: &I,
_token_start: &<I as Stream>::Checkpoint,
_kind: ErrorKind,
) -> Self {
self
}

#[inline]
fn or(self, other: Self) -> Self {
other
}
}

impl<C, I: Stream> AddContext<I, C> for ContextError<C> {
Expand Down Expand Up @@ -1134,16 +1108,6 @@ impl<I: Stream> ParserError<I> for ErrorKind {
fn from_error_kind(_input: &I, kind: ErrorKind) -> Self {
kind
}

#[inline]
fn append(
self,
_input: &I,
_token_start: &<I as Stream>::Checkpoint,
_kind: ErrorKind,
) -> Self {
self
}
}

impl<I: Stream, C> AddContext<I, C> for ErrorKind {}
Expand Down

0 comments on commit 499722c

Please sign in to comment.