16
16
// tidy-alphabetical-end
17
17
18
18
use std:: cell:: RefCell ;
19
- use std:: collections:: BTreeMap ;
20
19
use std:: marker:: PhantomData ;
21
20
use std:: ops:: Deref ;
22
21
22
+ use diagnostics:: BorrowckDiags ;
23
23
use rustc_abi:: FieldIdx ;
24
24
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
25
25
use rustc_data_structures:: graph:: dominators:: Dominators ;
26
- use rustc_errors:: Diag ;
27
26
use rustc_hir as hir;
28
27
use rustc_hir:: def_id:: LocalDefId ;
29
28
use rustc_index:: bit_set:: { BitSet , MixedBitSet } ;
@@ -41,7 +40,7 @@ use rustc_mir_dataflow::impls::{
41
40
EverInitializedPlaces , MaybeInitializedPlaces , MaybeUninitializedPlaces ,
42
41
} ;
43
42
use rustc_mir_dataflow:: move_paths:: {
44
- InitIndex , InitLocation , LookupResult , MoveData , MoveOutIndex , MovePathIndex ,
43
+ InitIndex , InitLocation , LookupResult , MoveData , MovePathIndex ,
45
44
} ;
46
45
use rustc_mir_dataflow:: { Analysis , EntryStates , Results , ResultsVisitor , visit_results} ;
47
46
use rustc_session:: lint:: builtin:: UNUSED_MUT ;
@@ -217,7 +216,7 @@ fn do_mir_borrowck<'tcx>(
217
216
218
217
// We also have a `#[rustc_regions]` annotation that causes us to dump
219
218
// information.
220
- let diags = & mut diags :: BorrowckDiags :: new ( ) ;
219
+ let diags = & mut BorrowckDiags :: new ( ) ;
221
220
nll:: dump_annotation ( & infcx, body, & regioncx, & opt_closure_req, & opaque_type_values, diags) ;
222
221
223
222
let movable_coroutine =
@@ -566,7 +565,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
566
565
/// Results of Polonius analysis.
567
566
polonius_output : Option < Box < PoloniusOutput > > ,
568
567
569
- diags : & ' a mut diags :: BorrowckDiags < ' infcx , ' tcx > ,
568
+ diags : & ' a mut BorrowckDiags < ' infcx , ' tcx > ,
570
569
move_errors : Vec < MoveError < ' tcx > > ,
571
570
}
572
571
@@ -2399,146 +2398,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
2399
2398
}
2400
2399
}
2401
2400
2402
- mod diags {
2403
- use rustc_errors:: ErrorGuaranteed ;
2404
-
2405
- use super :: * ;
2406
-
2407
- enum BufferedDiag < ' infcx > {
2408
- Error ( Diag < ' infcx > ) ,
2409
- NonError ( Diag < ' infcx , ( ) > ) ,
2410
- }
2411
-
2412
- impl < ' infcx > BufferedDiag < ' infcx > {
2413
- fn sort_span ( & self ) -> Span {
2414
- match self {
2415
- BufferedDiag :: Error ( diag) => diag. sort_span ,
2416
- BufferedDiag :: NonError ( diag) => diag. sort_span ,
2417
- }
2418
- }
2419
- }
2420
-
2421
- pub ( crate ) struct BorrowckDiags < ' infcx , ' tcx > {
2422
- /// This field keeps track of move errors that are to be reported for given move indices.
2423
- ///
2424
- /// There are situations where many errors can be reported for a single move out (see
2425
- /// #53807) and we want only the best of those errors.
2426
- ///
2427
- /// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the
2428
- /// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of
2429
- /// the `Place` of the previous most diagnostic. This happens instead of buffering the
2430
- /// error. Once all move errors have been reported, any diagnostics in this map are added
2431
- /// to the buffer to be emitted.
2432
- ///
2433
- /// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
2434
- /// when errors in the map are being re-added to the error buffer so that errors with the
2435
- /// same primary span come out in a consistent order.
2436
- buffered_move_errors : BTreeMap < Vec < MoveOutIndex > , ( PlaceRef < ' tcx > , Diag < ' infcx > ) > ,
2437
-
2438
- buffered_mut_errors : FxIndexMap < Span , ( Diag < ' infcx > , usize ) > ,
2439
-
2440
- /// Buffer of diagnostics to be reported. A mixture of error and non-error diagnostics.
2441
- buffered_diags : Vec < BufferedDiag < ' infcx > > ,
2442
- }
2443
-
2444
- impl < ' infcx , ' tcx > BorrowckDiags < ' infcx , ' tcx > {
2445
- pub ( crate ) fn new ( ) -> Self {
2446
- BorrowckDiags {
2447
- buffered_move_errors : BTreeMap :: new ( ) ,
2448
- buffered_mut_errors : Default :: default ( ) ,
2449
- buffered_diags : Default :: default ( ) ,
2450
- }
2451
- }
2452
-
2453
- pub ( crate ) fn buffer_error ( & mut self , diag : Diag < ' infcx > ) {
2454
- self . buffered_diags . push ( BufferedDiag :: Error ( diag) ) ;
2455
- }
2456
-
2457
- pub ( crate ) fn buffer_non_error ( & mut self , diag : Diag < ' infcx , ( ) > ) {
2458
- self . buffered_diags . push ( BufferedDiag :: NonError ( diag) ) ;
2459
- }
2460
- }
2461
-
2462
- impl < ' infcx , ' tcx > MirBorrowckCtxt < ' _ , ' infcx , ' tcx > {
2463
- pub ( crate ) fn buffer_error ( & mut self , diag : Diag < ' infcx > ) {
2464
- self . diags . buffer_error ( diag) ;
2465
- }
2466
-
2467
- pub ( crate ) fn buffer_non_error ( & mut self , diag : Diag < ' infcx , ( ) > ) {
2468
- self . diags . buffer_non_error ( diag) ;
2469
- }
2470
-
2471
- pub ( crate ) fn buffer_move_error (
2472
- & mut self ,
2473
- move_out_indices : Vec < MoveOutIndex > ,
2474
- place_and_err : ( PlaceRef < ' tcx > , Diag < ' infcx > ) ,
2475
- ) -> bool {
2476
- if let Some ( ( _, diag) ) =
2477
- self . diags . buffered_move_errors . insert ( move_out_indices, place_and_err)
2478
- {
2479
- // Cancel the old diagnostic so we don't ICE
2480
- diag. cancel ( ) ;
2481
- false
2482
- } else {
2483
- true
2484
- }
2485
- }
2486
-
2487
- pub ( crate ) fn get_buffered_mut_error (
2488
- & mut self ,
2489
- span : Span ,
2490
- ) -> Option < ( Diag < ' infcx > , usize ) > {
2491
- // FIXME(#120456) - is `swap_remove` correct?
2492
- self . diags . buffered_mut_errors . swap_remove ( & span)
2493
- }
2494
-
2495
- pub ( crate ) fn buffer_mut_error ( & mut self , span : Span , diag : Diag < ' infcx > , count : usize ) {
2496
- self . diags . buffered_mut_errors . insert ( span, ( diag, count) ) ;
2497
- }
2498
-
2499
- pub ( crate ) fn emit_errors ( & mut self ) -> Option < ErrorGuaranteed > {
2500
- let mut res = self . infcx . tainted_by_errors ( ) ;
2501
-
2502
- // Buffer any move errors that we collected and de-duplicated.
2503
- for ( _, ( _, diag) ) in std:: mem:: take ( & mut self . diags . buffered_move_errors ) {
2504
- // We have already set tainted for this error, so just buffer it.
2505
- self . diags . buffer_error ( diag) ;
2506
- }
2507
- for ( _, ( mut diag, count) ) in std:: mem:: take ( & mut self . diags . buffered_mut_errors ) {
2508
- if count > 10 {
2509
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
2510
- #[ allow( rustc:: untranslatable_diagnostic) ]
2511
- diag. note ( format ! ( "...and {} other attempted mutable borrows" , count - 10 ) ) ;
2512
- }
2513
- self . diags . buffer_error ( diag) ;
2514
- }
2515
-
2516
- if !self . diags . buffered_diags . is_empty ( ) {
2517
- self . diags . buffered_diags . sort_by_key ( |buffered_diag| buffered_diag. sort_span ( ) ) ;
2518
- for buffered_diag in self . diags . buffered_diags . drain ( ..) {
2519
- match buffered_diag {
2520
- BufferedDiag :: Error ( diag) => res = Some ( diag. emit ( ) ) ,
2521
- BufferedDiag :: NonError ( diag) => diag. emit ( ) ,
2522
- }
2523
- }
2524
- }
2525
-
2526
- res
2527
- }
2528
-
2529
- pub ( crate ) fn has_buffered_diags ( & self ) -> bool {
2530
- self . diags . buffered_diags . is_empty ( )
2531
- }
2532
-
2533
- pub ( crate ) fn has_move_error (
2534
- & self ,
2535
- move_out_indices : & [ MoveOutIndex ] ,
2536
- ) -> Option < & ( PlaceRef < ' tcx > , Diag < ' infcx > ) > {
2537
- self . diags . buffered_move_errors . get ( move_out_indices)
2538
- }
2539
- }
2540
- }
2541
-
2542
2401
/// The degree of overlap between 2 places for borrow-checking.
2543
2402
enum Overlap {
2544
2403
/// The places might partially overlap - in this case, we give
0 commit comments