@@ -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 ) ) ]
3332pub 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 ) ) ]
4950pub 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 ) ]
6670pub enum InputLocation {
@@ -737,6 +741,7 @@ fn visualize_whitespace(input: &str) -> String {
737741#[ cfg( feature = "miette-error" ) ]
738742mod 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