]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/lib.rs
Fix rebase fallout.
[rust.git] / src / librustc_driver / lib.rs
index 514c6d0e1dad962bad63390477fef273f80816e7..6557be9f7ecd0845f71a981d32e0ec56da43c69c 100644 (file)
@@ -40,7 +40,7 @@
 use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
 use rustc_metadata::locator;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
-use errors::PResult;
+use errors::{PResult, registry::Registry};
 use rustc_interface::interface;
 use rustc_interface::util::get_codegen_sysroot;
 use rustc_data_structures::sync::SeqCst;
 
 const ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE: &[&str] = &["incremental"];
 
-pub fn source_name(input: &Input) -> FileName {
-    match *input {
-        Input::File(ref ifile) => ifile.clone().into(),
-        Input::Str { ref name, .. } => name.clone(),
-    }
-}
-
 pub fn abort_on_err<T>(result: Result<T, ErrorReported>, sess: &Session) -> T {
     match result {
         Err(..) => {
@@ -140,6 +133,10 @@ fn config(&mut self, config: &mut interface::Config) {
     }
 }
 
+pub fn diagnostics_registry() -> Registry {
+    Registry::new(&rustc_error_codes::DIAGNOSTICS)
+}
+
 // Parse args and run the compiler. This is the primary entry point for rustc.
 // See comments on CompilerCalls below for details about the callbacks argument.
 // The FileLoader provides a way to load files from sources other than the file system.
@@ -182,13 +179,14 @@ pub fn run_compiler(
             lint_caps: Default::default(),
             register_lints: None,
             override_queries: None,
+            registry: diagnostics_registry(),
         };
         callbacks.config(&mut config);
         config
     };
 
     if let Some(ref code) = matches.opt_str("explain") {
-        handle_explain(code, sopts.error_format);
+        handle_explain(diagnostics_registry(), code, sopts.error_format);
         return Ok(());
     }
 
@@ -261,6 +259,7 @@ pub fn run_compiler(
         lint_caps: Default::default(),
         register_lints: None,
         override_queries: None,
+        registry: diagnostics_registry(),
     };
 
     callbacks.config(&mut config);
@@ -510,27 +509,25 @@ fn stdout_isatty() -> bool {
     }
 }
 
-fn handle_explain(code: &str,
-                  output: ErrorOutputType) {
-    let descriptions = rustc_interface::util::diagnostics_registry();
+fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
     let normalised = if code.starts_with("E") {
         code.to_string()
     } else {
         format!("E{0:0>4}", code)
     };
-    match descriptions.find_description(&normalised) {
+    match registry.find_description(&normalised) {
         Some(ref description) => {
             let mut is_in_code_block = false;
             let mut text = String::new();
 
             // Slice off the leading newline and print.
-            for line in description[1..].lines() {
+            for line in description.lines() {
                 let indent_level = line.find(|c: char| !c.is_whitespace())
                     .unwrap_or_else(|| line.len());
                 let dedented_line = &line[indent_level..];
                 if dedented_line.starts_with("```") {
                     is_in_code_block = !is_in_code_block;
-                    text.push_str(&line[..(indent_level+3)]);
+                    text.push_str(&line[..(indent_level + 3)]);
                 } else if is_in_code_block && dedented_line.starts_with("# ") {
                     continue;
                 } else {