1
- use crate :: { error:: CompileError , warning:: CompileWarning } ;
1
+ use crate :: {
2
+ error:: CompileError ,
3
+ warning:: { CompileInfo , CompileWarning } ,
4
+ } ;
2
5
use core:: cell:: RefCell ;
3
6
4
7
/// A handler with which you can emit diagnostics.
5
8
#[ derive( Default , Debug , Clone ) ]
6
9
pub struct Handler {
7
10
/// The inner handler.
8
11
/// This construction is used to avoid `&mut` all over the compiler.
9
- inner : RefCell < HandlerInner > ,
12
+ inner : RefCell < HandlerDiagnostics > ,
10
13
}
11
14
12
15
/// Contains the actual data for `Handler`.
13
16
/// Modelled this way to afford an API using interior mutability.
14
17
#[ derive( Default , Debug , Clone ) ]
15
- struct HandlerInner {
18
+ struct HandlerDiagnostics {
16
19
/// The sink through which errors will be emitted.
17
20
errors : Vec < CompileError > ,
18
21
/// The sink through which warnings will be emitted.
19
22
warnings : Vec < CompileWarning > ,
23
+ /// The sink through which infos will be emitted.
24
+ infos : Vec < CompileInfo > ,
20
25
}
21
26
22
27
impl Handler {
23
- pub fn from_parts ( errors : Vec < CompileError > , warnings : Vec < CompileWarning > ) -> Self {
28
+ pub fn from_parts (
29
+ errors : Vec < CompileError > ,
30
+ warnings : Vec < CompileWarning > ,
31
+ infos : Vec < CompileInfo > ,
32
+ ) -> Self {
24
33
Self {
25
- inner : RefCell :: new ( HandlerInner { errors, warnings } ) ,
34
+ inner : RefCell :: new ( HandlerDiagnostics {
35
+ errors,
36
+ warnings,
37
+ infos,
38
+ } ) ,
26
39
}
27
40
}
28
41
@@ -42,6 +55,11 @@ impl Handler {
42
55
self . inner . borrow_mut ( ) . warnings . push ( warn) ;
43
56
}
44
57
58
+ /// Emit the info `info`.
59
+ pub fn emit_info ( & self , info : CompileInfo ) {
60
+ self . inner . borrow_mut ( ) . infos . push ( info) ;
61
+ }
62
+
45
63
pub fn has_errors ( & self ) -> bool {
46
64
!self . inner . borrow ( ) . errors . is_empty ( )
47
65
}
@@ -67,22 +85,25 @@ impl Handler {
67
85
}
68
86
}
69
87
70
- /// Extract all the warnings and errors from this handler.
71
- pub fn consume ( self ) -> ( Vec < CompileError > , Vec < CompileWarning > ) {
88
+ /// Extract all the diagnostics from this handler.
89
+ pub fn consume ( self ) -> ( Vec < CompileError > , Vec < CompileWarning > , Vec < CompileInfo > ) {
72
90
let inner = self . inner . into_inner ( ) ;
73
- ( inner. errors , inner. warnings )
91
+ ( inner. errors , inner. warnings , inner . infos )
74
92
}
75
93
76
94
pub fn append ( & self , other : Handler ) -> Option < ErrorEmitted > {
77
95
let other_has_errors = other. has_errors ( ) ;
78
96
79
- let ( errors, warnings) = other. consume ( ) ;
97
+ let ( errors, warnings, infos ) = other. consume ( ) ;
80
98
for warn in warnings {
81
99
self . emit_warn ( warn) ;
82
100
}
83
101
for err in errors {
84
102
self . emit_err ( err) ;
85
103
}
104
+ for inf in infos {
105
+ self . emit_info ( inf) ;
106
+ }
86
107
87
108
if other_has_errors {
88
109
Some ( ErrorEmitted { _priv : ( ) } )
@@ -118,7 +139,7 @@ impl Handler {
118
139
) -> Result < ( ) , ErrorEmitted > {
119
140
let mut emitted = Ok ( ( ) ) ;
120
141
121
- let ( errs, _) = other. consume ( ) ;
142
+ let ( errs, _, _ ) = other. consume ( ) ;
122
143
for err in errs {
123
144
if let Some ( err) = ( f) ( err) {
124
145
emitted = Err ( self . emit_err ( err) ) ;
0 commit comments