@@ -38,34 +38,41 @@ pub struct JsonEmitter {
38
38
registry : Option < Registry > ,
39
39
cm : Rc < CodeMapper + ' static > ,
40
40
pretty : bool ,
41
+ /// Whether "approximate suggestions" are enabled in the config
42
+ approximate_suggestions : bool ,
41
43
}
42
44
43
45
impl JsonEmitter {
44
46
pub fn stderr ( registry : Option < Registry > ,
45
47
code_map : Rc < CodeMap > ,
46
- pretty : bool ) -> JsonEmitter {
48
+ pretty : bool ,
49
+ approximate_suggestions : bool ) -> JsonEmitter {
47
50
JsonEmitter {
48
51
dst : Box :: new ( io:: stderr ( ) ) ,
49
52
registry,
50
53
cm : code_map,
51
54
pretty,
55
+ approximate_suggestions,
52
56
}
53
57
}
54
58
55
59
pub fn basic ( pretty : bool ) -> JsonEmitter {
56
60
let file_path_mapping = FilePathMapping :: empty ( ) ;
57
- JsonEmitter :: stderr ( None , Rc :: new ( CodeMap :: new ( file_path_mapping) ) , pretty)
61
+ JsonEmitter :: stderr ( None , Rc :: new ( CodeMap :: new ( file_path_mapping) ) ,
62
+ pretty, false )
58
63
}
59
64
60
65
pub fn new ( dst : Box < Write + Send > ,
61
66
registry : Option < Registry > ,
62
67
code_map : Rc < CodeMap > ,
63
- pretty : bool ) -> JsonEmitter {
68
+ pretty : bool ,
69
+ approximate_suggestions : bool ) -> JsonEmitter {
64
70
JsonEmitter {
65
71
dst,
66
72
registry,
67
73
cm : code_map,
68
74
pretty,
75
+ approximate_suggestions,
69
76
}
70
77
}
71
78
}
@@ -283,6 +290,13 @@ impl DiagnosticSpan {
283
290
def_site_span,
284
291
} )
285
292
} ) ;
293
+
294
+ let suggestion_approximate = if je. approximate_suggestions {
295
+ suggestion. map ( |x| x. 1 )
296
+ } else {
297
+ None
298
+ } ;
299
+
286
300
DiagnosticSpan {
287
301
file_name : start. file . name . to_string ( ) ,
288
302
byte_start : span. lo ( ) . 0 - start. file . start_pos . 0 ,
@@ -294,7 +308,7 @@ impl DiagnosticSpan {
294
308
is_primary,
295
309
text : DiagnosticSpanLine :: from_span ( span, je) ,
296
310
suggested_replacement : suggestion. map ( |x| x. 0 . clone ( ) ) ,
297
- suggestion_approximate : suggestion . map ( |x| x . 1 ) ,
311
+ suggestion_approximate,
298
312
expansion : backtrace_step,
299
313
label,
300
314
}
0 commit comments