Skip to content

Commit f422dca

Browse files
committed
Rename many DiagCtxt arguments.
1 parent 4dc7fab commit f422dca

File tree

44 files changed

+317
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+317
-353
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl<'a> AstValidator<'a> {
696696
/// Checks that generic parameters are in the correct order,
697697
/// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
698698
fn validate_generic_param_order(
699-
handler: &rustc_errors::DiagCtxt,
699+
dcx: &rustc_errors::DiagCtxt,
700700
generics: &[GenericParam],
701701
span: Span,
702702
) {
@@ -759,7 +759,7 @@ fn validate_generic_param_order(
759759
ordered_params += ">";
760760

761761
for (param_ord, (max_param, spans)) in &out_of_order {
762-
handler.emit_err(errors::OutOfOrderParams {
762+
dcx.emit_err(errors::OutOfOrderParams {
763763
spans: spans.clone(),
764764
sugg_span: span,
765765
param_ord,

compiler/rustc_attr/src/session_diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> {
5151

5252
// Manual implementation to be able to format `expected` items correctly.
5353
impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> {
54-
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
54+
fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
5555
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
56-
let mut diag = handler.struct_span_err_with_code(
56+
let mut diag = dcx.struct_span_err_with_code(
5757
self.span,
5858
fluent::attr_unknown_meta_item,
5959
error_code!(E0541),
@@ -201,8 +201,8 @@ pub(crate) struct UnsupportedLiteral {
201201
}
202202

203203
impl<'a> IntoDiagnostic<'a> for UnsupportedLiteral {
204-
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
205-
let mut diag = handler.struct_span_err_with_code(
204+
fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
205+
let mut diag = dcx.struct_span_err_with_code(
206206
self.span,
207207
match self.reason {
208208
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ impl UseSpans<'_> {
624624
/// Add a subdiagnostic to the use of the captured variable, if it exists.
625625
pub(super) fn var_subdiag(
626626
self,
627-
handler: Option<&rustc_errors::DiagCtxt>,
627+
dcx: Option<&rustc_errors::DiagCtxt>,
628628
err: &mut Diagnostic,
629629
kind: Option<rustc_middle::mir::BorrowKind>,
630630
f: impl FnOnce(Option<CoroutineKind>, Span) -> CaptureVarCause,
@@ -646,7 +646,7 @@ impl UseSpans<'_> {
646646
});
647647
};
648648
let diag = f(coroutine_kind, path_span);
649-
match handler {
649+
match dcx {
650650
Some(hd) => err.eager_subdiagnostic(hd, diag),
651651
None => err.subdiagnostic(diag),
652652
};

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,12 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
448448
// Hand-written implementation to support custom user messages.
449449
impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage {
450450
#[track_caller]
451-
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
451+
fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
452452
#[expect(
453453
rustc::untranslatable_diagnostic,
454454
reason = "cannot translate user-provided messages"
455455
)]
456-
let mut diag = handler.struct_err(self.msg_from_user.to_string());
456+
let mut diag = dcx.struct_err(self.msg_from_user.to_string());
457457
diag.set_span(self.span);
458458
diag
459459
}
@@ -802,17 +802,16 @@ pub(crate) struct AsmClobberNoReg {
802802
}
803803

804804
impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg {
805-
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
806-
let mut diag =
807-
handler.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
805+
fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
806+
let mut diag = dcx.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
808807
diag.set_span(self.spans.clone());
809808
// eager translation as `span_labels` takes `AsRef<str>`
810-
let lbl1 = handler.eagerly_translate_to_string(
809+
let lbl1 = dcx.eagerly_translate_to_string(
811810
crate::fluent_generated::builtin_macros_asm_clobber_abi,
812811
[].into_iter(),
813812
);
814813
diag.span_labels(self.clobbers, &lbl1);
815-
let lbl2 = handler.eagerly_translate_to_string(
814+
let lbl2 = dcx.eagerly_translate_to_string(
816815
crate::fluent_generated::builtin_macros_asm_clobber_outputs,
817816
[].into_iter(),
818817
);

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ pub fn inject(
5252
is_proc_macro_crate: bool,
5353
has_proc_macro_decls: bool,
5454
is_test_crate: bool,
55-
handler: &rustc_errors::DiagCtxt,
55+
dcx: &rustc_errors::DiagCtxt,
5656
) {
5757
let ecfg = ExpansionConfig::default("proc_macro".to_string(), features);
5858
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
5959

6060
let mut collect = CollectProcMacros {
6161
macros: Vec::new(),
6262
in_root: true,
63-
dcx: handler,
63+
dcx,
6464
source_map: sess.source_map(),
6565
is_proc_macro_crate,
6666
is_test_crate,

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,19 @@ fn get_test_name(i: &ast::Item) -> Option<Symbol> {
389389
attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
390390
}
391391

392-
fn get_test_runner(sd: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option<ast::Path> {
392+
fn get_test_runner(dcx: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option<ast::Path> {
393393
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
394394
let meta_list = test_attr.meta_item_list()?;
395395
let span = test_attr.span;
396396
match &*meta_list {
397397
[single] => match single.meta_item() {
398398
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
399399
_ => {
400-
sd.emit_err(errors::TestRunnerInvalid { span });
400+
dcx.emit_err(errors::TestRunnerInvalid { span });
401401
}
402402
},
403403
_ => {
404-
sd.emit_err(errors::TestRunnerNargs { span });
404+
dcx.emit_err(errors::TestRunnerNargs { span });
405405
}
406406
}
407407
None

compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl ConcurrencyLimiter {
4646
}
4747
}
4848

49-
pub(super) fn acquire(&mut self, handler: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
49+
pub(super) fn acquire(&mut self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
5050
let mut state = self.state.lock().unwrap();
5151
loop {
5252
state.assert_invariants();
@@ -64,7 +64,7 @@ impl ConcurrencyLimiter {
6464
// Make sure to drop the mutex guard first to prevent poisoning the mutex.
6565
drop(state);
6666
if let Some(err) = err {
67-
handler.fatal(err);
67+
dcx.fatal(err);
6868
} else {
6969
// The error was already emitted, but compilation continued. Raise a silent
7070
// fatal error.

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct LtoData {
6161
tmp_path: TempDir,
6262
}
6363

64-
fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &DiagCtxt) -> Result<LtoData, FatalError> {
64+
fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, dcx: &DiagCtxt) -> Result<LtoData, FatalError> {
6565
let export_threshold = match cgcx.lto {
6666
// We're just doing LTO for our one crate
6767
Lto::ThinLocal => SymbolExportLevel::Rust,
@@ -106,18 +106,18 @@ fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &DiagCtxt
106106
// Make sure we actually can run LTO
107107
for crate_type in cgcx.crate_types.iter() {
108108
if !crate_type_allows_lto(*crate_type) {
109-
diag_handler.emit_err(LtoDisallowed);
109+
dcx.emit_err(LtoDisallowed);
110110
return Err(FatalError);
111111
} else if *crate_type == CrateType::Dylib {
112112
if !cgcx.opts.unstable_opts.dylib_lto {
113-
diag_handler.emit_err(LtoDylib);
113+
dcx.emit_err(LtoDylib);
114114
return Err(FatalError);
115115
}
116116
}
117117
}
118118

119119
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
120-
diag_handler.emit_err(DynamicLinkingWithLTO);
120+
dcx.emit_err(DynamicLinkingWithLTO);
121121
return Err(FatalError);
122122
}
123123

@@ -154,7 +154,7 @@ fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &DiagCtxt
154154
upstream_modules.push((module, CString::new(name).unwrap()));
155155
}
156156
Err(e) => {
157-
diag_handler.emit_err(e);
157+
dcx.emit_err(e);
158158
return Err(FatalError);
159159
}
160160
}
@@ -183,16 +183,16 @@ pub(crate) fn run_fat(
183183
modules: Vec<FatLtoInput<GccCodegenBackend>>,
184184
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
185185
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
186-
let diag_handler = cgcx.create_dcx();
187-
let lto_data = prepare_lto(cgcx, &diag_handler)?;
186+
let dcx = cgcx.create_dcx();
187+
let lto_data = prepare_lto(cgcx, &dcx)?;
188188
/*let symbols_below_threshold =
189189
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
190-
fat_lto(cgcx, &diag_handler, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path,
190+
fat_lto(cgcx, &dcx, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path,
191191
//&symbols_below_threshold,
192192
)
193193
}
194194

195-
fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &DiagCtxt, modules: Vec<FatLtoInput<GccCodegenBackend>>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, tmp_path: TempDir,
195+
fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _dcx: &DiagCtxt, modules: Vec<FatLtoInput<GccCodegenBackend>>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, tmp_path: TempDir,
196196
//symbols_below_threshold: &[*const libc::c_char],
197197
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
198198
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
@@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &DiagCtxt, m
257257
let (buffer, name) = serialized_modules.remove(0);
258258
info!("no in-memory regular modules to choose from, parsing {:?}", name);
259259
ModuleCodegen {
260-
module_llvm: GccContext::parse(cgcx, &name, buffer.data(), diag_handler)?,
260+
module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?,
261261
name: name.into_string().unwrap(),
262262
kind: ModuleKind::Regular,
263263
}*/

compiler/rustc_codegen_gcc/src/back/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_target::spec::SplitDebuginfo;
1313
use crate::{GccCodegenBackend, GccContext};
1414
use crate::errors::CopyBitcode;
1515

16-
pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &DiagCtxt, module: ModuleCodegen<GccContext>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
16+
pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, dcx: &DiagCtxt, module: ModuleCodegen<GccContext>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
1717
let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
1818
{
1919
let context = &module.module_llvm.context;
@@ -127,12 +127,12 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
127127
EmitObj::Bitcode => {
128128
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
129129
if let Err(err) = link_or_copy(&bc_out, &obj_out) {
130-
diag_handler.emit_err(CopyBitcode { err });
130+
dcx.emit_err(CopyBitcode { err });
131131
}
132132

133133
if !config.emit_bc {
134134
debug!("removing_bitcode {:?}", bc_out);
135-
ensure_removed(diag_handler, &bc_out);
135+
ensure_removed(dcx, &bc_out);
136136
}
137137
}
138138

@@ -148,7 +148,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
148148
))
149149
}
150150

151-
pub(crate) fn link(_cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &DiagCtxt, mut _modules: Vec<ModuleCodegen<GccContext>>) -> Result<ModuleCodegen<GccContext>, FatalError> {
151+
pub(crate) fn link(_cgcx: &CodegenContext<GccCodegenBackend>, _dcx: &DiagCtxt, mut _modules: Vec<ModuleCodegen<GccContext>>) -> Result<ModuleCodegen<GccContext>, FatalError> {
152152
unimplemented!();
153153
}
154154

compiler/rustc_codegen_gcc/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
112112
pub(crate) struct MissingFeatures;
113113

114114
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
115-
fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
116-
let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
115+
fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
116+
let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
117117
if let Some(span) = self.span {
118118
diag.set_span(span);
119119
};

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl WriteBackendMethods for GccCodegenBackend {
330330
unimplemented!()
331331
}
332332

333-
unsafe fn optimize(_cgcx: &CodegenContext<Self>, _diag_handler: &DiagCtxt, module: &ModuleCodegen<Self::Module>, config: &ModuleConfig) -> Result<(), FatalError> {
333+
unsafe fn optimize(_cgcx: &CodegenContext<Self>, _dcx: &DiagCtxt, module: &ModuleCodegen<Self::Module>, config: &ModuleConfig) -> Result<(), FatalError> {
334334
module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level));
335335
Ok(())
336336
}
@@ -344,8 +344,8 @@ impl WriteBackendMethods for GccCodegenBackend {
344344
unimplemented!();
345345
}
346346

347-
unsafe fn codegen(cgcx: &CodegenContext<Self>, diag_handler: &DiagCtxt, module: ModuleCodegen<Self::Module>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
348-
back::write::codegen(cgcx, diag_handler, module, config)
347+
unsafe fn codegen(cgcx: &CodegenContext<Self>, dcx: &DiagCtxt, module: ModuleCodegen<Self::Module>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
348+
back::write::codegen(cgcx, dcx, module, config)
349349
}
350350

351351
fn prepare_thin(_module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
@@ -356,8 +356,8 @@ impl WriteBackendMethods for GccCodegenBackend {
356356
unimplemented!();
357357
}
358358

359-
fn run_link(cgcx: &CodegenContext<Self>, diag_handler: &DiagCtxt, modules: Vec<ModuleCodegen<Self::Module>>) -> Result<ModuleCodegen<Self::Module>, FatalError> {
360-
back::write::link(cgcx, diag_handler, modules)
359+
fn run_link(cgcx: &CodegenContext<Self>, dcx: &DiagCtxt, modules: Vec<ModuleCodegen<Self::Module>>) -> Result<ModuleCodegen<Self::Module>, FatalError> {
360+
back::write::link(cgcx, dcx, modules)
361361
}
362362
}
363363

0 commit comments

Comments
 (0)