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(..) => {
}
}
+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.
crate_name: None,
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(());
}
crate_name: None,
lint_caps: Default::default(),
register_lints: None,
+ override_queries: None,
+ registry: diagnostics_registry(),
};
callbacks.config(&mut config);
}
}
-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 {