Skip to content

Commit 8c1afc7

Browse files
authored
Unrolled build for #152140
Rollup merge of #152140 - bjorn3:driver_fixed_error_codes, r=jdonszelmann Hard code the error code registry for custom drivers And do some cleanups enabled by this.
2 parents cf16cd9 + 639cb69 commit 8c1afc7

File tree

19 files changed

+79
-120
lines changed

19 files changed

+79
-120
lines changed

‎compiler/rustc_codegen_ssa/src/back/write.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,11 +1981,7 @@ impl SharedEmitter {
19811981
}
19821982

19831983
impl Emitter for SharedEmitter {
1984-
fn emit_diagnostic(
1985-
&mut self,
1986-
mut diag: rustc_errors::DiagInner,
1987-
_registry: &rustc_errors::registry::Registry,
1988-
) {
1984+
fn emit_diagnostic(&mut self, mut diag: rustc_errors::DiagInner) {
19891985
// Check that we aren't missing anything interesting when converting to
19901986
// the cut-down local `DiagInner`.
19911987
assert!(!diag.span.has_span_labels());

‎compiler/rustc_driver_impl/src/lib.rs‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_data_structures::profiling::{
3434
};
3535
pub use rustc_errors::catch_fatal_errors;
3636
use rustc_errors::emitter::stderr_destination;
37-
use rustc_errors::registry::Registry;
3837
use rustc_errors::translation::Translator;
3938
use rustc_errors::{ColorConfig, DiagCtxt, ErrCode, PResult, markdown};
4039
use rustc_feature::find_gated_cfg;
@@ -185,10 +184,6 @@ impl Callbacks for TimePassesCallbacks {
185184
}
186185
}
187186

188-
pub fn diagnostics_registry() -> Registry {
189-
Registry::new(rustc_errors::codes::DIAGNOSTICS)
190-
}
191-
192187
/// This is the primary entry point for rustc.
193188
pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
194189
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
@@ -216,7 +211,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
216211
let ice_file = ice_path_with_config(Some(&sopts.unstable_opts)).clone();
217212

218213
if let Some(ref code) = matches.opt_str("explain") {
219-
handle_explain(&default_early_dcx, diagnostics_registry(), code, sopts.color);
214+
handle_explain(&default_early_dcx, code, sopts.color);
220215
return;
221216
}
222217

@@ -243,7 +238,6 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
243238
override_queries: None,
244239
extra_symbols: Vec::new(),
245240
make_codegen_backend: None,
246-
registry: diagnostics_registry(),
247241
using_internal_features: &USING_INTERNAL_FEATURES,
248242
};
249243

@@ -443,12 +437,12 @@ pub enum Compilation {
443437
Continue,
444438
}
445439

446-
fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
440+
fn handle_explain(early_dcx: &EarlyDiagCtxt, code: &str, color: ColorConfig) {
447441
// Allow "E0123" or "0123" form.
448442
let upper_cased_code = code.to_ascii_uppercase();
449443
if let Ok(code) = upper_cased_code.trim_prefix('E').parse::<u32>()
450444
&& code <= ErrCode::MAX_AS_U32
451-
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
445+
&& let Ok(description) = rustc_errors::codes::try_find_description(ErrCode::from_u32(code))
452446
{
453447
let mut is_in_code_block = false;
454448
let mut text = String::new();

‎compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::emitter::{
2727
ConfusionType, Destination, MAX_SUGGESTIONS, OutputTheme, detect_confusion_type, is_different,
2828
normalize_whitespace, should_show_source_code,
2929
};
30-
use crate::registry::Registry;
3130
use crate::translation::{Translator, to_fluent_args};
3231
use crate::{
3332
CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, Level, MultiSpan, Style, Subdiag,
@@ -73,7 +72,7 @@ impl Debug for AnnotateSnippetEmitter {
7372

7473
impl Emitter for AnnotateSnippetEmitter {
7574
/// The entry point for the diagnostics generation
76-
fn emit_diagnostic(&mut self, mut diag: DiagInner, _registry: &Registry) {
75+
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
7776
let fluent_args = to_fluent_args(diag.args.iter());
7877

7978
if self.track_diagnostics && diag.span.has_primary_spans() && !diag.span.is_dummy() {

‎compiler/rustc_errors/src/codes.rs‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//! long description text.
66
77
use std::fmt;
8+
use std::sync::LazyLock;
9+
10+
use rustc_data_structures::fx::FxHashMap;
811

912
rustc_index::newtype_index! {
1013
#[max = 9999] // Because all error codes have four digits.
@@ -27,15 +30,28 @@ macro_rules! define_error_code_constants_and_diagnostics_table {
2730
$(
2831
pub const ${concat(E, $num)}: $crate::ErrCode = $crate::ErrCode::from_u32($num);
2932
)*
30-
pub static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
31-
$( (
32-
${concat(E, $num)},
33-
include_str!(
34-
concat!("../../rustc_error_codes/src/error_codes/E", stringify!($num), ".md")
35-
)
36-
), )*
37-
];
33+
static DIAGNOSTICS: LazyLock<FxHashMap<ErrCode, &'static str>> = LazyLock::new(|| {
34+
[
35+
$( (
36+
${concat(E, $num)},
37+
include_str!(
38+
concat!("../../rustc_error_codes/src/error_codes/E", stringify!($num), ".md")
39+
)
40+
), )*
41+
]
42+
.iter()
43+
.copied()
44+
.collect()
45+
});
3846
)
3947
}
4048

4149
rustc_error_codes::error_codes!(define_error_code_constants_and_diagnostics_table);
50+
51+
#[derive(Debug)]
52+
pub struct InvalidErrorCode;
53+
54+
/// Returns `InvalidErrorCode` if the code requested does not exist.
55+
pub fn try_find_description(code: ErrCode) -> Result<&'static str, InvalidErrorCode> {
56+
DIAGNOSTICS.get(&code).copied().ok_or(InvalidErrorCode)
57+
}

‎compiler/rustc_errors/src/emitter.rs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_span::source_map::SourceMap;
2424
use rustc_span::{FileName, SourceFile, Span};
2525
use tracing::{debug, warn};
2626

27-
use crate::registry::Registry;
2827
use crate::timings::TimingRecord;
2928
use crate::translation::Translator;
3029
use crate::{
@@ -54,7 +53,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
5453
/// Emitter trait for emitting errors and other structured information.
5554
pub trait Emitter {
5655
/// Emit a structured diagnostic.
57-
fn emit_diagnostic(&mut self, diag: DiagInner, registry: &Registry);
56+
fn emit_diagnostic(&mut self, diag: DiagInner);
5857

5958
/// Emit a notification that an artifact has been output.
6059
/// Currently only supported for the JSON format.
@@ -66,7 +65,7 @@ pub trait Emitter {
6665

6766
/// Emit a report about future breakage.
6867
/// Currently only supported for the JSON format.
69-
fn emit_future_breakage_report(&mut self, _diags: Vec<DiagInner>, _registry: &Registry) {}
68+
fn emit_future_breakage_report(&mut self, _diags: Vec<DiagInner>) {}
7069

7170
/// Emit list of unused externs.
7271
/// Currently only supported for the JSON format.
@@ -380,9 +379,9 @@ impl Emitter for EmitterWithNote {
380379
None
381380
}
382381

383-
fn emit_diagnostic(&mut self, mut diag: DiagInner, registry: &Registry) {
382+
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
384383
diag.sub(Level::Note, self.note.clone(), MultiSpan::new());
385-
self.emitter.emit_diagnostic(diag, registry);
384+
self.emitter.emit_diagnostic(diag);
386385
}
387386

388387
fn translator(&self) -> &Translator {
@@ -399,7 +398,7 @@ impl Emitter for SilentEmitter {
399398
None
400399
}
401400

402-
fn emit_diagnostic(&mut self, _diag: DiagInner, _registry: &Registry) {}
401+
fn emit_diagnostic(&mut self, _diag: DiagInner) {}
403402

404403
fn translator(&self) -> &Translator {
405404
&self.translator

‎compiler/rustc_errors/src/json.rs‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::emitter::{
3131
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
3232
should_show_source_code,
3333
};
34-
use crate::registry::Registry;
3534
use crate::timings::{TimingRecord, TimingSection};
3635
use crate::translation::{Translator, to_fluent_args};
3736
use crate::{CodeSuggestion, MultiSpan, SpanLabel, Subdiag, Suggestions, TerminalUrl};
@@ -107,8 +106,8 @@ enum EmitTyped<'a> {
107106
}
108107

109108
impl Emitter for JsonEmitter {
110-
fn emit_diagnostic(&mut self, diag: crate::DiagInner, registry: &Registry) {
111-
let data = Diagnostic::from_errors_diagnostic(diag, self, registry);
109+
fn emit_diagnostic(&mut self, diag: crate::DiagInner) {
110+
let data = Diagnostic::from_errors_diagnostic(diag, self);
112111
let result = self.emit(EmitTyped::Diagnostic(data));
113112
if let Err(e) = result {
114113
panic!("failed to print diagnostics: {e:?}");
@@ -139,7 +138,7 @@ impl Emitter for JsonEmitter {
139138
}
140139
}
141140

142-
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>, registry: &Registry) {
141+
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>) {
143142
let data: Vec<FutureBreakageItem<'_>> = diags
144143
.into_iter()
145144
.map(|mut diag| {
@@ -153,7 +152,7 @@ impl Emitter for JsonEmitter {
153152
}
154153
FutureBreakageItem {
155154
diagnostic: EmitTyped::Diagnostic(Diagnostic::from_errors_diagnostic(
156-
diag, self, registry,
155+
diag, self,
157156
)),
158157
}
159158
})
@@ -307,11 +306,7 @@ struct UnusedExterns<'a> {
307306

308307
impl Diagnostic {
309308
/// Converts from `rustc_errors::DiagInner` to `Diagnostic`.
310-
fn from_errors_diagnostic(
311-
diag: crate::DiagInner,
312-
je: &JsonEmitter,
313-
registry: &Registry,
314-
) -> Diagnostic {
309+
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
315310
let args = to_fluent_args(diag.args.iter());
316311
let sugg_to_diag = |sugg: &CodeSuggestion| {
317312
let translated_message =
@@ -351,7 +346,7 @@ impl Diagnostic {
351346
let code = if let Some(code) = diag.code {
352347
Some(DiagnosticCode {
353348
code: code.to_string(),
354-
explanation: registry.try_find_description(code).ok(),
349+
explanation: crate::codes::try_find_description(code).ok(),
355350
})
356351
} else if let Some(IsLint { name, .. }) = &diag.is_lint {
357352
Some(DiagnosticCode { code: name.to_string(), explanation: None })
@@ -388,7 +383,7 @@ impl Diagnostic {
388383
.ui_testing(je.ui_testing)
389384
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
390385
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
391-
.emit_diagnostic(diag, registry);
386+
.emit_diagnostic(diag);
392387

393388
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
394389
let buf = String::from_utf8(buf).unwrap();

‎compiler/rustc_errors/src/lib.rs‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use rustc_span::{DUMMY_SP, Span};
7171
use tracing::debug;
7272

7373
use crate::emitter::TimingEvent;
74-
use crate::registry::Registry;
7574
use crate::timings::TimingRecord;
7675

7776
pub mod annotate_snippet_emitter_writer;
@@ -84,7 +83,6 @@ pub mod error;
8483
pub mod json;
8584
mod lock;
8685
pub mod markdown;
87-
pub mod registry;
8886
#[cfg(test)]
8987
mod tests;
9088
pub mod timings;
@@ -297,8 +295,6 @@ impl<'a> std::ops::Deref for DiagCtxtHandle<'a> {
297295
struct DiagCtxtInner {
298296
flags: DiagCtxtFlags,
299297

300-
registry: Registry,
301-
302298
/// The error guarantees from all emitted errors. The length gives the error count.
303299
err_guars: Vec<ErrorGuaranteed>,
304300
/// The error guarantee from all emitted lint errors. The length gives the
@@ -480,11 +476,6 @@ impl DiagCtxt {
480476
self
481477
}
482478

483-
pub fn with_registry(mut self, registry: Registry) -> Self {
484-
self.inner.get_mut().registry = registry;
485-
self
486-
}
487-
488479
pub fn new(emitter: Box<DynEmitter>) -> Self {
489480
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
490481
}
@@ -537,7 +528,6 @@ impl DiagCtxt {
537528
let mut inner = self.inner.borrow_mut();
538529
let DiagCtxtInner {
539530
flags: _,
540-
registry: _,
541531
err_guars,
542532
lint_err_guars,
543533
delayed_bugs,
@@ -811,7 +801,7 @@ impl<'a> DiagCtxtHandle<'a> {
811801
.emitted_diagnostic_codes
812802
.iter()
813803
.filter_map(|&code| {
814-
if inner.registry.try_find_description(code).is_ok() {
804+
if crate::codes::try_find_description(code).is_ok() {
815805
Some(code.to_string())
816806
} else {
817807
None
@@ -883,7 +873,7 @@ impl<'a> DiagCtxtHandle<'a> {
883873
let inner = &mut *self.inner.borrow_mut();
884874
let diags = std::mem::take(&mut inner.future_breakage_diagnostics);
885875
if !diags.is_empty() {
886-
inner.emitter.emit_future_breakage_report(diags, &inner.registry);
876+
inner.emitter.emit_future_breakage_report(diags);
887877
}
888878
}
889879

@@ -1184,7 +1174,6 @@ impl DiagCtxtInner {
11841174
fn new(emitter: Box<DynEmitter>) -> Self {
11851175
Self {
11861176
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
1187-
registry: Registry::new(&[]),
11881177
err_guars: Vec::new(),
11891178
lint_err_guars: Vec::new(),
11901179
delayed_bugs: Vec::new(),
@@ -1360,7 +1349,7 @@ impl DiagCtxtInner {
13601349
}
13611350
self.has_printed = true;
13621351

1363-
self.emitter.emit_diagnostic(diagnostic, &self.registry);
1352+
self.emitter.emit_diagnostic(diagnostic);
13641353
}
13651354

13661355
if is_error {

‎compiler/rustc_errors/src/registry.rs‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎compiler/rustc_interface/src/interface.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::CodegenBackend;
77
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_data_structures::jobserver::{self, Proxy};
99
use rustc_data_structures::stable_hasher::StableHasher;
10-
use rustc_errors::registry::Registry;
1110
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
1211
use rustc_lint::LintStore;
1312
use rustc_middle::ty;
@@ -374,9 +373,6 @@ pub struct Config {
374373
pub make_codegen_backend:
375374
Option<Box<dyn FnOnce(&config::Options, &Target) -> Box<dyn CodegenBackend> + Send>>,
376375

377-
/// Registry of diagnostics codes.
378-
pub registry: Registry,
379-
380376
/// The inner atomic value is set to true when a feature marked as `internal` is
381377
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
382378
/// 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
464460
temps_dir,
465461
},
466462
bundle,
467-
config.registry,
468463
config.locale_resources,
469464
config.lint_caps,
470465
target,

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::sync::atomic::AtomicBool;
66

77
use rustc_abi::Align;
88
use rustc_data_structures::profiling::TimePassesFormat;
9+
use rustc_errors::ColorConfig;
910
use rustc_errors::emitter::HumanReadableErrorType;
10-
use rustc_errors::{ColorConfig, registry};
1111
use rustc_hir::attrs::{CollapseMacroDebuginfo, NativeLibKind};
1212
use rustc_session::config::{
1313
AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CoverageLevel, CoverageOptions,
@@ -72,7 +72,6 @@ where
7272
sessopts,
7373
io,
7474
None,
75-
registry::Registry::new(&[]),
7675
vec![],
7776
Default::default(),
7877
target,

0 commit comments

Comments
 (0)