@@ -12,7 +12,7 @@ use rustc_span::ErrorGuaranteed;
1212use smallvec:: SmallVec ;
1313
1414use crate :: consumers:: BorrowckConsumer ;
15- use crate :: diagnostics:: BufferedDiag ;
15+ use crate :: diagnostics:: BorrowckDiagnosticsBuffer ;
1616use crate :: nll:: compute_closure_requirements_modulo_opaques;
1717use crate :: region_infer:: opaque_types:: {
1818 UnexpectedHiddenRegion , apply_definition_site_hidden_types, clone_and_resolve_opaque_types,
@@ -46,7 +46,6 @@ pub(super) struct BorrowCheckRootCtxt<'diag, 'tcx: 'diag> {
4646 /// This should be `None` during normal compilation. See [`crate::consumers`] for more
4747 /// information on how this is used.
4848 pub consumer : Option < BorrowckConsumer < ' tcx > > ,
49- errors : Vec < BufferedDiag < ' diag > > ,
5049}
5150
5251impl < ' diag , ' tcx > BorrowCheckRootCtxt < ' diag , ' tcx > {
@@ -65,7 +64,6 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
6564 propagated_borrowck_results : Default :: default ( ) ,
6665 tainted_by_errors,
6766 consumer,
68- errors : Default :: default ( ) ,
6967 }
7068 }
7169
@@ -89,10 +87,9 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
8987 }
9088
9189 pub ( super ) fn finalize (
92- mut self ,
90+ self ,
9391 ) -> Result < & ' tcx FxIndexMap < LocalDefId , ty:: DefinitionSiteHiddenType < ' tcx > > , ErrorGuaranteed >
9492 {
95- self . emit_errors ( ) ;
9693 if let Some ( guar) = self . tainted_by_errors . get ( ) {
9794 Err ( guar)
9895 } else {
@@ -168,7 +165,10 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
168165 /// which don't depend on opaque types. In this case they get removed from
169166 /// `collect_region_constraints_results` and the final result gets put into
170167 /// `propagated_borrowck_results`.
171- fn apply_closure_requirements_modulo_opaques ( & mut self ) {
168+ fn apply_closure_requirements_modulo_opaques (
169+ & mut self ,
170+ diags_buffer : & mut BorrowckDiagnosticsBuffer < ' diag , ' tcx > ,
171+ ) {
172172 let mut closure_requirements_modulo_opaques = FxHashMap :: default ( ) ;
173173 // We need to `mem::take` both `self.collect_region_constraints_results` and
174174 // `input.deferred_closure_requirements` as we otherwise can't iterate over
@@ -226,7 +226,7 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
226226 self . collect_region_constraints_results . insert ( def_id, input) ;
227227 } else {
228228 assert ! ( input. deferred_closure_requirements. is_empty( ) ) ;
229- let result = borrowck_check_region_constraints ( self , input) ;
229+ let result = borrowck_check_region_constraints ( self , diags_buffer , input) ;
230230 self . propagated_borrowck_results . insert ( def_id, result) ;
231231 }
232232 }
@@ -281,14 +281,16 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
281281 self . collect_region_constraints_results . insert ( def_id, result) ;
282282 }
283283
284+ let diags_buffer = & mut BorrowckDiagnosticsBuffer :: default ( ) ;
285+
284286 // We now apply the closure requirements of nested bodies modulo
285287 // opaques. In case a body does not depend on opaque types, we
286288 // eagerly check its region constraints and use the final closure
287289 // requirements.
288290 //
289291 // We eagerly finish borrowck for bodies which don't depend on
290292 // opaques.
291- self . apply_closure_requirements_modulo_opaques ( ) ;
293+ self . apply_closure_requirements_modulo_opaques ( diags_buffer ) ;
292294
293295 // We handle opaque type uses for all bodies together.
294296 self . handle_opaque_type_uses ( ) ;
@@ -314,32 +316,9 @@ impl<'diag, 'tcx> BorrowCheckRootCtxt<'diag, 'tcx> {
314316 ) ;
315317 }
316318
317- let result = borrowck_check_region_constraints ( self , input) ;
319+ let result = borrowck_check_region_constraints ( self , diags_buffer , input) ;
318320 self . propagated_borrowck_results . insert ( def_id, result) ;
319321 }
320- }
321-
322- pub ( crate ) fn buffer_error ( & mut self , buffered_diag : BufferedDiag < ' _ > ) {
323- match buffered_diag {
324- BufferedDiag :: Error ( diag) => {
325- let diag = diag. with_dcx ( self . dcx ( ) ) ;
326- self . errors . push ( BufferedDiag :: Error ( diag) ) ;
327- }
328- BufferedDiag :: NonError ( diag) => {
329- let diag = diag. with_dcx ( self . dcx ( ) ) ;
330- self . errors . push ( BufferedDiag :: NonError ( diag) ) ;
331- }
332- }
333- }
334-
335- pub ( crate ) fn emit_errors ( & mut self ) {
336- for buffered_diag in self . errors . drain ( ..) {
337- match buffered_diag {
338- BufferedDiag :: Error ( diag) => {
339- diag. emit ( ) ;
340- }
341- BufferedDiag :: NonError ( diag) => diag. emit ( ) ,
342- }
343- }
322+ diags_buffer. emit_errors ( ) ;
344323 }
345324}
0 commit comments