@@ -210,14 +210,22 @@ impl FormatReport {
210210 if !new_errors. is_empty ( ) {
211211 errs. has_formatting_errors = true ;
212212 }
213- if errs. has_operational_errors && errs. has_check_errors {
213+ if errs. has_operational_errors && errs. has_check_errors && errs. has_unformatted_code_errors
214+ {
214215 return ;
215216 }
216217 for err in new_errors {
217218 match err. kind {
218- ErrorKind :: LineOverflow ( ..) | ErrorKind :: TrailingWhitespace => {
219+ ErrorKind :: LineOverflow ( ..) => {
219220 errs. has_operational_errors = true ;
220221 }
222+ ErrorKind :: TrailingWhitespace => {
223+ errs. has_operational_errors = true ;
224+ errs. has_unformatted_code_errors = true ;
225+ }
226+ ErrorKind :: LostComment => {
227+ errs. has_unformatted_code_errors = true ;
228+ }
221229 ErrorKind :: BadIssue ( _)
222230 | ErrorKind :: LicenseCheck
223231 | ErrorKind :: DeprecatedAttr
@@ -294,6 +302,9 @@ fn format_snippet(snippet: &str, config: &Config, is_macro_def: bool) -> Option<
294302 config. set ( ) . emit_mode ( config:: EmitMode :: Stdout ) ;
295303 config. set ( ) . verbose ( Verbosity :: Quiet ) ;
296304 config. set ( ) . hide_parse_errors ( true ) ;
305+ if is_macro_def {
306+ config. set ( ) . error_on_unformatted ( true ) ;
307+ }
297308
298309 let ( formatting_error, result) = {
299310 let input = Input :: Text ( snippet. into ( ) ) ;
@@ -302,7 +313,8 @@ fn format_snippet(snippet: &str, config: &Config, is_macro_def: bool) -> Option<
302313 (
303314 session. errors . has_macro_format_failure
304315 || session. out . as_ref ( ) . unwrap ( ) . is_empty ( ) && !snippet. is_empty ( )
305- || result. is_err ( ) ,
316+ || result. is_err ( )
317+ || ( is_macro_def && session. has_unformatted_code_errors ( ) ) ,
306318 result,
307319 )
308320 } ;
@@ -477,13 +489,18 @@ impl<'b, T: Write + 'b> Session<'b, T> {
477489 self . errors . has_diff
478490 }
479491
492+ pub fn has_unformatted_code_errors ( & self ) -> bool {
493+ self . errors . has_unformatted_code_errors
494+ }
495+
480496 pub fn has_no_errors ( & self ) -> bool {
481497 !( self . has_operational_errors ( )
482498 || self . has_parsing_errors ( )
483499 || self . has_formatting_errors ( )
484500 || self . has_check_errors ( )
485- || self . has_diff ( ) )
486- || self . errors . has_macro_format_failure
501+ || self . has_diff ( )
502+ || self . has_unformatted_code_errors ( )
503+ || self . errors . has_macro_format_failure )
487504 }
488505}
489506
0 commit comments