From 65c899edfe889118af594c37d16e93f6c4b194f6 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Nov 2017 12:37:11 +0100 Subject: [PATCH 1/5] Remove outdated documentation --- src/libsyntax/json.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 31fe0c234e8d3..a304173f36d5b 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -85,9 +85,7 @@ struct Diagnostic { spans: Vec, /// Associated diagnostic messages. children: Vec, - /// The message as rustc would render it. Currently this is only - /// `Some` for "suggestions", but eventually it will include all - /// snippets. + /// The message as rustc would render it. Currently this is always `None` rendered: Option, } @@ -110,9 +108,7 @@ struct DiagnosticSpan { /// Label that should be placed at this location (if any) label: Option, /// If we are suggesting a replacement, this will contain text - /// that should be sliced in atop this span. You may prefer to - /// load the fully rendered version from the parent `Diagnostic`, - /// however. + /// that should be sliced in atop this span. suggested_replacement: Option, /// Macro invocations that created the code at this span, if any. expansion: Option>, From c7cb2cf8b5a9c7b5b57128a4969b0b577ecaf5d9 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Nov 2017 13:38:26 +0100 Subject: [PATCH 2/5] Pretty print json in ui tests --- src/librustc/session/config.rs | 12 +- src/librustc/session/mod.rs | 14 +- src/libsyntax/json.rs | 22 +- .../ui/lint/unused_parens_json_suggestion.rs | 2 +- .../lint/unused_parens_json_suggestion.stderr | 92 +++++- src/test/ui/lint/use_suggestion_json.rs | 2 +- src/test/ui/lint/use_suggestion_json.stderr | 292 +++++++++++++++++- src/tools/compiletest/src/runtest.rs | 3 +- 8 files changed, 418 insertions(+), 21 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 0f8312abc3f9f..3e93a6332465b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -155,7 +155,7 @@ impl OutputType { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ErrorOutputType { HumanReadable(ColorConfig), - Json, + Json(bool), Short(ColorConfig), } @@ -1104,6 +1104,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "enable ThinLTO when possible"), inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], "control whether #[inline] functions are in all cgus"), + pretty_json_error_format: bool = (false, parse_bool, [UNTRACKED], + "allow `--error-format=pretty-json` (used for compiletest)"), } pub fn default_lib_output() -> CrateType { @@ -1433,7 +1435,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) let error_format = if matches.opts_present(&["error-format".to_owned()]) { match matches.opt_str("error-format").as_ref().map(|s| &s[..]) { Some("human") => ErrorOutputType::HumanReadable(color), - Some("json") => ErrorOutputType::Json, + Some("json") => ErrorOutputType::Json(false), + Some("pretty-json") => ErrorOutputType::Json(true), Some("short") => ErrorOutputType::Short(color), None => ErrorOutputType::HumanReadable(color), @@ -1474,6 +1477,11 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) let debugging_opts = build_debugging_options(matches, error_format); + if !debugging_opts.pretty_json_error_format && error_format == ErrorOutputType::Json(true) { + early_error(ErrorOutputType::Json(false), "--error-format=pretty-json is unstable \ + (use -Zpretty-json-error-format)"); + } + let mut output_types = BTreeMap::new(); if !debugging_opts.parse_only { for list in matches.opt_strs("emit") { diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index a15a9a84580b3..39cf50787effe 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -372,7 +372,7 @@ impl Session { match self.opts.error_format { // when outputting JSON for tool consumption, the tool might want // the duplicates - config::ErrorOutputType::Json => { + config::ErrorOutputType::Json(_) => { do_method() }, _ => { @@ -736,11 +736,11 @@ pub fn build_session_with_codemap(sopts: config::Options, (config::ErrorOutputType::HumanReadable(_), Some(dst)) => { Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false)) } - (config::ErrorOutputType::Json, None) => { - Box::new(JsonEmitter::stderr(Some(registry), codemap.clone())) + (config::ErrorOutputType::Json(pretty), None) => { + Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(), pretty)) } - (config::ErrorOutputType::Json, Some(dst)) => { - Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone())) + (config::ErrorOutputType::Json(pretty), Some(dst)) => { + Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(), pretty)) } (config::ErrorOutputType::Short(color_config), None) => { Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true)) @@ -918,7 +918,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { config::ErrorOutputType::HumanReadable(color_config) => { Box::new(EmitterWriter::stderr(color_config, None, false)) } - config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()), + config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)), config::ErrorOutputType::Short(color_config) => { Box::new(EmitterWriter::stderr(color_config, None, true)) } @@ -933,7 +933,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { config::ErrorOutputType::HumanReadable(color_config) => { Box::new(EmitterWriter::stderr(color_config, None, false)) } - config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()), + config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)), config::ErrorOutputType::Short(color_config) => { Box::new(EmitterWriter::stderr(color_config, None, true)) } diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index a304173f36d5b..74a762f2f622c 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -30,36 +30,41 @@ use std::rc::Rc; use std::io::{self, Write}; use std::vec; -use rustc_serialize::json::as_json; +use rustc_serialize::json::{as_json, as_pretty_json}; pub struct JsonEmitter { dst: Box, registry: Option, cm: Rc, + pretty: bool, } impl JsonEmitter { pub fn stderr(registry: Option, - code_map: Rc) -> JsonEmitter { + code_map: Rc, + pretty: bool) -> JsonEmitter { JsonEmitter { dst: Box::new(io::stderr()), registry, cm: code_map, + pretty, } } - pub fn basic() -> JsonEmitter { + pub fn basic(pretty: bool) -> JsonEmitter { let file_path_mapping = FilePathMapping::empty(); - JsonEmitter::stderr(None, Rc::new(CodeMap::new(file_path_mapping))) + JsonEmitter::stderr(None, Rc::new(CodeMap::new(file_path_mapping)), pretty) } pub fn new(dst: Box, registry: Option, - code_map: Rc) -> JsonEmitter { + code_map: Rc, + pretty: bool) -> JsonEmitter { JsonEmitter { dst, registry, cm: code_map, + pretty, } } } @@ -67,7 +72,12 @@ impl JsonEmitter { impl Emitter for JsonEmitter { fn emit(&mut self, db: &DiagnosticBuilder) { let data = Diagnostic::from_diagnostic_builder(db, self); - if let Err(e) = writeln!(&mut self.dst, "{}", as_json(&data)) { + let result = if self.pretty { + writeln!(&mut self.dst, "{}", as_pretty_json(&data)) + } else { + writeln!(&mut self.dst, "{}", as_json(&data)) + }; + if let Err(e) = result { panic!("failed to print diagnostics: {:?}", e); } } diff --git a/src/test/ui/lint/unused_parens_json_suggestion.rs b/src/test/ui/lint/unused_parens_json_suggestion.rs index 15251795d5e08..e05eac774bf4e 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.rs +++ b/src/test/ui/lint/unused_parens_json_suggestion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --error-format json +// compile-flags: --error-format pretty-json -Zpretty_json_error_format // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr index 02bb76722e6fa..d2e2d6220f117 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr @@ -1 +1,91 @@ -{"message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"warning","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":847,"byte_end":860,"line_start":19,"line_end":19,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![warn(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":"1 / (2 + 3)","expansion":null}],"children":[],"rendered":null}],"rendered":null} +{ + "message": "unnecessary parentheses around assigned value", + "code": { + "code": "unused_parens", + "explanation": null + }, + "level": "warning", + "spans": [ + { + "file_name": "$DIR/unused_parens_json_suggestion.rs", + "byte_start": 1035, + "byte_end": 1048, + "line_start": 24, + "line_end": 24, + "column_start": 14, + "column_end": 27, + "is_primary": true, + "text": [ + { + "text": " let _a = (1 / (2 + 3));", + "highlight_start": 14, + "highlight_end": 27 + } + ], + "label": null, + "suggested_replacement": null, + "expansion": null + } + ], + "children": [ + { + "message": "lint level defined here", + "code": null, + "level": "note", + "spans": [ + { + "file_name": "$DIR/unused_parens_json_suggestion.rs", + "byte_start": 881, + "byte_end": 894, + "line_start": 19, + "line_end": 19, + "column_start": 9, + "column_end": 22, + "is_primary": true, + "text": [ + { + "text": "#![warn(unused_parens)]", + "highlight_start": 9, + "highlight_end": 22 + } + ], + "label": null, + "suggested_replacement": null, + "expansion": null + } + ], + "children": [], + "rendered": null + }, + { + "message": "remove these parentheses", + "code": null, + "level": "help", + "spans": [ + { + "file_name": "$DIR/unused_parens_json_suggestion.rs", + "byte_start": 1035, + "byte_end": 1048, + "line_start": 24, + "line_end": 24, + "column_start": 14, + "column_end": 27, + "is_primary": true, + "text": [ + { + "text": " let _a = (1 / (2 + 3));", + "highlight_start": 14, + "highlight_end": 27 + } + ], + "label": null, + "suggested_replacement": "1 / (2 + 3)", + "expansion": null + } + ], + "children": [], + "rendered": null + } + ], + "rendered": null +} diff --git a/src/test/ui/lint/use_suggestion_json.rs b/src/test/ui/lint/use_suggestion_json.rs index 20c24d6405042..19169722b35b7 100644 --- a/src/test/ui/lint/use_suggestion_json.rs +++ b/src/test/ui/lint/use_suggestion_json.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --error-format json +// compile-flags: --error-format pretty-json -Zpretty_json_error_format // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index 2ebe212b93ddb..163574fc0ad01 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -1,2 +1,290 @@ -{"message":"cannot find type `Iter` in this scope","code":{"code":"E0412","explanation":"/nThe type name used is not in scope./n/nErroneous code examples:/n/n```compile_fail,E0412/nimpl Something {} // error: type name `Something` is not in scope/n/n// or:/n/ntrait Foo {/n fn bar(N); // error: type name `N` is not in scope/n}/n/n// or:/n/nfn foo(x: T) {} // type name `T` is not in scope/n```/n/nTo fix this error, please verify you didn't misspell the type name, you did/ndeclare it or imported it into the scope. Examples:/n/n```/nstruct Something;/n/nimpl Something {} // ok!/n/n// or:/n/ntrait Foo {/n type N;/n/n fn bar(_: Self::N); // ok!/n}/n/n// or:/n/nfn foo(x: T) {} // ok!/n```/n/nAnother case that causes this error is when a type is imported into a parent/nmodule. To fix this, you can follow the suggestion and use File directly or/n`use super::File;` which will import the types from the parent namespace. An/nexample that causes this error is below:/n/n```compile_fail,E0412/nuse std::fs::File;/n/nmod foo {/n fn some_function(f: File) {}/n}/n```/n/n```/nuse std::fs::File;/n/nmod foo {/n // either/n use super::File;/n // or/n // use std::fs::File;/n fn foo(f: File) {}/n}/n# fn main() {} // don't insert it for us; that'll break imports/n```/n"},"level":"error","spans":[{"file_name":"$DIR/use_suggestion_json.rs","byte_start":862,"byte_end":866,"line_start":20,"line_end":20,"column_start":12,"column_end":16,"is_primary":true,"text":[{"text":" let x: Iter;","highlight_start":12,"highlight_end":16}],"label":"not found in this scope","suggested_replacement":null,"expansion":null}],"children":[{"message":"possible candidates are found in other modules, you can import them into scope","code":null,"level":"help","spans":[{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::binary_heap::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::btree_map::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::btree_set::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::hash_map::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::hash_set::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::linked_list::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::collections::vec_deque::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::option::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::path::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::result::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::slice::Iter;/n/n","expansion":null},{"file_name":"$DIR/use_suggestion_json.rs","byte_start":839,"byte_end":839,"line_start":19,"line_end":19,"column_start":1,"column_end":1,"is_primary":true,"text":[{"text":"fn main() {","highlight_start":1,"highlight_end":1}],"label":null,"suggested_replacement":"use std::sync::mpsc::Iter;/n/n","expansion":null}],"children":[],"rendered":null}],"rendered":null} -{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":null} +{ + "message": "cannot find type `Iter` in this scope", + "code": { + "code": "E0412", + "explanation": "/nThe type name used is not in scope./n/nErroneous code examples:/n/n```compile_fail,E0412/nimpl Something {} // error: type name `Something` is not in scope/n/n// or:/n/ntrait Foo {/n fn bar(N); // error: type name `N` is not in scope/n}/n/n// or:/n/nfn foo(x: T) {} // type name `T` is not in scope/n```/n/nTo fix this error, please verify you didn't misspell the type name, you did/ndeclare it or imported it into the scope. Examples:/n/n```/nstruct Something;/n/nimpl Something {} // ok!/n/n// or:/n/ntrait Foo {/n type N;/n/n fn bar(_: Self::N); // ok!/n}/n/n// or:/n/nfn foo(x: T) {} // ok!/n```/n/nAnother case that causes this error is when a type is imported into a parent/nmodule. To fix this, you can follow the suggestion and use File directly or/n`use super::File;` which will import the types from the parent namespace. An/nexample that causes this error is below:/n/n```compile_fail,E0412/nuse std::fs::File;/n/nmod foo {/n fn some_function(f: File) {}/n}/n```/n/n```/nuse std::fs::File;/n/nmod foo {/n // either/n use super::File;/n // or/n // use std::fs::File;/n fn foo(f: File) {}/n}/n# fn main() {} // don't insert it for us; that'll break imports/n```/n" + }, + "level": "error", + "spans": [ + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 896, + "byte_end": 900, + "line_start": 20, + "line_end": 20, + "column_start": 12, + "column_end": 16, + "is_primary": true, + "text": [ + { + "text": " let x: Iter;", + "highlight_start": 12, + "highlight_end": 16 + } + ], + "label": "not found in this scope", + "suggested_replacement": null, + "expansion": null + } + ], + "children": [ + { + "message": "possible candidates are found in other modules, you can import them into scope", + "code": null, + "level": "help", + "spans": [ + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::binary_heap::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::btree_map::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::btree_set::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::hash_map::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::hash_set::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::linked_list::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::collections::vec_deque::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::option::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::path::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::result::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::slice::Iter;/n/n", + "expansion": null + }, + { + "file_name": "$DIR/use_suggestion_json.rs", + "byte_start": 873, + "byte_end": 873, + "line_start": 19, + "line_end": 19, + "column_start": 1, + "column_end": 1, + "is_primary": true, + "text": [ + { + "text": "fn main() {", + "highlight_start": 1, + "highlight_end": 1 + } + ], + "label": null, + "suggested_replacement": "use std::sync::mpsc::Iter;/n/n", + "expansion": null + } + ], + "children": [], + "rendered": null + } + ], + "rendered": null +} +{ + "message": "aborting due to previous error", + "code": null, + "level": "error", + "spans": [], + "children": [], + "rendered": null +} diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f8628158aff46..128bccbee62cb 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2378,7 +2378,8 @@ actual:\n\ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String { let parent_dir = self.testpaths.file.parent().unwrap(); let cflags = self.props.compile_flags.join(" "); - let parent_dir_str = if cflags.contains("--error-format json") { + let parent_dir_str = if cflags.contains("--error-format json") + || cflags.contains("--error-format pretty-json") { parent_dir.display().to_string().replace("\\", "\\\\") } else { parent_dir.display().to_string() From d1d9cfc7221d0b0b791f571049b13cf86d1d8ed1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Nov 2017 16:22:19 +0100 Subject: [PATCH 3/5] Don't add a new -Z flag, reuse -Zunstable-options --- src/librustc/session/config.rs | 110 +++++++++--------- .../ui/lint/unused_parens_json_suggestion.rs | 2 +- src/test/ui/lint/use_suggestion_json.rs | 2 +- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 3e93a6332465b..7a5b3afe5ae7d 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1104,8 +1104,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "enable ThinLTO when possible"), inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], "control whether #[inline] functions are in all cgus"), - pretty_json_error_format: bool = (false, parse_bool, [UNTRACKED], - "allow `--error-format=pretty-json` (used for compiletest)"), } pub fn default_lib_output() -> CrateType { @@ -1477,7 +1475,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) let debugging_opts = build_debugging_options(matches, error_format); - if !debugging_opts.pretty_json_error_format && error_format == ErrorOutputType::Json(true) { + if !debugging_opts.unstable_options && error_format == ErrorOutputType::Json(true) { early_error(ErrorOutputType::Json(false), "--error-format=pretty-json is unstable \ (use -Zpretty-json-error-format)"); } @@ -2262,46 +2260,46 @@ mod tests { let mut v5 = super::basic_options(); // Reference - v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json); + v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); // Native changed - v2.search_paths.add_path("native=XXX", super::ErrorOutputType::Json); - v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json); + v2.search_paths.add_path("native=XXX", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); // Crate changed - v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v2.search_paths.add_path("crate=XXX", super::ErrorOutputType::Json); - v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json); + v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("crate=XXX", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); // Dependency changed - v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v3.search_paths.add_path("dependency=XXX", super::ErrorOutputType::Json); - v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json); + v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("dependency=XXX", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); // Framework changed - v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v4.search_paths.add_path("framework=XXX", super::ErrorOutputType::Json); - v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json); + v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("framework=XXX", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); // All changed - v5.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v5.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v5.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v5.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v5.search_paths.add_path("all=XXX", super::ErrorOutputType::Json); + v5.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v5.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v5.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v5.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v5.search_paths.add_path("all=XXX", super::ErrorOutputType::Json(false)); assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash()); assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash()); @@ -2324,29 +2322,29 @@ mod tests { let mut v4 = super::basic_options(); // Reference - v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json); - - v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json); - - v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); - v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v3.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json); - - v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json); - v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json); - v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json); - v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json); - v4.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json); + v1.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v1.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); + + v2.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v2.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); + + v3.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v3.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); + + v4.search_paths.add_path("all=mno", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("native=abc", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("crate=def", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("dependency=ghi", super::ErrorOutputType::Json(false)); + v4.search_paths.add_path("framework=jkl", super::ErrorOutputType::Json(false)); assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash()); assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash()); diff --git a/src/test/ui/lint/unused_parens_json_suggestion.rs b/src/test/ui/lint/unused_parens_json_suggestion.rs index e05eac774bf4e..ad501e668095a 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.rs +++ b/src/test/ui/lint/unused_parens_json_suggestion.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --error-format pretty-json -Zpretty_json_error_format +// compile-flags: --error-format pretty-json -Zunstable-options // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/src/test/ui/lint/use_suggestion_json.rs b/src/test/ui/lint/use_suggestion_json.rs index 19169722b35b7..27232c4fec4ad 100644 --- a/src/test/ui/lint/use_suggestion_json.rs +++ b/src/test/ui/lint/use_suggestion_json.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: --error-format pretty-json -Zpretty_json_error_format +// compile-flags: --error-format pretty-json -Zunstable-options // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested From e5c1d512e754e93a56a7dd9ca27e82f502eee39a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 3 Nov 2017 16:32:03 +0100 Subject: [PATCH 4/5] Update config.rs --- src/librustc/session/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 7a5b3afe5ae7d..94cc22f11a003 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1476,8 +1476,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) let debugging_opts = build_debugging_options(matches, error_format); if !debugging_opts.unstable_options && error_format == ErrorOutputType::Json(true) { - early_error(ErrorOutputType::Json(false), "--error-format=pretty-json is unstable \ - (use -Zpretty-json-error-format)"); + early_error(ErrorOutputType::Json(false), + "--error-format=pretty-json is unstable"); } let mut output_types = BTreeMap::new(); From 6d6fb2ef97b81cd5fd39c86b881879d16ecd31c0 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 6 Nov 2017 10:34:23 +0100 Subject: [PATCH 5/5] Adjust json errors to byte changes --- .../lint/unused_parens_json_suggestion.stderr | 12 ++--- src/test/ui/lint/use_suggestion_json.stderr | 52 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr index d2e2d6220f117..e166f7011b58a 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr @@ -8,8 +8,8 @@ "spans": [ { "file_name": "$DIR/unused_parens_json_suggestion.rs", - "byte_start": 1035, - "byte_end": 1048, + "byte_start": 1027, + "byte_end": 1040, "line_start": 24, "line_end": 24, "column_start": 14, @@ -35,8 +35,8 @@ "spans": [ { "file_name": "$DIR/unused_parens_json_suggestion.rs", - "byte_start": 881, - "byte_end": 894, + "byte_start": 873, + "byte_end": 886, "line_start": 19, "line_end": 19, "column_start": 9, @@ -64,8 +64,8 @@ "spans": [ { "file_name": "$DIR/unused_parens_json_suggestion.rs", - "byte_start": 1035, - "byte_end": 1048, + "byte_start": 1027, + "byte_end": 1040, "line_start": 24, "line_end": 24, "column_start": 14, diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index 163574fc0ad01..fd3b5fe1adadf 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -8,8 +8,8 @@ "spans": [ { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 896, - "byte_end": 900, + "byte_start": 888, + "byte_end": 892, "line_start": 20, "line_end": 20, "column_start": 12, @@ -35,8 +35,8 @@ "spans": [ { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -55,8 +55,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -75,8 +75,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -95,8 +95,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -115,8 +115,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -135,8 +135,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -155,8 +155,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -175,8 +175,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -195,8 +195,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -215,8 +215,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -235,8 +235,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1, @@ -255,8 +255,8 @@ }, { "file_name": "$DIR/use_suggestion_json.rs", - "byte_start": 873, - "byte_end": 873, + "byte_start": 865, + "byte_end": 865, "line_start": 19, "line_end": 19, "column_start": 1,