@@ -3,27 +3,17 @@ use std::cell::Cell;
33#[ derive( Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd ) ]
44pub enum History {
55 Spotless ,
6- WarningIssued ,
7- ErrorIssued ,
6+ WarningIssued ( u32 ) ,
7+ ErrorIssued ( u32 ) ,
88 FatalError ,
99}
1010
1111thread_local ! {
1212 static HISTORY : Cell <History > = Cell :: new( History :: Spotless ) ;
13- static ERR_COUNT : Cell <u32 > = Cell :: new( 0 ) ;
1413}
1514
1615pub ( crate ) fn reset ( ) {
1716 HISTORY . with ( |cell| cell. set ( History :: Spotless ) ) ;
18- ERR_COUNT . with ( |cell| cell. set ( 0 ) ) ;
19- }
20-
21- fn get_err ( ) -> u32 {
22- ERR_COUNT . with ( |e| e. get ( ) )
23- }
24-
25- fn set_err ( f : impl FnOnce ( u32 ) -> u32 ) {
26- ERR_COUNT . with ( |e| e. set ( f ( e. get ( ) ) ) )
2717}
2818
2919pub ( crate ) fn get_history ( ) -> History {
@@ -35,28 +25,21 @@ pub(crate) fn set_history(hist: History) {
3525}
3626
3727pub ( crate ) fn mark_warning ( ) {
38- let history = get_history ( ) ;
39- if history == History :: WarningIssued {
40- set_err ( |e| e + 1 ) ;
41- } else if history == History :: Spotless {
42- set_history ( History :: WarningIssued ) ;
43- set_err ( |_| 1 ) ;
28+ match get_history ( ) {
29+ History :: WarningIssued ( cur) => set_history ( History :: WarningIssued ( cur + 1 ) ) ,
30+ History :: Spotless => set_history ( History :: WarningIssued ( 1 ) ) ,
31+ _ => ( ) ,
4432 }
4533}
4634
4735pub ( crate ) fn mark_error ( ) {
48- if get_history ( ) < History :: ErrorIssued {
49- set_history ( History :: ErrorIssued ) ;
50- set_err ( |_| 1 ) ;
51- } else {
52- set_err ( |e| e + 1 ) ;
36+ match get_history ( ) {
37+ History :: Spotless | History :: WarningIssued ( _) => set_history ( History :: ErrorIssued ( 1 ) ) ,
38+ History :: ErrorIssued ( cur) => set_history ( History :: ErrorIssued ( cur + 1 ) ) ,
39+ _ => ( ) ,
5340 }
5441}
5542
5643pub fn mark_fatal ( ) {
5744 set_history ( History :: FatalError ) ;
5845}
59-
60- pub fn err_count ( ) -> u32 {
61- get_err ( )
62- }
0 commit comments