Skip to content

Commit 9ff8ec8

Browse files
committed
Auto merge of #50204 - Manishearth:approx-enum, r=estebank
Use enum for approximate suggestions r? @nrc @killercup
2 parents f900bcf + 4e2cd41 commit 9ff8ec8

File tree

7 files changed

+45
-31
lines changed

7 files changed

+45
-31
lines changed

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12701270
dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
12711271
"in dep-info output, omit targets for tracking dependencies of the dep-info files \
12721272
themselves"),
1273-
approximate_suggestions: bool = (false, parse_bool, [UNTRACKED],
1273+
suggestion_applicability: bool = (false, parse_bool, [UNTRACKED],
12741274
"include machine-applicability of suggestions in JSON output"),
12751275
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
12761276
"Present the input source, unstable (and less-pretty) variants;

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ pub fn build_session_with_codemap(
10021002
Some(registry),
10031003
codemap.clone(),
10041004
pretty,
1005-
sopts.debugging_opts.approximate_suggestions,
1005+
sopts.debugging_opts.suggestion_applicability,
10061006
).ui_testing(sopts.debugging_opts.ui_testing),
10071007
),
10081008
(config::ErrorOutputType::Json(pretty), Some(dst)) => Box::new(
@@ -1011,7 +1011,7 @@ pub fn build_session_with_codemap(
10111011
Some(registry),
10121012
codemap.clone(),
10131013
pretty,
1014-
sopts.debugging_opts.approximate_suggestions,
1014+
sopts.debugging_opts.suggestion_applicability,
10151015
).ui_testing(sopts.debugging_opts.ui_testing),
10161016
),
10171017
(config::ErrorOutputType::Short(color_config), None) => Box::new(

src/librustc_errors/diagnostic.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use CodeSuggestion;
1212
use SubstitutionPart;
1313
use Substitution;
14+
use Applicability;
1415
use Level;
1516
use std::fmt;
1617
use syntax_pos::{MultiSpan, Span};
@@ -222,7 +223,7 @@ impl Diagnostic {
222223
}],
223224
msg: msg.to_owned(),
224225
show_code_when_inline: false,
225-
approximate: false,
226+
applicability: Applicability::Unspecified,
226227
});
227228
self
228229
}
@@ -253,7 +254,7 @@ impl Diagnostic {
253254
}],
254255
msg: msg.to_owned(),
255256
show_code_when_inline: true,
256-
approximate: false,
257+
applicability: Applicability::Unspecified,
257258
});
258259
self
259260
}
@@ -269,15 +270,16 @@ impl Diagnostic {
269270
}).collect(),
270271
msg: msg.to_owned(),
271272
show_code_when_inline: true,
272-
approximate: false,
273+
applicability: Applicability::Unspecified,
273274
});
274275
self
275276
}
276277

