diff options
| author | bors <bors@rust-lang.org> | 2016-03-21 03:27:53 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-21 03:27:53 -0700 |
| commit | 690f160f8f64df041133bcba58416435826d3e73 (patch) | |
| tree | 1ee4bc0adbe44229248741031df2017ce8e0fb74 | |
| parent | 7ec8f5c3699bf16c452cff6abaeda26abaeef02c (diff) | |
| parent | 4d52b0f5507f9c1f86035fa1bbee2b53dcaa08b6 (diff) | |
Auto merge of #32369 - frewsxcv:librustc-driver-lib, r=alexcrichton
Minor cleanup for 'src/librustc_driver/lib.rs' Reading through this file my first time. Cleaned up some stuff on the way.
| -rw-r--r-- | src/librustc_driver/lib.rs | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 357c7238c1f..0fb192bb4db 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), }; @@ -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) => { @@ -870,9 +870,9 @@ fn print_flag_list<T>(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<String>) -> Option<getopts::Matches> { +pub fn handle_options(args: &[String]) -> Option<getopts::Matches> { // 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 @@ -916,10 +916,10 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> { 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 @@ -1033,43 +1033,38 @@ pub fn monitor<F: FnOnce() + Send + 'static>(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::<errors::FatalError>() { - 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::<errors::ExplicitBug>() { - emitter.emit(None, "unexpected panic", None, errors::Level::Bug); - } + let thread = cfg.spawn(move || { + io::set_panic(box err); + f() + }); - 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); - } + if let Err(value) = thread.unwrap().join() { + // Thread panicked without emitting a fatal diagnostic + if !value.is::<errors::FatalError>() { + let mut emitter = errors::emitter::BasicEmitter::stderr(errors::ColorConfig::Auto); - println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); + // a .span_bug or .bug call has already printed what + // it wants to print. + if !value.is::<errors::ExplicitBug>() { + emitter.emit(None, "unexpected panic", None, errors::Level::Bug); } - exit_on_err(); + 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); + } + + println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); } + + exit_on_err(); } } |
