diff options
| author | Kamal Marhubi <kamal@marhubi.com> | 2016-02-08 15:53:05 -0500 |
|---|---|---|
| committer | Kamal Marhubi <kamal@marhubi.com> | 2016-02-08 17:15:24 -0500 |
| commit | 4c4bb5ff5c5d660c565d6d79f2204e23b673d39e (patch) | |
| tree | a9012fd1d07fdeabb9d14bb0f07420acffe272c9 /src | |
| parent | 9951ac4be90848bbc12e8187886047ae35795c8d (diff) | |
| download | rust-4c4bb5ff5c5d660c565d6d79f2204e23b673d39e.tar.gz rust-4c4bb5ff5c5d660c565d6d79f2204e23b673d39e.zip | |
driver: Extract handling of --explain to separate function
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_driver/lib.rs | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index fbed5f31725..5b0ee3cf973 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -329,6 +329,25 @@ pub trait CompilerCalls<'a> { #[derive(Copy, Clone)] 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 { + code.to_string() + }; + match descriptions.find_description(&normalised) { + Some(ref description) => { + // Slice off the leading newline and print. + print!("{}", &description[1..]); + } + None => { + early_error(output, &format!("no extended information for {}", code)); + } + } +} + impl<'a> CompilerCalls<'a> for RustcDefaultCalls { fn early_callback(&mut self, matches: &getopts::Matches, @@ -336,28 +355,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { descriptions: &diagnostics::registry::Registry, output: ErrorOutputType) -> Compilation { - match matches.opt_str("explain") { - Some(ref code) => { - let normalised = if !code.starts_with("E") { - format!("E{0:0>4}", code) - } else { - code.to_string() - }; - match descriptions.find_description(&normalised) { - Some(ref description) => { - // Slice off the leading newline and print. - print!("{}", &description[1..]); - } - None => { - early_error(output, &format!("no extended information for {}", code)); - } - } - return Compilation::Stop; - } - None => (), + if let Some(ref code) = matches.opt_str("explain") { + handle_explain(code, descriptions, output); + return Compilation::Stop; } - return Compilation::Continue; + Compilation::Continue } fn no_input(&mut self, |
