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