@@ -165,40 +165,73 @@ pub enum ExpandErrorKind {
165165}
166166
167167impl ExpandError {
168- pub fn render_to_string ( & self , db : & dyn ExpandDatabase ) -> ( String , bool ) {
168+ pub fn render_to_string ( & self , db : & dyn ExpandDatabase ) -> RenderedExpandError {
169169 self . inner . 0 . render_to_string ( db)
170170 }
171171}
172172
173+ pub struct RenderedExpandError {
174+ pub message : String ,
175+ pub error : bool ,
176+ pub kind : & ' static str ,
177+ }
178+
179+ impl RenderedExpandError {
180+ const GENERAL_KIND : & str = "macro-error" ;
181+ }
182+
173183impl ExpandErrorKind {
174- pub fn render_to_string ( & self , db : & dyn ExpandDatabase ) -> ( String , bool ) {
184+ pub fn render_to_string ( & self , db : & dyn ExpandDatabase ) -> RenderedExpandError {
175185 match self {
176- ExpandErrorKind :: ProcMacroAttrExpansionDisabled => {
177- ( "procedural attribute macro expansion is disabled" . to_owned ( ) , false )
178- }
179- ExpandErrorKind :: MacroDisabled => {
180- ( "proc-macro is explicitly disabled" . to_owned ( ) , false )
181- }
186+ ExpandErrorKind :: ProcMacroAttrExpansionDisabled => RenderedExpandError {
187+ message : "procedural attribute macro expansion is disabled" . to_owned ( ) ,
188+ error : false ,
189+ kind : "proc-macros-disabled" ,
190+ } ,
191+ ExpandErrorKind :: MacroDisabled => RenderedExpandError {
192+ message : "proc-macro is explicitly disabled" . to_owned ( ) ,
193+ error : false ,
194+ kind : "proc-macro-disabled" ,
195+ } ,
182196 & ExpandErrorKind :: MissingProcMacroExpander ( def_crate) => {
183197 match db. proc_macros ( ) . get_error_for_crate ( def_crate) {
184- Some ( ( e, hard_err) ) => ( e. to_owned ( ) , hard_err) ,
185- None => (
186- format ! (
187- "internal error: proc-macro map is missing error entry for crate {def_crate:?}"
188- ) ,
189- true ,
190- ) ,
198+ Some ( ( e, hard_err) ) => RenderedExpandError {
199+ message : e. to_owned ( ) ,
200+ error : hard_err,
201+ kind : RenderedExpandError :: GENERAL_KIND ,
202+ } ,
203+ None => RenderedExpandError {
204+ message : format ! ( "internal error: proc-macro map is missing error entry for crate {def_crate:?}" ) ,
205+ error : true ,
206+ kind : RenderedExpandError :: GENERAL_KIND ,
207+ } ,
191208 }
192209 }
193- ExpandErrorKind :: MacroDefinition => {
194- ( "macro definition has parse errors" . to_owned ( ) , true )
195- }
196- ExpandErrorKind :: Mbe ( e) => ( e. to_string ( ) , true ) ,
197- ExpandErrorKind :: RecursionOverflow => {
198- ( "overflow expanding the original macro" . to_owned ( ) , true )
199- }
200- ExpandErrorKind :: Other ( e) => ( ( * * e) . to_owned ( ) , true ) ,
201- ExpandErrorKind :: ProcMacroPanic ( e) => ( format ! ( "proc-macro panicked: {e}" ) , true ) ,
210+ ExpandErrorKind :: MacroDefinition => RenderedExpandError {
211+ message : "macro definition has parse errors" . to_owned ( ) ,
212+ error : true ,
213+ kind : RenderedExpandError :: GENERAL_KIND ,
214+ } ,
215+ ExpandErrorKind :: Mbe ( e) => RenderedExpandError {
216+ message : e. to_string ( ) ,
217+ error : true ,
218+ kind : RenderedExpandError :: GENERAL_KIND ,
219+ } ,
220+ ExpandErrorKind :: RecursionOverflow => RenderedExpandError {
221+ message : "overflow expanding the original macro" . to_owned ( ) ,
222+ error : true ,
223+ kind : RenderedExpandError :: GENERAL_KIND ,
224+ } ,
225+ ExpandErrorKind :: Other ( e) => RenderedExpandError {
226+ message : ( * * e) . to_owned ( ) ,
227+ error : true ,
228+ kind : RenderedExpandError :: GENERAL_KIND ,
229+ } ,
230+ ExpandErrorKind :: ProcMacroPanic ( e) => RenderedExpandError {
231+ message : format ! ( "proc-macro panicked: {e}" ) ,
232+ error : true ,
233+ kind : RenderedExpandError :: GENERAL_KIND ,
234+ } ,
202235 }
203236 }
204237}
0 commit comments