@@ -50,7 +50,10 @@ lazy_static! {
5050}
5151
5252struct CTConflictsError < StorageT : Eq + Hash > {
53+ conflicts_diagnostic : String ,
54+ #[ cfg( test) ]
5355 stable : StateTable < StorageT > ,
56+ phantom : PhantomData < StorageT > ,
5457}
5558
5659/// The quote impl of `ToTokens` for `Option` prints an empty string for `None`
@@ -108,13 +111,7 @@ where
108111 usize : AsPrimitive < StorageT > ,
109112{
110113 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
111- let conflicts = self . stable . conflicts ( ) . unwrap ( ) ;
112- write ! (
113- f,
114- "CTConflictsError{{{} Reduce/Reduce, {} Shift/Reduce}}" ,
115- conflicts. rr_len( ) ,
116- conflicts. sr_len( )
117- )
114+ write ! ( f, "{}" , self . conflicts_diagnostic)
118115 }
119116}
120117
@@ -124,13 +121,7 @@ where
124121 usize : AsPrimitive < StorageT > ,
125122{
126123 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
127- let conflicts = self . stable . conflicts ( ) . unwrap ( ) ;
128- write ! (
129- f,
130- "CTConflictsError{{{} Reduce/Reduce, {} Shift/Reduce}}" ,
131- conflicts. rr_len( ) ,
132- conflicts. sr_len( )
133- )
124+ write ! ( f, "{}" , self . conflicts_diagnostic)
134125 }
135126}
136127
@@ -733,9 +724,21 @@ where
733724 ( Some ( i) , None ) if i == c. sr_len ( ) && 0 == c. rr_len ( ) => ( ) ,
734725 ( None , Some ( j) ) if 0 == c. sr_len ( ) && j == c. rr_len ( ) => ( ) ,
735726 ( None , None ) if 0 == c. rr_len ( ) && 0 == c. sr_len ( ) => ( ) ,
736- // TODO change SpannedDiagnosticsFormatter::handle_conflicts to return
737- // a string instead of using eprintln directly, then use that here.
738- _ => return Err ( Box :: new ( CTConflictsError { stable } ) ) ,
727+ _ => {
728+ let conflicts_diagnostic = yacc_diag. format_conflicts :: < LexerTypesT > (
729+ & grm,
730+ ast_validation. ast ( ) ,
731+ c,
732+ & sgraph,
733+ & stable,
734+ ) ;
735+ return Err ( Box :: new ( CTConflictsError {
736+ conflicts_diagnostic,
737+ phantom : PhantomData ,
738+ #[ cfg( test) ]
739+ stable,
740+ } ) ) ;
741+ }
739742 }
740743 }
741744 }
0 commit comments