Skip to content

Commit a53bdc6

Browse files
committed
Add -Zapproximate-suggestions
1 parent 937bc2e commit a53bdc6

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12881288
dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
12891289
"in dep-info output, omit targets for tracking dependencies of the dep-info files \
12901290
themselves"),
1291+
approximate_suggestions: bool = (false, parse_bool, [UNTRACKED],
1292+
"include machine-applicability of suggestions in JSON output"),
12911293
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
12921294
"Present the input source, unstable (and less-pretty) variants;
12931295
valid types are any of the types for `--pretty`, as well as:

src/librustc/session/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,12 @@ pub fn build_session_with_codemap(sopts: config::Options,
910910
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
911911
}
912912
(config::ErrorOutputType::Json(pretty), None) => {
913-
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(), pretty))
913+
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(),
914+
pretty, sopts.debugging_opts.approximate_suggestions))
914915
}
915916
(config::ErrorOutputType::Json(pretty), Some(dst)) => {
916-
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(), pretty))
917+
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(),
918+
pretty, sopts.debugging_opts.approximate_suggestions))
917919
}
918920
(config::ErrorOutputType::Short(color_config), None) => {
919921
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))

src/libsyntax/json.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -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

4345
impl 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
}
@@ -283,6 +290,13 @@ impl DiagnosticSpan {
283290
def_site_span,
284291
})
285292
});
293+
294+
let suggestion_approximate = if je.approximate_suggestions {
295+
suggestion.map(|x| x.1)
296+
} else {
297+
None
298+
};
299+
286300
DiagnosticSpan {
287301
file_name: start.file.name.to_string(),
288302
byte_start: span.lo().0 - start.file.start_pos.0,
@@ -294,7 +308,7 @@ impl DiagnosticSpan {
294308
is_primary,
295309
text: DiagnosticSpanLine::from_span(span, je),
296310
suggested_replacement: suggestion.map(|x| x.0.clone()),
297-
suggestion_approximate: suggestion.map(|x| x.1),
311+
suggestion_approximate,
298312
expansion: backtrace_step,
299313
label,
300314
}

0 commit comments

Comments
 (0)