From 4238d0b639d4ead97d9cf4ffbb049c0573239cac Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 19 Mar 2016 23:37:13 -0400 Subject: [PATCH 1/3] Replace unneeded owned `Vec` usage with `slice`. --- src/librustc_driver/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 357c7238c1f6c..d4f164b6e24be 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -157,7 +157,7 @@ pub fn run_compiler<'a>(args: &[String], } }} - let matches = match handle_options(args.to_vec()) { + let matches = match handle_options(args) { Some(matches) => matches, None => return (Ok(()), None), }; @@ -870,9 +870,9 @@ fn print_flag_list(cmdline_opt: &str, /// /// So with all that in mind, the comments below have some more detail about the /// contortions done here to get things to work out correctly. -pub fn handle_options(mut args: Vec) -> Option { +pub fn handle_options(args: &[String]) -> Option { // Throw away the first argument, the name of the binary - let _binary = args.remove(0); + let args = &args[1..]; if args.is_empty() { // user did not write `-v` nor `-Z unstable-options`, so do not From 77eb78a8c583e17f0cf98a433eb42aa0fc63ce4f Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 20 Mar 2016 00:35:46 -0400 Subject: [PATCH 2/3] Remove double-negative conditionals. --- src/librustc_driver/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index d4f164b6e24be..dc048807bcce3 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -335,10 +335,10 @@ pub struct RustcDefaultCalls; fn handle_explain(code: &str, descriptions: &diagnostics::registry::Registry, output: ErrorOutputType) { - let normalised = if !code.starts_with("E") { - format!("E{0:0>4}", code) - } else { + let normalised = if code.starts_with("E") { code.to_string() + } else { + format!("E{0:0>4}", code) }; match descriptions.find_description(&normalised) { Some(ref description) => { @@ -916,10 +916,10 @@ pub fn handle_options(args: &[String]) -> Option { if opt.stability == OptionStability::Stable { continue } - let opt_name = if !opt.opt_group.long_name.is_empty() { - &opt.opt_group.long_name - } else { + let opt_name = if opt.opt_group.long_name.is_empty() { &opt.opt_group.short_name + } else { + &opt.opt_group.long_name }; if !matches.opt_present(opt_name) { continue From 4d52b0f5507f9c1f86035fa1bbee2b53dcaa08b6 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 20 Mar 2016 00:46:50 -0400 Subject: [PATCH 3/3] Utilize `if..let` over single `match` branch. --- src/librustc_driver/lib.rs | 61 +++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index dc048807bcce3..0fb192bb4db21 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1033,43 +1033,38 @@ pub fn monitor(f: F) { cfg = cfg.stack_size(STACK_SIZE); } - match cfg.spawn(move || { - io::set_panic(box err); - f() - }) - .unwrap() - .join() { - Ok(()) => { - // fallthrough - } - Err(value) => { - // Thread panicked without emitting a fatal diagnostic - if !value.is::() { - let mut emitter = errors::emitter::BasicEmitter::stderr(errors::ColorConfig::Auto); - - // a .span_bug or .bug call has already printed what - // it wants to print. - if !value.is::() { - emitter.emit(None, "unexpected panic", None, errors::Level::Bug); - } - - let xs = ["the compiler unexpectedly panicked. this is a bug.".to_string(), - format!("we would appreciate a bug report: {}", BUG_REPORT_URL)]; - for note in &xs { - emitter.emit(None, ¬e[..], None, errors::Level::Note) - } - if let None = env::var_os("RUST_BACKTRACE") { - emitter.emit(None, - "run with `RUST_BACKTRACE=1` for a backtrace", - None, - errors::Level::Note); - } + let thread = cfg.spawn(move || { + io::set_panic(box err); + f() + }); + + if let Err(value) = thread.unwrap().join() { + // Thread panicked without emitting a fatal diagnostic + if !value.is::() { + let mut emitter = errors::emitter::BasicEmitter::stderr(errors::ColorConfig::Auto); + + // a .span_bug or .bug call has already printed what + // it wants to print. + if !value.is::() { + emitter.emit(None, "unexpected panic", None, errors::Level::Bug); + } - println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); + let xs = ["the compiler unexpectedly panicked. this is a bug.".to_string(), + format!("we would appreciate a bug report: {}", BUG_REPORT_URL)]; + for note in &xs { + emitter.emit(None, ¬e[..], None, errors::Level::Note) + } + if let None = env::var_os("RUST_BACKTRACE") { + emitter.emit(None, + "run with `RUST_BACKTRACE=1` for a backtrace", + None, + errors::Level::Note); } - exit_on_err(); + println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); } + + exit_on_err(); } }