Rollup merge of #66456 - Centril:driver-codes, r=Mark-Simulacrum
Move `DIAGNOSTICS` usage to `rustc_driver` Remove `rustc_interface`'s dependency on `rustc_error_codes` and centralize all usages of `DIAGNOSTICS` in `rustc_driver`. Once we remove all references to `rustc_error_codes` in all other crates but `rustc_driver`, this should allow for incremental recompilation of the compiler to be smoother when tweaking error codes. This works towards https://github.com/rust-lang/rust/issues/66210#issuecomment-551862528. (May include traces of minor drive-by cleanup.) r? @Mark-Simulacrum
This commit is contained in:
@@ -3522,6 +3522,7 @@ dependencies = [
|
|||||||
"rustc",
|
"rustc",
|
||||||
"rustc_codegen_utils",
|
"rustc_codegen_utils",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
"rustc_error_codes",
|
||||||
"rustc_errors",
|
"rustc_errors",
|
||||||
"rustc_interface",
|
"rustc_interface",
|
||||||
"rustc_lint",
|
"rustc_lint",
|
||||||
@@ -3595,7 +3596,6 @@ dependencies = [
|
|||||||
"rustc_codegen_ssa",
|
"rustc_codegen_ssa",
|
||||||
"rustc_codegen_utils",
|
"rustc_codegen_utils",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_error_codes",
|
|
||||||
"rustc_errors",
|
"rustc_errors",
|
||||||
"rustc_incremental",
|
"rustc_incremental",
|
||||||
"rustc_lint",
|
"rustc_lint",
|
||||||
|
|||||||
@@ -1037,12 +1037,11 @@ pub fn build_session_with_source_map(
|
|||||||
|
|
||||||
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
|
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
|
||||||
|
|
||||||
let emitter = match diagnostics_output {
|
let write_dest = match diagnostics_output {
|
||||||
DiagnosticOutput::Default => default_emitter(&sopts, registry, &source_map, None),
|
DiagnosticOutput::Default => None,
|
||||||
DiagnosticOutput::Raw(write) => {
|
DiagnosticOutput::Raw(write) => Some(write),
|
||||||
default_emitter(&sopts, registry, &source_map, Some(write))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
let emitter = default_emitter(&sopts, registry, &source_map, write_dest);
|
||||||
|
|
||||||
let diagnostic_handler = errors::Handler::with_emitter_and_flags(
|
let diagnostic_handler = errors::Handler::with_emitter_and_flags(
|
||||||
emitter,
|
emitter,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ rustc_plugin = { path = "../librustc_plugin/deprecated" } # To get this in the s
|
|||||||
rustc_plugin_impl = { path = "../librustc_plugin" }
|
rustc_plugin_impl = { path = "../librustc_plugin" }
|
||||||
rustc_save_analysis = { path = "../librustc_save_analysis" }
|
rustc_save_analysis = { path = "../librustc_save_analysis" }
|
||||||
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
|
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
|
||||||
|
rustc_error_codes = { path = "../librustc_error_codes" }
|
||||||
rustc_interface = { path = "../librustc_interface" }
|
rustc_interface = { path = "../librustc_interface" }
|
||||||
rustc_serialize = { path = "../libserialize", package = "serialize" }
|
rustc_serialize = { path = "../libserialize", package = "serialize" }
|
||||||
rustc_resolve = { path = "../librustc_resolve" }
|
rustc_resolve = { path = "../librustc_resolve" }
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ use rustc::ty::TyCtxt;
|
|||||||
use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
|
use rustc::util::common::{set_time_depth, time, print_time_passes_entry, ErrorReported};
|
||||||
use rustc_metadata::locator;
|
use rustc_metadata::locator;
|
||||||
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
||||||
use errors::PResult;
|
use errors::{PResult, registry::Registry};
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
use rustc_interface::util::get_codegen_sysroot;
|
use rustc_interface::util::get_codegen_sysroot;
|
||||||
use rustc_data_structures::sync::SeqCst;
|
use rustc_data_structures::sync::SeqCst;
|
||||||
@@ -140,6 +140,10 @@ impl Callbacks for TimePassesCallbacks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
// 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.
|
// 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.
|
// The FileLoader provides a way to load files from sources other than the file system.
|
||||||
@@ -182,13 +186,14 @@ pub fn run_compiler(
|
|||||||
lint_caps: Default::default(),
|
lint_caps: Default::default(),
|
||||||
register_lints: None,
|
register_lints: None,
|
||||||
override_queries: None,
|
override_queries: None,
|
||||||
|
registry: diagnostics_registry(),
|
||||||
};
|
};
|
||||||
callbacks.config(&mut config);
|
callbacks.config(&mut config);
|
||||||
config
|
config
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref code) = matches.opt_str("explain") {
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +266,7 @@ pub fn run_compiler(
|
|||||||
lint_caps: Default::default(),
|
lint_caps: Default::default(),
|
||||||
register_lints: None,
|
register_lints: None,
|
||||||
override_queries: None,
|
override_queries: None,
|
||||||
|
registry: diagnostics_registry(),
|
||||||
};
|
};
|
||||||
|
|
||||||
callbacks.config(&mut config);
|
callbacks.config(&mut config);
|
||||||
@@ -510,15 +516,13 @@ fn stdout_isatty() -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_explain(code: &str,
|
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
|
||||||
output: ErrorOutputType) {
|
|
||||||
let descriptions = rustc_interface::util::diagnostics_registry();
|
|
||||||
let normalised = if code.starts_with("E") {
|
let normalised = if code.starts_with("E") {
|
||||||
code.to_string()
|
code.to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("E{0:0>4}", code)
|
format!("E{0:0>4}", code)
|
||||||
};
|
};
|
||||||
match descriptions.find_description(&normalised) {
|
match registry.find_description(&normalised) {
|
||||||
Some(ref description) => {
|
Some(ref description) => {
|
||||||
let mut is_in_code_block = false;
|
let mut is_in_code_block = false;
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
// Error messages' format must follow the RFC 1567 available here:
|
// Error messages' format must follow the RFC 1567 available here:
|
||||||
// https://github.com/rust-lang/rfcs/pull/1567
|
// https://github.com/rust-lang/rfcs/pull/1567
|
||||||
|
|
||||||
crate::register_diagnostics! {
|
register_diagnostics! {
|
||||||
|
|
||||||
E0001: include_str!("./error_codes/E0001.md"),
|
E0001: include_str!("./error_codes/E0001.md"),
|
||||||
E0002: include_str!("./error_codes/E0002.md"),
|
E0002: include_str!("./error_codes/E0002.md"),
|
||||||
E0004: include_str!("./error_codes/E0004.md"),
|
E0004: include_str!("./error_codes/E0004.md"),
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
//! This library is used to gather all error codes into one place. The goal
|
//! This library is used to gather all error codes into one place,
|
||||||
//! being to make their maintenance easier.
|
//! the goal being to make their maintenance easier.
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! register_diagnostics {
|
macro_rules! register_diagnostics {
|
||||||
($($ecode:ident: $message:expr,)*) => (
|
|
||||||
$crate::register_diagnostics!{$($ecode:$message,)* ;}
|
|
||||||
);
|
|
||||||
|
|
||||||
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
|
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
|
||||||
pub static DIAGNOSTICS: &[(&str, &str)] = &[
|
pub static DIAGNOSTICS: &[(&str, &str)] = &[
|
||||||
$( (stringify!($ecode), $message), )*
|
$( (stringify!($ecode), $message), )*
|
||||||
];
|
];
|
||||||
|
|
||||||
$(
|
$(
|
||||||
pub const $ecode: &str = $message;
|
pub const $ecode: () = ();
|
||||||
)*
|
)*
|
||||||
$(
|
$(
|
||||||
pub const $code: () = ();
|
pub const $code: () = ();
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ rustc_errors = { path = "../librustc_errors" }
|
|||||||
rustc_plugin = { path = "../librustc_plugin", package = "rustc_plugin_impl" }
|
rustc_plugin = { path = "../librustc_plugin", package = "rustc_plugin_impl" }
|
||||||
rustc_privacy = { path = "../librustc_privacy" }
|
rustc_privacy = { path = "../librustc_privacy" }
|
||||||
rustc_resolve = { path = "../librustc_resolve" }
|
rustc_resolve = { path = "../librustc_resolve" }
|
||||||
rustc_error_codes = { path = "../librustc_error_codes" }
|
|
||||||
tempfile = "3.0.5"
|
tempfile = "3.0.5"
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
|||||||
use rustc_data_structures::OnDrop;
|
use rustc_data_structures::OnDrop;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
||||||
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_parse::new_parser_from_source_str;
|
use rustc_parse::new_parser_from_source_str;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -141,12 +142,16 @@ pub struct Config {
|
|||||||
/// The second parameter is local providers and the third parameter is external providers.
|
/// The second parameter is local providers and the third parameter is external providers.
|
||||||
pub override_queries:
|
pub override_queries:
|
||||||
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
|
Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>,
|
||||||
|
|
||||||
|
/// Registry of diagnostics codes.
|
||||||
|
pub registry: Registry,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_compiler_in_existing_thread_pool<F, R>(config: Config, f: F) -> R
|
pub fn run_compiler_in_existing_thread_pool<R>(
|
||||||
where
|
config: Config,
|
||||||
F: FnOnce(&Compiler) -> R,
|
f: impl FnOnce(&Compiler) -> R,
|
||||||
{
|
) -> R {
|
||||||
|
let registry = &config.registry;
|
||||||
let (sess, codegen_backend, source_map) = util::create_session(
|
let (sess, codegen_backend, source_map) = util::create_session(
|
||||||
config.opts,
|
config.opts,
|
||||||
config.crate_cfg,
|
config.crate_cfg,
|
||||||
@@ -154,6 +159,7 @@ where
|
|||||||
config.file_loader,
|
config.file_loader,
|
||||||
config.input_path.clone(),
|
config.input_path.clone(),
|
||||||
config.lint_caps,
|
config.lint_caps,
|
||||||
|
registry.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let compiler = Compiler {
|
let compiler = Compiler {
|
||||||
@@ -171,17 +177,13 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let _sess_abort_error = OnDrop(|| {
|
let _sess_abort_error = OnDrop(|| {
|
||||||
compiler.sess.diagnostic().print_error_count(&util::diagnostics_registry());
|
compiler.sess.diagnostic().print_error_count(registry);
|
||||||
});
|
});
|
||||||
|
|
||||||
f(&compiler)
|
f(&compiler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_compiler<F, R>(mut config: Config, f: F) -> R
|
pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
|
||||||
where
|
|
||||||
F: FnOnce(&Compiler) -> R + Send,
|
|
||||||
R: Send,
|
|
||||||
{
|
|
||||||
let stderr = config.stderr.take();
|
let stderr = config.stderr.take();
|
||||||
util::spawn_thread_pool(
|
util::spawn_thread_pool(
|
||||||
config.opts.edition,
|
config.opts.edition,
|
||||||
@@ -191,11 +193,7 @@ where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_thread_pool<F, R>(edition: edition::Edition, f: F) -> R
|
pub fn default_thread_pool<R: Send>(edition: edition::Edition, f: impl FnOnce() -> R + Send) -> R {
|
||||||
where
|
|
||||||
F: FnOnce() -> R + Send,
|
|
||||||
R: Send,
|
|
||||||
{
|
|
||||||
// the 1 here is duplicating code in config.opts.debugging_opts.threads
|
// the 1 here is duplicating code in config.opts.debugging_opts.threads
|
||||||
// which also defaults to 1; it ultimately doesn't matter as the default
|
// which also defaults to 1; it ultimately doesn't matter as the default
|
||||||
// isn't threaded, and just ignores this parameter
|
// isn't threaded, and just ignores this parameter
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
|||||||
use rustc_errors::registry::Registry;
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_metadata::dynamic_lib::DynamicLibrary;
|
use rustc_metadata::dynamic_lib::DynamicLibrary;
|
||||||
use rustc_resolve::{self, Resolver};
|
use rustc_resolve::{self, Resolver};
|
||||||
use rustc_error_codes;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
|
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
@@ -37,15 +36,6 @@ use syntax_pos::edition::Edition;
|
|||||||
#[cfg(not(parallel_compiler))]
|
#[cfg(not(parallel_compiler))]
|
||||||
use std::{thread, panic};
|
use std::{thread, panic};
|
||||||
|
|
||||||
pub fn diagnostics_registry() -> Registry {
|
|
||||||
let mut all_errors = Vec::new();
|
|
||||||
all_errors.extend_from_slice(&rustc_error_codes::DIAGNOSTICS);
|
|
||||||
// FIXME: need to figure out a way to get these back in here
|
|
||||||
// all_errors.extend_from_slice(get_codegen_backend(sess).diagnostics());
|
|
||||||
|
|
||||||
Registry::new(&all_errors)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds `target_feature = "..."` cfgs for a variety of platform
|
/// Adds `target_feature = "..."` cfgs for a variety of platform
|
||||||
/// specific features (SSE, NEON etc.).
|
/// specific features (SSE, NEON etc.).
|
||||||
///
|
///
|
||||||
@@ -77,9 +67,8 @@ pub fn create_session(
|
|||||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||||
input_path: Option<PathBuf>,
|
input_path: Option<PathBuf>,
|
||||||
lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
lint_caps: FxHashMap<lint::LintId, lint::Level>,
|
||||||
|
descriptions: Registry,
|
||||||
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>, Lrc<SourceMap>) {
|
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>, Lrc<SourceMap>) {
|
||||||
let descriptions = diagnostics_registry();
|
|
||||||
|
|
||||||
let loader = file_loader.unwrap_or(box RealFileLoader);
|
let loader = file_loader.unwrap_or(box RealFileLoader);
|
||||||
let source_map = Lrc::new(SourceMap::with_file_loader(
|
let source_map = Lrc::new(SourceMap::with_file_loader(
|
||||||
loader,
|
loader,
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use syntax::feature_gate::UnstableFeatures;
|
|||||||
use errors::json::JsonEmitter;
|
use errors::json::JsonEmitter;
|
||||||
use syntax::symbol::sym;
|
use syntax::symbol::sym;
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
use errors;
|
|
||||||
use errors::emitter::{Emitter, EmitterWriter};
|
use errors::emitter::{Emitter, EmitterWriter};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@@ -341,6 +340,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
|||||||
lint_caps,
|
lint_caps,
|
||||||
register_lints: None,
|
register_lints: None,
|
||||||
override_queries: None,
|
override_queries: None,
|
||||||
|
registry: rustc_driver::diagnostics_registry(),
|
||||||
};
|
};
|
||||||
|
|
||||||
interface::run_compiler_in_existing_thread_pool(config, |compiler| {
|
interface::run_compiler_in_existing_thread_pool(config, |compiler| {
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ extern crate getopts;
|
|||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
extern crate rustc_data_structures;
|
extern crate rustc_data_structures;
|
||||||
extern crate rustc_index;
|
|
||||||
extern crate rustc_driver;
|
extern crate rustc_driver;
|
||||||
|
extern crate rustc_error_codes;
|
||||||
|
extern crate rustc_index;
|
||||||
extern crate rustc_resolve;
|
extern crate rustc_resolve;
|
||||||
extern crate rustc_lint;
|
extern crate rustc_lint;
|
||||||
extern crate rustc_interface;
|
extern crate rustc_interface;
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ pub fn run(options: Options) -> i32 {
|
|||||||
lint_caps: Default::default(),
|
lint_caps: Default::default(),
|
||||||
register_lints: None,
|
register_lints: None,
|
||||||
override_queries: None,
|
override_queries: None,
|
||||||
|
registry: rustc_driver::diagnostics_registry(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut test_args = options.test_args.clone();
|
let mut test_args = options.test_args.clone();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
extern crate rustc_interface;
|
extern crate rustc_interface;
|
||||||
extern crate rustc_driver as _;
|
extern crate rustc_driver;
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
use rustc::session::DiagnosticOutput;
|
use rustc::session::DiagnosticOutput;
|
||||||
@@ -61,6 +61,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
|||||||
lint_caps: Default::default(),
|
lint_caps: Default::default(),
|
||||||
register_lints: None,
|
register_lints: None,
|
||||||
override_queries: None,
|
override_queries: None,
|
||||||
|
registry: rustc_driver::diagnostics_registry(),
|
||||||
};
|
};
|
||||||
|
|
||||||
interface::run_compiler(config, |compiler| {
|
interface::run_compiler(config, |compiler| {
|
||||||
|
|||||||
Reference in New Issue
Block a user