Skip to content

Commit a2889a0

Browse files
deps: drop thiserror for a manual impl (#1120)
1 parent 3da954b commit a2889a0

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

pest/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ rust-version = "1.80"
1616
[features]
1717
default = ["std", "memchr"]
1818
# Implements `std::error::Error` for the `Error` type
19-
std = ["ucd-trie/std", "dep:thiserror"]
19+
std = ["ucd-trie/std"]
2020
# Enables the `to_json` function for `Pair` and `Pairs`
2121
pretty-print = ["dep:serde", "dep:serde_json"]
2222
# Enable const fn constructor for `PrecClimber`
2323
const_prec_climber = []
2424
# Enable miette error
25-
miette-error = ["std", "pretty-print", "dep:miette", "dep:thiserror"]
25+
miette-error = ["std", "pretty-print", "dep:miette"]
2626

2727
[dependencies]
2828
ucd-trie = { version = "0.1.5", default-features = false }
2929
serde = { version = "1.0.145", optional = true }
3030
serde_json = { version = "1.0.85", optional = true }
31-
thiserror = { version = "2", optional = true }
3231
memchr = { version = "2", optional = true }
3332
miette = { version = "7.2.0", optional = true, features = ["fancy"] }
3433

pest/src/error.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::RuleType;
2929

3030
/// Parse-related error type.
3131
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
32-
#[cfg_attr(feature = "std", derive(thiserror::Error))]
3332
pub struct Error<R> {
3433
/// Variant of the error
3534
pub variant: ErrorVariant<R>,
@@ -43,9 +42,11 @@ pub struct Error<R> {
4342
parse_attempts: Option<ParseAttempts<R>>,
4443
}
4544

45+
#[cfg(feature = "std")]
46+
impl<R: RuleType> core::error::Error for Error<R> {}
47+
4648
/// Different kinds of parsing errors.
4749
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
48-
#[cfg_attr(feature = "std", derive(thiserror::Error))]
4950
pub enum ErrorVariant<R> {
5051
/// Generated parsing error with expected and unexpected `Rule`s
5152
ParsingError {
@@ -61,6 +62,9 @@ pub enum ErrorVariant<R> {
6162
},
6263
}
6364

65+
#[cfg(feature = "std")]
66+
impl<R: RuleType> std::error::Error for ErrorVariant<R> {}
67+
6468
/// Where an `Error` has occurred.
6569
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
6670
pub enum InputLocation {
@@ -737,6 +741,7 @@ fn visualize_whitespace(input: &str) -> String {
737741
#[cfg(feature = "miette-error")]
738742
mod miette_adapter {
739743
use alloc::string::ToString;
744+
use core::fmt;
740745
use std::boxed::Box;
741746

742747
use crate::error::LineColLocation;
@@ -745,8 +750,7 @@ mod miette_adapter {
745750

746751
use miette::{Diagnostic, LabeledSpan, SourceCode};
747752

748-
#[derive(thiserror::Error, Debug)]
749-
#[error("Failure to parse at {:?}", self.0.line_col)]
753+
#[derive(Debug)]
750754
pub(crate) struct MietteAdapter<R: RuleType>(pub(crate) Error<R>);
751755

752756
impl<R: RuleType> Diagnostic for MietteAdapter<R> {
@@ -769,10 +773,23 @@ mod miette_adapter {
769773
Some(Box::new(std::iter::once(span)))
770774
}
771775

772-
fn help<'a>(&'a self) -> Option<Box<dyn core::fmt::Display + 'a>> {
776+
fn help<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
773777
Some(Box::new(self.0.message()))
774778
}
775779
}
780+
781+
impl<R: RuleType> fmt::Display for MietteAdapter<R> {
782+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
783+
write!(f, "Failure to parse at {:?}", self.0.line_col)
784+
}
785+
}
786+
787+
impl<R> std::error::Error for MietteAdapter<R>
788+
where
789+
R: RuleType,
790+
Self: fmt::Debug + fmt::Display,
791+
{
792+
}
776793
}
777794

778795
#[cfg(test)]

0 commit comments

Comments
 (0)