@@ -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
}
@@ -101,6 +108,7 @@ struct Diagnostic {
101
108
}
102
109
103
110
#[ derive( RustcEncodable ) ]
111
+ #[ allow( unused_attributes) ]
104
112
struct DiagnosticSpan {
105
113
file_name : String ,
106
114
byte_start : u32 ,
@@ -121,6 +129,9 @@ struct DiagnosticSpan {
121
129
/// If we are suggesting a replacement, this will contain text
122
130
/// that should be sliced in atop this span.
123
131
suggested_replacement : Option < String > ,
132
+ /// If the suggestion is approximate
133
+ #[ rustc_serialize_exclude_null]
134
+ suggestion_approximate : Option < bool > ,
124
135
/// Macro invocations that created the code at this span, if any.
125
136
expansion : Option < Box < DiagnosticSpanMacroExpansion > > ,
126
137
}
@@ -220,7 +231,7 @@ impl Diagnostic {
220
231
221
232
impl DiagnosticSpan {
222
233
fn from_span_label ( span : SpanLabel ,
223
- suggestion : Option < & String > ,
234
+ suggestion : Option < ( & String , bool ) > ,
224
235
je : & JsonEmitter )
225
236
-> DiagnosticSpan {
226
237
Self :: from_span_etc ( span. span ,
@@ -233,7 +244,7 @@ impl DiagnosticSpan {
233
244
fn from_span_etc ( span : Span ,
234
245
is_primary : bool ,
235
246
label : Option < String > ,
236
- suggestion : Option < & String > ,
247
+ suggestion : Option < ( & String , bool ) > ,
237
248
je : & JsonEmitter )
238
249
-> DiagnosticSpan {
239
250
// obtain the full backtrace from the `macro_backtrace`
@@ -253,7 +264,7 @@ impl DiagnosticSpan {
253
264
fn from_span_full ( span : Span ,
254
265
is_primary : bool ,
255
266
label : Option < String > ,
256
- suggestion : Option < & String > ,
267
+ suggestion : Option < ( & String , bool ) > ,
257
268
mut backtrace : vec:: IntoIter < MacroBacktrace > ,
258
269
je : & JsonEmitter )
259
270
-> DiagnosticSpan {
@@ -281,6 +292,13 @@ impl DiagnosticSpan {
281
292
def_site_span,
282
293
} )
283
294
} ) ;
295
+
296
+ let suggestion_approximate = if je. approximate_suggestions {
297
+ suggestion. map ( |x| x. 1 )
298
+ } else {
299
+ None
300
+ } ;
301
+
284
302
DiagnosticSpan {
285
303
file_name : start. file . name . to_string ( ) ,
286
304
byte_start : span. lo ( ) . 0 - start. file . start_pos . 0 ,
@@ -291,7 +309,8 @@ impl DiagnosticSpan {
291
309
column_end : end. col . 0 + 1 ,
292
310
is_primary,
293
311
text : DiagnosticSpanLine :: from_span ( span, je) ,
294
- suggested_replacement : suggestion. cloned ( ) ,
312
+ suggested_replacement : suggestion. map ( |x| x. 0 . clone ( ) ) ,
313
+ suggestion_approximate,
295
314
expansion : backtrace_step,
296
315
label,
297
316
}
@@ -309,14 +328,15 @@ impl DiagnosticSpan {
309
328
suggestion. substitutions
310
329
. iter ( )
311
330
. flat_map ( |substitution| {
312
- substitution. parts . iter ( ) . map ( move |suggestion | {
331
+ substitution. parts . iter ( ) . map ( move |suggestion_inner | {
313
332
let span_label = SpanLabel {
314
- span : suggestion . span ,
333
+ span : suggestion_inner . span ,
315
334
is_primary : true ,
316
335
label : None ,
317
336
} ;
318
337
DiagnosticSpan :: from_span_label ( span_label,
319
- Some ( & suggestion. snippet ) ,
338
+ Some ( ( & suggestion_inner. snippet ,
339
+ suggestion. approximate ) ) ,
320
340
je)
321
341
} )
322
342
} )
0 commit comments