277278
/// This is a suggestion that may contain mistakes or fillers and should
278279
/// be read and understood by a human.
279-
pub fn span_approximate_suggestion(&mut self, sp: Span, msg: &str,
280-
suggestion: String) -> &mut Self {
280+
pub fn span_suggestion_with_applicability(&mut self, sp: Span, msg: &str,
281+
suggestion: String,
282+
applicability: Applicability) -> &mut Self {
281283
self.suggestions.push(CodeSuggestion {
282284
substitutions: vec![Substitution {
283285
parts: vec![SubstitutionPart {
@@ -287,13 +289,14 @@ impl Diagnostic {
287289
}],
288290
msg: msg.to_owned(),
289291
show_code_when_inline: true,
290-
approximate: true,
292+
applicability,
291293
});
292294
self
293295
}
294296

295-
pub fn span_approximate_suggestions(&mut self, sp: Span, msg: &str,
296-
suggestions: Vec<String>) -> &mut Self {
297+
pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
298+
suggestions: Vec<String>,
299+
applicability: Applicability) -> &mut Self {
297300
self.suggestions.push(CodeSuggestion {
298301
substitutions: suggestions.into_iter().map(|snippet| Substitution {
299302
parts: vec![SubstitutionPart {
@@ -303,7 +306,7 @@ impl Diagnostic {
303306
}).collect(),
304307
msg: msg.to_owned(),
305308
show_code_when_inline: true,
306-
approximate: true,
309+
applicability,
307310
});
308311
self
309312
}

src/librustc_errors/diagnostic_builder.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Diagnostic;
1212
use DiagnosticId;
1313
use DiagnosticStyledString;
14+
use Applicability;
1415

1516
use Level;
1617
use Handler;
@@ -187,15 +188,17 @@ impl<'a> DiagnosticBuilder<'a> {
187188
msg: &str,
188189
suggestions: Vec<String>)
189190
-> &mut Self);
190-
forward!(pub fn span_approximate_suggestion(&mut self,
191+
forward!(pub fn span_suggestion_with_applicability(&mut self,
191192
sp: Span,
192193
msg: &str,
193-
suggestion: String)
194+
suggestion: String,
195+
applicability: Applicability)
194196
-> &mut Self);
195-
forward!(pub fn span_approximate_suggestions(&mut self,
197+
forward!(pub fn span_suggestions_with_applicability(&mut self,
196198
sp: Span,
197199
msg: &str,
198-
suggestions: Vec<String>)
200+
suggestions: Vec<String>,
201+
applicability: Applicability)
199202
-> &mut Self);
200203
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
201204
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);

src/librustc_errors/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ mod lock;
5656

5757
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
5858

59+
#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
60+
pub enum Applicability {
61+
MachineApplicable,
62+
HasPlaceholders,
63+
MaybeIncorrect,
64+
Unspecified
65+
}
66+
5967
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
6068
pub struct CodeSuggestion {
6169
/// Each substitute can have multiple variants due to multiple
@@ -87,7 +95,7 @@ pub struct CodeSuggestion {
8795
/// Sometimes we may show suggestions with placeholders,
8896
/// which are useful for users but not useful for
8997
/// tools like rustfix
90-
pub approximate: bool,
98+
pub applicability: Applicability,
9199
}
92100

93101
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn run_core(search_paths: SearchPaths,
177177
None,
178178
codemap.clone(),
179179
pretty,
180-
sessopts.debugging_opts.approximate_suggestions,
180+
sessopts.debugging_opts.suggestion_applicability,
181181
).ui_testing(sessopts.debugging_opts.ui_testing)
182182
),
183183
ErrorOutputType::Short(color_config) => Box::new(

src/libsyntax/json.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use codemap::{CodeMap, FilePathMapping};
2323
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
2424
use errors::registry::Registry;
2525
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
26-
use errors::DiagnosticId;
26+
use errors::{DiagnosticId, Applicability};
2727
use errors::emitter::{Emitter, EmitterWriter};
2828

2929
use rustc_data_structures::sync::{self, Lrc};
@@ -39,21 +39,21 @@ pub struct JsonEmitter {
3939
cm: Lrc<CodeMapper + sync::Send + sync::Sync>,
4040
pretty: bool,
4141
/// Whether "approximate suggestions" are enabled in the config
42-
approximate_suggestions: bool,
42+
suggestion_applicability: bool,
4343
ui_testing: bool,
4444
}
4545

4646
impl JsonEmitter {
4747
pub fn stderr(registry: Option<Registry>,
4848
code_map: Lrc<CodeMap>,
4949
pretty: bool,
50-
approximate_suggestions: bool) -> JsonEmitter {
50+
suggestion_applicability: bool) -> JsonEmitter {
5151
JsonEmitter {
5252
dst: Box::new(io::stderr()),
5353
registry,
5454
cm: code_map,
5555
pretty,
56-
approximate_suggestions,
56+
suggestion_applicability,
5757
ui_testing: false,
5858
}
5959
}
@@ -68,13 +68,13 @@ impl JsonEmitter {
6868
registry: Option<Registry>,
6969
code_map: Lrc<CodeMap>,
7070
pretty: bool,
71-
approximate_suggestions: bool) -> JsonEmitter {
71+
suggestion_applicability: bool) -> JsonEmitter {
7272
JsonEmitter {
7373
dst,
7474
registry,
7575
cm: code_map,
7676
pretty,
77-
approximate_suggestions,
77+
suggestion_applicability,
7878
ui_testing: false,
7979
}
8080
}
@@ -138,7 +138,7 @@ struct DiagnosticSpan {
138138
suggested_replacement: Option<String>,
139139
/// If the suggestion is approximate
140140
#[rustc_serialize_exclude_null]
141-
suggestion_approximate: Option<bool>,
141+
suggestion_applicability: Option<Applicability>,
142142
/// Macro invocations that created the code at this span, if any.
143143
expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
144144
}
@@ -239,7 +239,7 @@ impl Diagnostic {
239239

240240
impl DiagnosticSpan {
241241
fn from_span_label(span: SpanLabel,
242-
suggestion: Option<(&String, bool)>,
242+
suggestion: Option<(&String, Applicability)>,
243243
je: &JsonEmitter)
244244
-> DiagnosticSpan {
245245
Self::from_span_etc(span.span,
@@ -252,7 +252,7 @@ impl DiagnosticSpan {
252252
fn from_span_etc(span: Span,
253253
is_primary: bool,
254254
label: Option<String>,
255-
suggestion: Option<(&String, bool)>,
255+
suggestion: Option<(&String, Applicability)>,
256256
je: &JsonEmitter)
257257
-> DiagnosticSpan {
258258
// obtain the full backtrace from the `macro_backtrace`
@@ -272,7 +272,7 @@ impl DiagnosticSpan {
272272
fn from_span_full(span: Span,
273273
is_primary: bool,
274274
label: Option<String>,
275-
suggestion: Option<(&String, bool)>,
275+
suggestion: Option<(&String, Applicability)>,
276276
mut backtrace: vec::IntoIter<MacroBacktrace>,
277277
je: &JsonEmitter)
278278
-> DiagnosticSpan {
@@ -301,7 +301,7 @@ impl DiagnosticSpan {
301301
})
302302
});
303303

304-
let suggestion_approximate = if je.approximate_suggestions {
304+
let suggestion_applicability = if je.suggestion_applicability {
305305
suggestion.map(|x| x.1)
306306
} else {
307307
None
@@ -318,7 +318,7 @@ impl DiagnosticSpan {
318318
is_primary,
319319
text: DiagnosticSpanLine::from_span(span, je),
320320
suggested_replacement: suggestion.map(|x| x.0.clone()),
321-
suggestion_approximate,
321+
suggestion_applicability,
322322
expansion: backtrace_step,
323323
label,
324324
}
@@ -344,7 +344,7 @@ impl DiagnosticSpan {
344344
};
345345
DiagnosticSpan::from_span_label(span_label,
346346
Some((&suggestion_inner.snippet,
347-
suggestion.approximate)),
347+
suggestion.applicability)),
348348
je)
349349
})
350350
})

0 commit comments

Comments
 (0)