@@ -603,7 +603,10 @@ impl<'test> TestCx<'test> {
603603 ) ;
604604 } else {
605605 for pattern in missing_patterns {
606- self . error ( & format ! ( "error pattern '{}' not found!" , pattern) ) ;
606+ println ! (
607+ "\n {prefix}: error pattern '{pattern}' not found!" ,
608+ prefix = self . error_prefix( )
609+ ) ;
607610 }
608611 self . fatal_proc_rec ( "multiple error patterns not found" , proc_res) ;
609612 }
@@ -762,11 +765,12 @@ impl<'test> TestCx<'test> {
762765 }
763766
764767 if !unexpected. is_empty ( ) || !not_found. is_empty ( ) {
765- self . error ( & format ! (
766- "{} unexpected diagnostics reported, {} expected diagnostics not reported" ,
767- unexpected. len( ) ,
768- not_found. len( )
769- ) ) ;
768+ println ! (
769+ "\n {prefix}: {unexpected} unexpected diagnostics reported, {not_found} expected diagnostics not reported" ,
770+ prefix = self . error_prefix( ) ,
771+ unexpected = unexpected. len( ) ,
772+ not_found = not_found. len( ) ,
773+ ) ;
770774
771775 // Emit locations in a format that is short (relative paths) but "clickable" in editors.
772776 // Also normalize path separators to `/`.
@@ -1993,16 +1997,19 @@ impl<'test> TestCx<'test> {
19931997 output_base_name ( self . config , self . testpaths , self . safe_revision ( ) )
19941998 }
19951999
1996- fn error ( & self , err : & str ) {
2000+ /// Prefix to print before error messages. Normally just `error`, but also
2001+ /// includes the revision name for tests that use revisions.
2002+ #[ must_use]
2003+ fn error_prefix ( & self ) -> String {
19972004 match self . revision {
1998- Some ( rev) => println ! ( "\n error in revision `{}`: {}" , rev , err ) ,
1999- None => println ! ( "\n error: {}" , err ) ,
2005+ Some ( rev) => format ! ( "error in revision `{rev}`" ) ,
2006+ None => format ! ( "error" ) ,
20002007 }
20012008 }
20022009
20032010 #[ track_caller]
20042011 fn fatal ( & self , err : & str ) -> ! {
2005- self . error ( err ) ;
2012+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
20062013 error ! ( "fatal error, panic: {:?}" , err) ;
20072014 panic ! ( "fatal error" ) ;
20082015 }
@@ -2020,7 +2027,7 @@ impl<'test> TestCx<'test> {
20202027 proc_res : & ProcRes ,
20212028 callback_before_unwind : impl FnOnce ( ) ,
20222029 ) -> ! {
2023- self . error ( err ) ;
2030+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
20242031
20252032 // Some callers want to print additional notes after the main error message.
20262033 if let Some ( note) = extra_note {
0 commit comments