@@ -639,7 +639,12 @@ impl Handler {
639639 ) -> String {
640640 let inner = self . inner . borrow ( ) ;
641641 let args = crate :: translation:: to_fluent_args ( args) ;
642- inner. emitter . translate_message ( & message, & args) . map_err ( Report :: new) . unwrap ( ) . to_string ( )
642+ inner
643+ . emitter
644+ . translate_message ( & message, & args)
645+ . map_err ( Report :: new)
646+ . unwrap ( )
647+ . to_string ( )
643648 }
644649
645650 // This is here to not allow mutation of flags;
@@ -685,12 +690,14 @@ impl Handler {
685690 }
686691
687692 pub fn has_stashed_diagnostic ( & self , span : Span , key : StashKey ) -> bool {
688- self . inner . borrow ( ) . stashed_diagnostics . get ( & ( span. with_parent ( None ) , key) ) . is_some ( )
693+ self . inner . with_borrow ( |inner| {
694+ inner. stashed_diagnostics . get ( & ( span. with_parent ( None ) , key) ) . is_some ( )
695+ } )
689696 }
690697
691698 /// Emit all stashed diagnostics.
692699 pub fn emit_stashed_diagnostics ( & self ) -> Option < ErrorGuaranteed > {
693- self . inner . borrow_mut ( ) . emit_stashed_diagnostics ( )
700+ self . inner . lock ( ) . emit_stashed_diagnostics ( )
694701 }
695702
696703 /// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`.
@@ -992,7 +999,7 @@ impl Handler {
992999 }
9931000
9941001 pub fn span_bug ( & self , span : impl Into < MultiSpan > , msg : impl Into < DiagnosticMessage > ) -> ! {
995- self . inner . borrow_mut ( ) . span_bug ( span, msg)
1002+ self . inner . lock ( ) . span_bug ( span, msg)
9961003 }
9971004
9981005 /// For documentation on this, see `Session::delay_span_bug`.
@@ -1002,13 +1009,13 @@ impl Handler {
10021009 span : impl Into < MultiSpan > ,
10031010 msg : impl Into < DiagnosticMessage > ,
10041011 ) -> ErrorGuaranteed {
1005- self . inner . borrow_mut ( ) . delay_span_bug ( span, msg)
1012+ self . inner . lock ( ) . delay_span_bug ( span, msg)
10061013 }
10071014
10081015 // FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
10091016 // where the explanation of what "good path" is (also, it should be renamed).
10101017 pub fn delay_good_path_bug ( & self , msg : impl Into < DiagnosticMessage > ) {
1011- self . inner . borrow_mut ( ) . delay_good_path_bug ( msg)
1018+ self . inner . lock ( ) . delay_good_path_bug ( msg)
10121019 }
10131020
10141021 #[ track_caller]
@@ -1041,12 +1048,12 @@ impl Handler {
10411048 // NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
10421049 #[ rustc_lint_diagnostics]
10431050 pub fn fatal ( & self , msg : impl Into < DiagnosticMessage > ) -> FatalError {
1044- self . inner . borrow_mut ( ) . fatal ( msg)
1051+ self . inner . lock ( ) . fatal ( msg)
10451052 }
10461053
10471054 #[ rustc_lint_diagnostics]
10481055 pub fn err ( & self , msg : impl Into < DiagnosticMessage > ) -> ErrorGuaranteed {
1049- self . inner . borrow_mut ( ) . err ( msg)
1056+ self . inner . lock ( ) . err ( msg)
10501057 }
10511058
10521059 #[ rustc_lint_diagnostics]
@@ -1061,47 +1068,52 @@ impl Handler {
10611068 }
10621069
10631070 pub fn bug ( & self , msg : impl Into < DiagnosticMessage > ) -> ! {
1064- self . inner . borrow_mut ( ) . bug ( msg)
1071+ self . inner . lock ( ) . bug ( msg)
10651072 }
10661073
10671074 #[ inline]
10681075 pub fn err_count ( & self ) -> usize {
1069- self . inner . borrow ( ) . err_count ( )
1076+ self . inner . with_borrow ( |inner| inner . err_count ( ) )
10701077 }
10711078
10721079 pub fn has_errors ( & self ) -> Option < ErrorGuaranteed > {
1073- self . inner . borrow ( ) . has_errors ( ) . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1080+ self . inner . with_borrow ( |inner| {
1081+ inner. has_errors ( ) . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1082+ } )
10741083 }
10751084
10761085 pub fn has_errors_or_lint_errors ( & self ) -> Option < ErrorGuaranteed > {
1077- self . inner
1078- . borrow ( )
1079- . has_errors_or_lint_errors ( )
1080- . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1086+ self . inner . with_borrow ( |inner| {
1087+ inner
1088+ . has_errors_or_lint_errors ( )
1089+ . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1090+ } )
10811091 }
10821092 pub fn has_errors_or_delayed_span_bugs ( & self ) -> Option < ErrorGuaranteed > {
1083- self . inner
1084- . borrow ( )
1085- . has_errors_or_delayed_span_bugs ( )
1086- . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1093+ self . inner . with_borrow ( |inner| {
1094+ inner
1095+ . has_errors_or_delayed_span_bugs ( )
1096+ . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1097+ } )
10871098 }
10881099 pub fn is_compilation_going_to_fail ( & self ) -> Option < ErrorGuaranteed > {
1089- self . inner
1090- . borrow ( )
1091- . is_compilation_going_to_fail ( )
1092- . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1100+ self . inner . with_borrow ( |inner| {
1101+ inner
1102+ . is_compilation_going_to_fail ( )
1103+ . then ( ErrorGuaranteed :: unchecked_claim_error_was_emitted)
1104+ } )
10931105 }
10941106
10951107 pub fn print_error_count ( & self , registry : & Registry ) {
1096- self . inner . borrow_mut ( ) . print_error_count ( registry)
1108+ self . inner . lock ( ) . print_error_count ( registry)
10971109 }
10981110
10991111 pub fn take_future_breakage_diagnostics ( & self ) -> Vec < Diagnostic > {
1100- std:: mem:: take ( & mut self . inner . borrow_mut ( ) . future_breakage_diagnostics )
1112+ std:: mem:: take ( & mut self . inner . lock ( ) . future_breakage_diagnostics )
11011113 }
11021114
11031115 pub fn abort_if_errors ( & self ) {
1104- self . inner . borrow_mut ( ) . abort_if_errors ( )
1116+ self . inner . lock ( ) . abort_if_errors ( )
11051117 }
11061118
11071119 /// `true` if we haven't taught a diagnostic with this code already.
@@ -1110,15 +1122,15 @@ impl Handler {
11101122 /// Used to suppress emitting the same error multiple times with extended explanation when
11111123 /// calling `-Zteach`.
11121124 pub fn must_teach ( & self , code : & DiagnosticId ) -> bool {
1113- self . inner . borrow_mut ( ) . must_teach ( code)
1125+ self . inner . lock ( ) . must_teach ( code)
11141126 }
11151127
11161128 pub fn force_print_diagnostic ( & self , db : Diagnostic ) {
1117- self . inner . borrow_mut ( ) . force_print_diagnostic ( db)
1129+ self . inner . lock ( ) . force_print_diagnostic ( db)
11181130 }
11191131
11201132 pub fn emit_diagnostic ( & self , diagnostic : & mut Diagnostic ) -> Option < ErrorGuaranteed > {
1121- self . inner . borrow_mut ( ) . emit_diagnostic ( diagnostic)
1133+ self . inner . lock ( ) . emit_diagnostic ( diagnostic)
11221134 }
11231135
11241136 pub fn emit_err < ' a > ( & ' a self , err : impl IntoDiagnostic < ' a > ) -> ErrorGuaranteed {
@@ -1198,16 +1210,15 @@ impl Handler {
11981210 mut diag : Diagnostic ,
11991211 sp : impl Into < MultiSpan > ,
12001212 ) -> Option < ErrorGuaranteed > {
1201- let mut inner = self . inner . borrow_mut ( ) ;
1202- inner. emit_diagnostic ( diag. set_span ( sp) )
1213+ self . inner . lock ( ) . emit_diagnostic ( diag. set_span ( sp) )
12031214 }
12041215
12051216 pub fn emit_artifact_notification ( & self , path : & Path , artifact_type : & str ) {
1206- self . inner . borrow_mut ( ) . emit_artifact_notification ( path, artifact_type)
1217+ self . inner . lock ( ) . emit_artifact_notification ( path, artifact_type)
12071218 }
12081219
12091220 pub fn emit_future_breakage_report ( & self , diags : Vec < Diagnostic > ) {
1210- self . inner . borrow_mut ( ) . emitter . emit_future_breakage_report ( diags)
1221+ self . inner . lock ( ) . emitter . emit_future_breakage_report ( diags)
12111222 }
12121223
12131224 pub fn emit_unused_externs (
0 commit comments