@@ -38,34 +38,41 @@ pub struct JsonEmitter {
3838 registry : Option < Registry > ,
3939 cm : Rc < CodeMapper + ' static > ,
4040 pretty : bool ,
41+ /// Whether "approximate suggestions" are enabled in the config
42+ approximate_suggestions : bool ,
4143}
4244
4345impl JsonEmitter {
4446 pub fn stderr ( registry : Option < Registry > ,
4547 code_map : Rc < CodeMap > ,
46- pretty : bool ) -> JsonEmitter {
48+ pretty : bool ,
49+ approximate_suggestions : bool ) -> JsonEmitter {
4750 JsonEmitter {
4851 dst : Box :: new ( io:: stderr ( ) ) ,
4952 registry,
5053 cm : code_map,
5154 pretty,
55+ approximate_suggestions,
5256 }
5357 }
5458
5559 pub fn basic ( pretty : bool ) -> JsonEmitter {
5660 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 )
5863 }
5964
6065 pub fn new ( dst : Box < Write + Send > ,
6166 registry : Option < Registry > ,
6267 code_map : Rc < CodeMap > ,
63- pretty : bool ) -> JsonEmitter {
68+ pretty : bool ,
69+ approximate_suggestions : bool ) -> JsonEmitter {
6470 JsonEmitter {
6571 dst,
6672 registry,
6773 cm : code_map,
6874 pretty,
75+ approximate_suggestions,
6976 }
7077 }
7178}
@@ -101,6 +108,7 @@ struct Diagnostic {
101108}
102109
103110#[ derive( RustcEncodable ) ]
111+ #[ allow( unused_attributes) ]
104112struct DiagnosticSpan {
105113 file_name : String ,
106114 byte_start : u32 ,
@@ -121,6 +129,9 @@ struct DiagnosticSpan {
121129 /// If we are suggesting a replacement, this will contain text
122130 /// that should be sliced in atop this span.
123131 suggested_replacement : Option < String > ,
132+ /// If the suggestion is approximate
133+ #[ rustc_serialize_exclude_null]
134+ suggestion_approximate : Option < bool > ,
124135 /// Macro invocations that created the code at this span, if any.
125136 expansion : Option < Box < DiagnosticSpanMacroExpansion > > ,
126137}
@@ -220,7 +231,7 @@ impl Diagnostic {
220231
221232impl DiagnosticSpan {
222233 fn from_span_label ( span : SpanLabel ,
223- suggestion : Option < & String > ,
234+ suggestion : Option < ( & String , bool ) > ,
224235 je : & JsonEmitter )
225236 -> DiagnosticSpan {
226237 Self :: from_span_etc ( span. span ,
@@ -233,7 +244,7 @@ impl DiagnosticSpan {
233244 fn from_span_etc ( span : Span ,
234245 is_primary : bool ,
235246 label : Option < String > ,
236- suggestion : Option < & String > ,
247+ suggestion : Option < ( & String , bool ) > ,
237248 je : & JsonEmitter )
238249 -> DiagnosticSpan {
239250 // obtain the full backtrace from the `macro_backtrace`
@@ -253,7 +264,7 @@ impl DiagnosticSpan {
253264 fn from_span_full ( span : Span ,
254265 is_primary : bool ,
255266 label : Option < String > ,
256- suggestion : Option < & String > ,
267+ suggestion : Option < ( & String , bool ) > ,
257268 mut backtrace : vec:: IntoIter < MacroBacktrace > ,
258269 je : & JsonEmitter )
259270 -> DiagnosticSpan {
@@ -281,6 +292,13 @@ impl DiagnosticSpan {
281292 def_site_span,
282293 } )
283294 } ) ;
295+
296+ let suggestion_approximate = if je. approximate_suggestions {
297+ suggestion. map ( |x| x. 1 )
298+ } else {
299+ None
300+ } ;
301+
284302 DiagnosticSpan {
285303 file_name : start. file . name . to_string ( ) ,
286304 byte_start : span. lo ( ) . 0 - start. file . start_pos . 0 ,
@@ -291,7 +309,8 @@ impl DiagnosticSpan {
291309 column_end : end. col . 0 + 1 ,
292310 is_primary,
293311 text : DiagnosticSpanLine :: from_span ( span, je) ,
294- suggested_replacement : suggestion. cloned ( ) ,
312+ suggested_replacement : suggestion. map ( |x| x. 0 . clone ( ) ) ,
313+ suggestion_approximate,
295314 expansion : backtrace_step,
296315 label,
297316 }
@@ -309,14 +328,15 @@ impl DiagnosticSpan {
309328 suggestion. substitutions
310329 . iter ( )
311330 . flat_map ( |substitution| {
312- substitution. parts . iter ( ) . map ( move |suggestion | {
331+ substitution. parts . iter ( ) . map ( move |suggestion_inner | {
313332 let span_label = SpanLabel {
314- span : suggestion . span ,
333+ span : suggestion_inner . span ,
315334 is_primary : true ,
316335 label : None ,
317336 } ;
318337 DiagnosticSpan :: from_span_label ( span_label,
319- Some ( & suggestion. snippet ) ,
338+ Some ( ( & suggestion_inner. snippet ,
339+ suggestion. approximate ) ) ,
320340 je)
321341 } )
322342 } )
0 commit comments