Hard code the error code registry for custom drivers

This commit is contained in:
bjorn3 2026-02-04 12:59:06 +00:00
parent 8bccf1224d
commit 1851937577
13 changed files with 16 additions and 40 deletions

View file

@ -197,10 +197,6 @@ impl Callbacks for TimePassesCallbacks {
}
}
pub fn diagnostics_registry() -> Registry {
Registry::new(rustc_errors::codes::DIAGNOSTICS)
}
/// This is the primary entry point for rustc.
pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
@ -228,7 +224,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
let ice_file = ice_path_with_config(Some(&sopts.unstable_opts)).clone();
if let Some(ref code) = matches.opt_str("explain") {
handle_explain(&default_early_dcx, diagnostics_registry(), code, sopts.color);
handle_explain(&default_early_dcx, code, sopts.color);
return;
}
@ -255,7 +251,6 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
override_queries: None,
extra_symbols: Vec::new(),
make_codegen_backend: None,
registry: diagnostics_registry(),
using_internal_features: &USING_INTERNAL_FEATURES,
};
@ -455,7 +450,9 @@ pub enum Compilation {
Continue,
}
fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
fn handle_explain(early_dcx: &EarlyDiagCtxt, code: &str, color: ColorConfig) {
let registry = Registry::new();
// Allow "E0123" or "0123" form.
let upper_cased_code = code.to_ascii_uppercase();
if let Ok(code) = upper_cased_code.trim_prefix('E').parse::<u32>()

View file

@ -27,7 +27,7 @@ macro_rules! define_error_code_constants_and_diagnostics_table {
$(
pub const ${concat(E, $num)}: $crate::ErrCode = $crate::ErrCode::from_u32($num);
)*
pub static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
pub(crate) static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
$( (
${concat(E, $num)},
include_str!(

View file

@ -482,11 +482,6 @@ impl DiagCtxt {
self
}
pub fn with_registry(mut self, registry: Registry) -> Self {
self.inner.get_mut().registry = registry;
self
}
pub fn new(emitter: Box<DynEmitter>) -> Self {
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
}
@ -1186,7 +1181,7 @@ impl DiagCtxtInner {
fn new(emitter: Box<DynEmitter>) -> Self {
Self {
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
registry: Registry::new(&[]),
registry: Registry::new(),
err_guars: Vec::new(),
lint_err_guars: Vec::new(),
delayed_bugs: Vec::new(),

View file

@ -11,8 +11,8 @@ pub struct Registry {
}
impl Registry {
pub fn new(long_descriptions: &[(ErrCode, &'static str)]) -> Registry {
Registry { long_descriptions: long_descriptions.iter().copied().collect() }
pub fn new() -> Registry {
Registry { long_descriptions: crate::codes::DIAGNOSTICS.iter().copied().collect() }
}
/// Returns `InvalidErrorCode` if the code requested does not exist in the

View file

@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::jobserver::{self, Proxy};
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_errors::registry::Registry;
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
use rustc_lint::LintStore;
use rustc_middle::ty;
@ -374,9 +373,6 @@ pub struct Config {
pub make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options, &Target) -> Box<dyn CodegenBackend> + Send>>,
/// Registry of diagnostics codes.
pub registry: Registry,
/// The inner atomic value is set to true when a feature marked as `internal` is
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
/// internal features are wontfix, and they are usually the cause of the ICEs.
@ -464,7 +460,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
temps_dir,
},
bundle,
config.registry,
config.locale_resources,
config.lint_caps,
target,

View file

@ -6,8 +6,8 @@ use std::sync::atomic::AtomicBool;
use rustc_abi::Align;
use rustc_data_structures::profiling::TimePassesFormat;
use rustc_errors::ColorConfig;
use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, registry};
use rustc_hir::attrs::{CollapseMacroDebuginfo, NativeLibKind};
use rustc_session::config::{
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CoverageLevel, CoverageOptions,
@ -72,7 +72,6 @@ where
sessopts,
io,
None,
registry::Registry::new(&[]),
vec![],
Default::default(),
target,

View file

@ -963,7 +963,6 @@ pub fn build_session(
sopts: config::Options,
io: CompilerIO,
fluent_bundle: Option<Arc<rustc_errors::FluentBundle>>,
registry: rustc_errors::registry::Registry,
fluent_resources: Vec<&'static str>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
target: Target,
@ -992,9 +991,8 @@ pub fn build_session(
let source_map = rustc_span::source_map::get_source_map().unwrap();
let emitter = default_emitter(&sopts, Arc::clone(&source_map), translator);
let mut dcx = DiagCtxt::new(emitter)
.with_flags(sopts.unstable_opts.dcx_flags(can_emit_warnings))
.with_registry(registry);
let mut dcx =
DiagCtxt::new(emitter).with_flags(sopts.unstable_opts.dcx_flags(can_emit_warnings));
if let Some(ice_file) = ice_file {
dcx = dcx.with_ice_file(ice_file);
}

View file

@ -4,14 +4,12 @@
extern crate rustc_driver;
extern crate rustc_error_codes;
extern crate rustc_errors;
extern crate rustc_hash;
extern crate rustc_hir;
extern crate rustc_interface;
extern crate rustc_session;
extern crate rustc_span;
use rustc_errors::registry;
use rustc_hash::FxHashMap;
use rustc_session::config;
@ -50,8 +48,6 @@ fn main() {
//
// The second parameter is local providers and the third parameter is external providers.
override_queries: None, // Option<fn(&Session, &mut ty::query::Providers<'_>, &mut ty::query::Providers<'_>)>
// Registry of diagnostics codes.
registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS),
make_codegen_backend: None,
expanded_args: Vec::new(),
ice_file: None,

View file

@ -15,7 +15,7 @@ extern crate rustc_span;
use std::sync::{Arc, Mutex};
use rustc_errors::emitter::Emitter;
use rustc_errors::registry::{self, Registry};
use rustc_errors::registry::Registry;
use rustc_errors::translation::Translate;
use rustc_errors::{DiagInner, FluentBundle};
use rustc_session::config;
@ -76,7 +76,6 @@ fn main() {
})),
register_lints: None,
override_queries: None,
registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS),
make_codegen_backend: None,
expanded_args: Vec::new(),
ice_file: None,

View file

@ -322,7 +322,6 @@ pub(crate) fn create_config(
}),
extra_symbols: Vec::new(),
make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(),
ice_file: None,
using_internal_features: &USING_INTERNAL_FEATURES,
}

View file

@ -196,7 +196,6 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
override_queries: None,
extra_symbols: Vec::new(),
make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(),
ice_file: None,
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};

View file

@ -401,7 +401,7 @@ mod tests {
let source =
String::from(r#"extern "system" fn jni_symbol!( funcName ) ( ... ) -> {} "#);
source_map.new_source_file(filename(&source_map, "foo.rs"), source);
let registry = Registry::new(&[]);
let registry = Registry::new();
let mut emitter = build_emitter(
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
@ -424,7 +424,7 @@ mod tests {
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let source = String::from(r#"pub fn bar() { 1x; }"#);
source_map.new_source_file(filename(&source_map, "foo.rs"), source);
let registry = Registry::new(&[]);
let registry = Registry::new();
let mut emitter = build_emitter(
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
@ -446,7 +446,7 @@ mod tests {
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let source = String::from(r#"pub fn bar() { 1x; }"#);
source_map.new_source_file(filename(&source_map, "foo.rs"), source);
let registry = Registry::new(&[]);
let registry = Registry::new();
let mut emitter = build_emitter(
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),
@ -474,7 +474,7 @@ mod tests {
source_map.new_source_file(filename(&source_map, "bar.rs"), bar_source);
source_map.new_source_file(filename(&source_map, "foo.rs"), foo_source);
source_map.new_source_file(filename(&source_map, "fatal.rs"), fatal_source);
let registry = Registry::new(&[]);
let registry = Registry::new();
let mut emitter = build_emitter(
Arc::clone(&num_emitted_errors),
Arc::clone(&can_reset_errors),

View file

@ -72,7 +72,6 @@ fn compile(code: String, output: PathBuf, sysroot: Sysroot, linker: Option<&Path
override_queries: None,
extra_symbols: Vec::new(),
make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(),
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};