]> git.lizzy.rs Git - rust.git/commitdiff
driver: Extract handling of --explain to separate function
authorKamal Marhubi <kamal@marhubi.com>
Mon, 8 Feb 2016 20:53:05 +0000 (15:53 -0500)
committerKamal Marhubi <kamal@marhubi.com>
Mon, 8 Feb 2016 22:15:24 +0000 (17:15 -0500)
src/librustc_driver/lib.rs

index fbed5f31725ee157aa3556a1c382b5adcd29448b..5b0ee3cf973b07219886555aa6bcb4ceaec627bf 100644 (file)
@@ -329,6 +329,25 @@ fn parse_pretty(&mut self,
 #[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 @@ fn early_callback(&mut self,
                       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,