@@ -78,6 +78,7 @@ use std::fmt;
78
78
use std:: hash:: Hash ;
79
79
use std:: io:: Write ;
80
80
use std:: num:: NonZeroUsize ;
81
+ use std:: ops:: DerefMut ;
81
82
use std:: panic;
82
83
use std:: path:: { Path , PathBuf } ;
83
84
@@ -666,22 +667,51 @@ impl DiagCtxt {
666
667
/// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
667
668
/// the overall count of emitted error diagnostics.
668
669
pub fn reset_err_count ( & self ) {
670
+ // Use destructuring so that if a field gets added to `DiagCtxtInner`, it's impossible to
671
+ // fail to update this method as well.
669
672
let mut inner = self . inner . borrow_mut ( ) ;
670
- inner. stashed_err_count = 0 ;
671
- inner. deduplicated_err_count = 0 ;
672
- inner. deduplicated_warn_count = 0 ;
673
- inner. must_produce_diag = false ;
674
- inner. has_printed = false ;
675
- inner. suppressed_expected_diag = false ;
676
-
677
- // actually free the underlying memory (which `clear` would not do)
678
- inner. err_guars = Default :: default ( ) ;
679
- inner. lint_err_guars = Default :: default ( ) ;
680
- inner. delayed_bugs = Default :: default ( ) ;
681
- inner. taught_diagnostics = Default :: default ( ) ;
682
- inner. emitted_diagnostic_codes = Default :: default ( ) ;
683
- inner. emitted_diagnostics = Default :: default ( ) ;
684
- inner. stashed_diagnostics = Default :: default ( ) ;
673
+ let DiagCtxtInner {
674
+ flags : _,
675
+ err_guars,
676
+ lint_err_guars,
677
+ delayed_bugs,
678
+ stashed_err_count,
679
+ deduplicated_err_count,
680
+ deduplicated_warn_count,
681
+ emitter : _,
682
+ must_produce_diag,
683
+ has_printed,
684
+ suppressed_expected_diag,
685
+ taught_diagnostics,
686
+ emitted_diagnostic_codes,
687
+ emitted_diagnostics,
688
+ stashed_diagnostics,
689
+ future_breakage_diagnostics,
690
+ check_unstable_expect_diagnostics,
691
+ unstable_expect_diagnostics,
692
+ fulfilled_expectations,
693
+ ice_file : _,
694
+ } = inner. deref_mut ( ) ;
695
+
696
+ // For the `Vec`s and `HashMap`s, we overwrite with an empty container to free the
697
+ // underlying memory (which `clear` would not do).
698
+ * err_guars = Default :: default ( ) ;
699
+ * lint_err_guars = Default :: default ( ) ;
700
+ * delayed_bugs = Default :: default ( ) ;
701
+ * stashed_err_count = 0 ;
702
+ * deduplicated_err_count = 0 ;
703
+ * deduplicated_warn_count = 0 ;
704
+ * must_produce_diag = false ;
705
+ * has_printed = false ;
706
+ * suppressed_expected_diag = false ;
707
+ * taught_diagnostics = Default :: default ( ) ;
708
+ * emitted_diagnostic_codes = Default :: default ( ) ;
709
+ * emitted_diagnostics = Default :: default ( ) ;
710
+ * stashed_diagnostics = Default :: default ( ) ;
711
+ * future_breakage_diagnostics = Default :: default ( ) ;
712
+ * check_unstable_expect_diagnostics = false ;
713
+ * unstable_expect_diagnostics = Default :: default ( ) ;
714
+ * fulfilled_expectations = Default :: default ( ) ;
685
715
}
686
716
687
717
/// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key.
0 commit comments