Skip to content

Commit

Permalink
box PestError
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidion committed Oct 5, 2023
1 parent 48f50da commit 0f19d90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pest-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum TestError<R> {
#[error("Error building model from test case parse tree")]
Model { source: ModelError },
#[error("Error parsing code with target parser")]
Target { source: PestError<R> },
Target { source: Box<PestError<R>> },
#[error("Expected and actual parse trees are different:\n{diff}")]
Diff { diff: ExpressionDiff },
}
Expand Down
8 changes: 4 additions & 4 deletions pest-test/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use pest::{error::Error as PestError, iterators::Pair, Parser, RuleType};
use std::marker::PhantomData;
use thiserror::Error;

// TODO: clippy complains about the `Pest` variant being large -
// maybe box `source`?
#[derive(Error, Debug)]
pub enum ParserError<R> {
#[error("Error parsing source text")]
Pest { source: PestError<R> },
Pest { source: Box<PestError<R>> },
#[error("Empty parse tree")]
Empty,
}
Expand All @@ -18,7 +16,9 @@ pub fn parse<R: RuleType, P: Parser<R>>(
_: PhantomData<P>,
) -> Result<Pair<'_, R>, ParserError<R>> {
P::parse(rule, text)
.map_err(|source| ParserError::Pest { source })
.map_err(|source| ParserError::Pest {
source: Box::new(source),
})
.and_then(|mut code_pairs| code_pairs.next().ok_or(ParserError::Empty))
}

Expand Down

0 comments on commit 0f19d90

Please sign in to comment.