Skip to content

Commit 82f8e5c

Browse files
committed
Address reviewer comments
[breaking-change] `OptLevel` variants are no longer `pub use`ed by rust::session::config. If you are using these variants, you must change your code to prefix the variant name with `OptLevel`.
1 parent 11dcb48 commit 82f8e5c

File tree

5 files changed

+69
-68
lines changed

5 files changed

+69
-68
lines changed

src/librustc/session/config.rs

+53-57
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ pub enum OutputType {
7272

7373
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7474
pub enum ErrorOutputType {
75-
Tty(ColorConfig),
75+
HumanReadable(ColorConfig),
7676
Json,
7777
}
7878

7979
impl Default for ErrorOutputType {
8080
fn default() -> ErrorOutputType {
81-
ErrorOutputType::Tty(ColorConfig::Auto)
81+
ErrorOutputType::HumanReadable(ColorConfig::Auto)
8282
}
8383
}
8484

@@ -135,7 +135,7 @@ pub struct Options {
135135
pub test: bool,
136136
pub parse_only: bool,
137137
pub no_trans: bool,
138-
pub output: ErrorOutputType,
138+
pub error_format: ErrorOutputType,
139139
pub treat_err_as_bug: bool,
140140
pub incremental_compilation: bool,
141141
pub dump_dep_graph: bool,
@@ -252,12 +252,7 @@ pub fn basic_options() -> Options {
252252
debugging_opts: basic_debugging_options(),
253253
prints: Vec::new(),
254254
cg: basic_codegen_options(),
255-
<<<<<<< HEAD
256-
color: ColorConfig::Auto,
257-
=======
258-
output: ErrorOutputType::default(),
259-
show_span: None,
260-
>>>>>>> Add an --output option for specifying an error emitter
255+
error_format: ErrorOutputType::default(),
261256
externs: HashMap::new(),
262257
crate_name: None,
263258
alt_std_name: None,
@@ -324,7 +319,7 @@ macro_rules! options {
324319
$struct_name { $($opt: $init),* }
325320
}
326321

327-
pub fn $buildfn(matches: &getopts::Matches, output: ErrorOutputType) -> $struct_name
322+
pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $struct_name
328323
{
329324
let mut op = $defaultfn();
330325
for option in matches.opt_strs($prefix) {
@@ -338,20 +333,20 @@ macro_rules! options {
338333
if !setter(&mut op, value) {
339334
match (value, opt_type_desc) {
340335
(Some(..), None) => {
341-
early_error(output, &format!("{} option `{}` takes no \
342-
value", $outputname, key))
336+
early_error(error_format, &format!("{} option `{}` takes no \
337+
value", $outputname, key))
343338
}
344339
(None, Some(type_desc)) => {
345-
early_error(output, &format!("{0} option `{1}` requires \
346-
{2} ({3} {1}=<value>)",
347-
$outputname, key,
348-
type_desc, $prefix))
340+
early_error(error_format, &format!("{0} option `{1}` requires \
341+
{2} ({3} {1}=<value>)",
342+
$outputname, key,
343+
type_desc, $prefix))
349344
}
350345
(Some(value), Some(type_desc)) => {
351-
early_error(output, &format!("incorrect value `{}` for {} \
352-
option `{}` - {} was expected",
353-
value, $outputname,
354-
key, type_desc))
346+
early_error(error_format, &format!("incorrect value `{}` for {} \
347+
option `{}` - {} was expected",
348+
value, $outputname,
349+
key, type_desc))
355350
}
356351
(None, None) => unreachable!()
357352
}
@@ -360,8 +355,8 @@ macro_rules! options {
360355
break;
361356
}
362357
if !found {
363-
early_error(output, &format!("unknown {} option: `{}`",
364-
$outputname, key));
358+
early_error(error_format, &format!("unknown {} option: `{}`",
359+
$outputname, key));
365360
}
366361
}
367362
return op;
@@ -879,7 +874,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
879874
"NAME=PATH"),
880875
opt::opt("", "sysroot", "Override the system root", "PATH"),
881876
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
882-
opt::opt_u("", "output", "How errors and other mesasges are produced", "tty|json"),
877+
opt::opt_u("", "error-format", "How errors and other messages are produced", "human|json"),
883878
opt::opt("", "color", "Configure coloring of output:
884879
auto = colorize, if output goes to a tty (default);
885880
always = always colorize output;
@@ -929,19 +924,20 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
929924
};
930925

931926
// We need the opts_present check because the driver will send us Matches
932-
// with only stable options if no unstable options are used. Since output is
933-
// unstable, it will not be present. We have to use opts_present not
927+
// with only stable options if no unstable options are used. Since error-format
928+
// is unstable, it will not be present. We have to use opts_present not
934929
// opt_present because the latter will panic.
935-
let output = if matches.opts_present(&["output".to_owned()]) {
936-
match matches.opt_str("output").as_ref().map(|s| &s[..]) {
937-
Some("tty") => ErrorOutputType::Tty(color),
930+
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
931+
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
932+
Some("human") => ErrorOutputType::HumanReadable(color),
938933
Some("json") => ErrorOutputType::Json,
939934

940935
None => ErrorOutputType::default(),
941936

942937
Some(arg) => {
943-
early_error(ErrorOutputType::default(), &format!("argument for --output must be \
944-
tty or json (instead was `{}`)",
938+
early_error(ErrorOutputType::default(), &format!("argument for --error-format must \
939+
be human or json (instead was \
940+
`{}`)",
945941
arg))
946942
}
947943
}
@@ -951,7 +947,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
951947

952948
let unparsed_crate_types = matches.opt_strs("crate-type");
953949
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
954-
.unwrap_or_else(|e| early_error(output, &e[..]));
950+
.unwrap_or_else(|e| early_error(error_format, &e[..]));
955951

956952
let mut lint_opts = vec!();
957953
let mut describe_lints = false;
@@ -968,11 +964,11 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
968964

969965
let lint_cap = matches.opt_str("cap-lints").map(|cap| {
970966
lint::Level::from_str(&cap).unwrap_or_else(|| {
971-
early_error(output, &format!("unknown lint level: `{}`", cap))
967+
early_error(error_format, &format!("unknown lint level: `{}`", cap))
972968
})
973969
});
974970

975-
let debugging_opts = build_debugging_options(matches, output);
971+
let debugging_opts = build_debugging_options(matches, error_format);
976972

977973
let parse_only = debugging_opts.parse_only;
978974
let no_trans = debugging_opts.no_trans;
@@ -998,7 +994,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
998994
"link" => OutputType::Exe,
999995
"dep-info" => OutputType::DepInfo,
1000996
part => {
1001-
early_error(output, &format!("unknown emission type: `{}`",
997+
early_error(error_format, &format!("unknown emission type: `{}`",
1002998
part))
1003999
}
10041000
};
@@ -1011,7 +1007,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10111007
output_types.insert(OutputType::Exe, None);
10121008
}
10131009

1014-
let mut cg = build_codegen_options(matches, output);
1010+
let mut cg = build_codegen_options(matches, error_format);
10151011

10161012
// Issue #30063: if user requests llvm-related output to one
10171013
// particular path, disable codegen-units.
@@ -1023,11 +1019,11 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10231019
}).collect();
10241020
if !incompatible.is_empty() {
10251021
for ot in &incompatible {
1026-
early_warn(output, &format!("--emit={} with -o incompatible with \
1027-
-C codegen-units=N for N > 1",
1028-
ot.shorthand()));
1022+
early_warn(error_format, &format!("--emit={} with -o incompatible with \
1023+
-C codegen-units=N for N > 1",
1024+
ot.shorthand()));
10291025
}
1030-
early_warn(output, "resetting to default -C codegen-units=1");
1026+
early_warn(error_format, "resetting to default -C codegen-units=1");
10311027
cg.codegen_units = 1;
10321028
}
10331029
}
@@ -1040,7 +1036,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10401036
let opt_level = {
10411037
if matches.opt_present("O") {
10421038
if cg.opt_level.is_some() {
1043-
early_error(output, "-O and -C opt-level both provided");
1039+
early_error(error_format, "-O and -C opt-level both provided");
10441040
}
10451041
OptLevel::Default
10461042
} else {
@@ -1051,9 +1047,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10511047
Some(2) => OptLevel::Default,
10521048
Some(3) => OptLevel::Aggressive,
10531049
Some(arg) => {
1054-
early_error(output, &format!("optimization level needs to be \
1055-
between 0-3 (instead was `{}`)",
1056-
arg));
1050+
early_error(error_format, &format!("optimization level needs to be \
1051+
between 0-3 (instead was `{}`)",
1052+
arg));
10571053
}
10581054
}
10591055
}
@@ -1062,7 +1058,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10621058
let gc = debugging_opts.gc;
10631059
let debuginfo = if matches.opt_present("g") {
10641060
if cg.debuginfo.is_some() {
1065-
early_error(output, "-g and -C debuginfo both provided");
1061+
early_error(error_format, "-g and -C debuginfo both provided");
10661062
}
10671063
FullDebugInfo
10681064
} else {
@@ -1071,16 +1067,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10711067
Some(1) => LimitedDebugInfo,
10721068
Some(2) => FullDebugInfo,
10731069
Some(arg) => {
1074-
early_error(output, &format!("debug info level needs to be between \
1075-
0-2 (instead was `{}`)",
1076-
arg));
1070+
early_error(error_format, &format!("debug info level needs to be between \
1071+
0-2 (instead was `{}`)",
1072+
arg));
10771073
}
10781074
}
10791075
};
10801076

10811077
let mut search_paths = SearchPaths::new();
10821078
for s in &matches.opt_strs("L") {
1083-
search_paths.add_path(&s[..], output);
1079+
search_paths.add_path(&s[..], error_format);
10841080
}
10851081

10861082
let libs = matches.opt_strs("l").into_iter().map(|s| {
@@ -1092,9 +1088,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10921088
(Some(name), "framework") => (name, cstore::NativeFramework),
10931089
(Some(name), "static") => (name, cstore::NativeStatic),
10941090
(_, s) => {
1095-
early_error(output, &format!("unknown library kind `{}`, expected \
1096-
one of dylib, framework, or static",
1097-
s));
1091+
early_error(error_format, &format!("unknown library kind `{}`, expected \
1092+
one of dylib, framework, or static",
1093+
s));
10981094
}
10991095
};
11001096
(name.to_string(), kind)
@@ -1109,26 +1105,26 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11091105
"file-names" => PrintRequest::FileNames,
11101106
"sysroot" => PrintRequest::Sysroot,
11111107
req => {
1112-
early_error(output, &format!("unknown print request `{}`", req))
1108+
early_error(error_format, &format!("unknown print request `{}`", req))
11131109
}
11141110
}
11151111
}).collect::<Vec<_>>();
11161112

11171113
if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
1118-
early_warn(output, "-C remark will not show source locations without \
1119-
--debuginfo");
1114+
early_warn(error_format, "-C remark will not show source locations without \
1115+
--debuginfo");
11201116
}
11211117

11221118
let mut externs = HashMap::new();
11231119
for arg in &matches.opt_strs("extern") {
11241120
let mut parts = arg.splitn(2, '=');
11251121
let name = match parts.next() {
11261122
Some(s) => s,
1127-
None => early_error(output, "--extern value must not be empty"),
1123+
None => early_error(error_format, "--extern value must not be empty"),
11281124
};
11291125
let location = match parts.next() {
11301126
Some(s) => s,
1131-
None => early_error(output, "--extern value must be of the format `foo=bar`"),
1127+
None => early_error(error_format, "--extern value must be of the format `foo=bar`"),
11321128
};
11331129

11341130
externs.entry(name.to_string()).or_insert(vec![]).push(location.to_string());
@@ -1159,7 +1155,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11591155
debugging_opts: debugging_opts,
11601156
prints: prints,
11611157
cg: cg,
1162-
output: output,
1158+
error_format: error_format,
11631159
externs: externs,
11641160
crate_name: crate_name,
11651161
alt_std_name: None,

src/librustc/session/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ pub fn build_session(sopts: config::Options,
406406
let treat_err_as_bug = sopts.treat_err_as_bug;
407407

408408
let codemap = Rc::new(codemap::CodeMap::new());
409-
let emitter: Box<Emitter> = match sopts.output {
410-
config::ErrorOutputType::Tty(color_config) => {
409+
let emitter: Box<Emitter> = match sopts.error_format {
410+
config::ErrorOutputType::HumanReadable(color_config) => {
411411
Box::new(EmitterWriter::stderr(color_config, Some(registry), codemap.clone()))
412412
}
413413
config::ErrorOutputType::Json => {
@@ -483,7 +483,9 @@ pub fn build_session_(sopts: config::Options,
483483

484484
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
485485
let mut emitter: Box<Emitter> = match output {
486-
config::ErrorOutputType::Tty(color_config) => Box::new(BasicEmitter::stderr(color_config)),
486+
config::ErrorOutputType::HumanReadable(color_config) => {
487+
Box::new(BasicEmitter::stderr(color_config))
488+
}
487489
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
488490
};
489491
emitter.emit(None, msg, None, errors::Level::Fatal);
@@ -492,7 +494,9 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
492494

493495
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
494496
let mut emitter: Box<Emitter> = match output {
495-
config::ErrorOutputType::Tty(color_config) => Box::new(BasicEmitter::stderr(color_config)),
497+
config::ErrorOutputType::HumanReadable(color_config) => {
498+
Box::new(BasicEmitter::stderr(color_config))
499+
}
496500
config::ErrorOutputType::Json => Box::new(JsonEmitter::basic()),
497501
};
498502
emitter.emit(None, msg, None, errors::Level::Warning);

src/librustc_driver/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn run_compiler<'a>(args: &[String], callbacks: &mut CompilerCalls<'a>) {
127127

128128
let descriptions = diagnostics_registry();
129129

130-
do_or_return!(callbacks.early_callback(&matches, &descriptions, sopts.output));
130+
do_or_return!(callbacks.early_callback(&matches, &descriptions, sopts.error_format));
131131

132132
let (odir, ofile) = make_output(&matches);
133133
let (input, input_file_path) = match make_input(&matches.free) {
@@ -340,10 +340,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
340340
if should_stop == Compilation::Stop {
341341
return None;
342342
}
343-
early_error(sopts.output, "no input filename given");
343+
early_error(sopts.error_format, "no input filename given");
344344
}
345345
1 => panic!("make_input should have provided valid inputs"),
346-
_ => early_error(sopts.output, "multiple input filenames provided"),
346+
_ => early_error(sopts.error_format, "multiple input filenames provided"),
347347
}
348348

349349
None

src/test/run-make/json-errors/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
all:
44
cp foo.rs $(TMPDIR)
55
cd $(TMPDIR)
6-
$(RUSTC) -Z unstable-options --output=json foo.rs 2>foo.log || true
7-
grep -q '{"message":"unresolved name `y`","code":{"code":"E0425","explanation":"\\nAn unresolved name was used. Example of erroneous codes.*"},"level":"error","span":{"file_name":"foo.rs","byte_start":523,"byte_end":524,"line_start":14,"line_end":14,"column_start":18,"column_end":19},"children":\[\]}' foo.log
6+
-$(RUSTC) -Z unstable-options --error-format=json foo.rs 2>foo.log
7+
grep -q '{"message":"unresolved name `y`","code":{"code":"E0425","explanation":"\\nAn unresolved name was used. Example of erroneous codes.*"},"level":"error","span":{"file_name":"foo.rs","byte_start":496,"byte_end":497,"line_start":12,"line_end":12,"column_start":18,"column_end":19},"children":\[\]}' foo.log
8+
grep -q '{"message":".*","code":{"code":"E0277","explanation":"\\nYou tried.*"},"level":"error","span":{.*},"children":\[{"message":"the .*","code":null,"level":"help","span":{"file_name":"foo.rs","byte_start":504,"byte_end":516,"line_start":14,"line_end":14,"column_start":0,"column_end":0},"children":\[\]},{"message":" <u8 as core::ops::Add>","code":null,"level":"help",' foo.log

src/test/run-make/json-errors/foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-tidy-linelength
12-
1311
fn main() {
1412
let x = 42 + y;
13+
14+
42u8 + 42i32;
1515
}

0 commit comments

Comments
 (0)