@@ -29,7 +29,6 @@ use crate::RuleType;
29
29
30
30
/// Parse-related error type.
31
31
#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
32
- #[ cfg_attr( feature = "std" , derive( thiserror:: Error ) ) ]
33
32
pub struct Error < R > {
34
33
/// Variant of the error
35
34
pub variant : ErrorVariant < R > ,
@@ -43,9 +42,11 @@ pub struct Error<R> {
43
42
parse_attempts : Option < ParseAttempts < R > > ,
44
43
}
45
44
45
+ #[ cfg( feature = "std" ) ]
46
+ impl < R : RuleType > core:: error:: Error for Error < R > { }
47
+
46
48
/// Different kinds of parsing errors.
47
49
#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
48
- #[ cfg_attr( feature = "std" , derive( thiserror:: Error ) ) ]
49
50
pub enum ErrorVariant < R > {
50
51
/// Generated parsing error with expected and unexpected `Rule`s
51
52
ParsingError {
@@ -61,6 +62,9 @@ pub enum ErrorVariant<R> {
61
62
} ,
62
63
}
63
64
65
+ #[ cfg( feature = "std" ) ]
66
+ impl < R : RuleType > std:: error:: Error for ErrorVariant < R > { }
67
+
64
68
/// Where an `Error` has occurred.
65
69
#[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
66
70
pub enum InputLocation {
@@ -737,6 +741,7 @@ fn visualize_whitespace(input: &str) -> String {
737
741
#[ cfg( feature = "miette-error" ) ]
738
742
mod miette_adapter {
739
743
use alloc:: string:: ToString ;
744
+ use core:: fmt;
740
745
use std:: boxed:: Box ;
741
746
742
747
use crate :: error:: LineColLocation ;
@@ -745,8 +750,7 @@ mod miette_adapter {
745
750
746
751
use miette:: { Diagnostic , LabeledSpan , SourceCode } ;
747
752
748
- #[ derive( thiserror:: Error , Debug ) ]
749
- #[ error( "Failure to parse at {:?}" , self . 0 . line_col) ]
753
+ #[ derive( Debug ) ]
750
754
pub ( crate ) struct MietteAdapter < R : RuleType > ( pub ( crate ) Error < R > ) ;
751
755
752
756
impl < R : RuleType > Diagnostic for MietteAdapter < R > {
@@ -769,10 +773,23 @@ mod miette_adapter {
769
773
Some ( Box :: new ( std:: iter:: once ( span) ) )
770
774
}
771
775
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 > > {
773
777
Some ( Box :: new ( self . 0 . message ( ) ) )
774
778
}
775
779
}
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
+ }
776
793
}
777
794
778
795
#[ cfg( test) ]
0 commit comments