@@ -25,6 +25,8 @@ use std::collections::{HashMap, HashSet};
25
25
use std:: cmp:: min;
26
26
use unicode_width;
27
27
28
+ const ANONYMIZED_LINE_NUM : & str = "LL" ;
29
+
28
30
/// Emitter trait for emitting errors.
29
31
pub trait Emitter {
30
32
/// Emit a structured diagnostic.
@@ -108,6 +110,7 @@ pub struct EmitterWriter {
108
110
short_message : bool ,
109
111
teach : bool ,
110
112
error_codes : HashSet < String > ,
113
+ ui_testing : bool ,
111
114
}
112
115
113
116
struct FileWithAnnotatedLines {
@@ -157,6 +160,7 @@ impl EmitterWriter {
157
160
short_message,
158
161
teach,
159
162
error_codes : HashSet :: new ( ) ,
163
+ ui_testing : false ,
160
164
}
161
165
} else {
162
166
EmitterWriter {
@@ -165,6 +169,7 @@ impl EmitterWriter {
165
169
short_message,
166
170
teach,
167
171
error_codes : HashSet :: new ( ) ,
172
+ ui_testing : false ,
168
173
}
169
174
}
170
175
}
@@ -180,9 +185,14 @@ impl EmitterWriter {
180
185
short_message,
181
186
teach,
182
187
error_codes : HashSet :: new ( ) ,
188
+ ui_testing : false ,
183
189
}
184
190
}
185
191
192
+ pub fn ui_testing ( self , ui_testing : bool ) -> Self {
193
+ Self { ui_testing, ..self }
194
+ }
195
+
186
196
fn preprocess_annotations ( & mut self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
187
197
fn add_annotation_to_file ( file_vec : & mut Vec < FileWithAnnotatedLines > ,
188
198
file : Rc < FileMap > ,
@@ -334,9 +344,14 @@ impl EmitterWriter {
334
344
335
345
// First create the source line we will highlight.
336
346
buffer. puts ( line_offset, code_offset, & source_string, Style :: Quotation ) ;
347
+ let line_index = if self . ui_testing {
348
+ ANONYMIZED_LINE_NUM . to_string ( )
349
+ } else {
350
+ line. line_index . to_string ( )
351
+ } ;
337
352
buffer. puts ( line_offset,
338
353
0 ,
339
- & ( line . line_index . to_string ( ) ) ,
354
+ & line_index,
340
355
Style :: LineNumber ) ;
341
356
342
357
draw_col_separator ( buffer, line_offset, width_offset - 2 ) ;
@@ -1288,8 +1303,11 @@ impl EmitterWriter {
1288
1303
span : & MultiSpan ,
1289
1304
children : & Vec < SubDiagnostic > ,
1290
1305
suggestions : & [ CodeSuggestion ] ) {
1291
- let max_line_num = self . get_max_line_num ( span, children) ;
1292
- let max_line_num_len = max_line_num. to_string ( ) . len ( ) ;
1306
+ let max_line_num_len = if self . ui_testing {
1307
+ ANONYMIZED_LINE_NUM . len ( )
1308
+ } else {
1309
+ self . get_max_line_num ( span, children) . to_string ( ) . len ( )
1310
+ } ;
1293
1311
1294
1312
match self . emit_message_default ( span,
1295
1313
message,
0 commit comments