Skip to content

Commit f6aa418

Browse files
committed
Rename many DiagCtxt and EarlyDiagCtxt locals.
1 parent d58e372 commit f6aa418

File tree

33 files changed

+253
-261
lines changed

33 files changed

+253
-261
lines changed

Diff for: compiler/rustc_builtin_macros/src/asm.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ pub fn parse_asm_args<'a>(
4747
sp: Span,
4848
is_global_asm: bool,
4949
) -> PResult<'a, AsmArgs> {
50-
let diag = &sess.dcx;
50+
let dcx = &sess.dcx;
5151

5252
if p.token == token::Eof {
53-
return Err(diag.create_err(errors::AsmRequiresTemplate { span: sp }));
53+
return Err(dcx.create_err(errors::AsmRequiresTemplate { span: sp }));
5454
}
5555

5656
let first_template = p.parse_expr()?;
@@ -69,7 +69,7 @@ pub fn parse_asm_args<'a>(
6969
if !p.eat(&token::Comma) {
7070
if allow_templates {
7171
// After a template string, we always expect *only* a comma...
72-
return Err(diag.create_err(errors::AsmExpectedComma { span: p.token.span }));
72+
return Err(dcx.create_err(errors::AsmExpectedComma { span: p.token.span }));
7373
} else {
7474
// ...after that delegate to `expect` to also include the other expected tokens.
7575
return Err(p.expect(&token::Comma).err().unwrap());
@@ -110,7 +110,7 @@ pub fn parse_asm_args<'a>(
110110
let op = if !is_global_asm && p.eat_keyword(kw::In) {
111111
let reg = parse_reg(p, &mut explicit_reg)?;
112112
if p.eat_keyword(kw::Underscore) {
113-
let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
113+
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
114114
return Err(err);
115115
}
116116
let expr = p.parse_expr()?;
@@ -126,7 +126,7 @@ pub fn parse_asm_args<'a>(
126126
} else if !is_global_asm && p.eat_keyword(sym::inout) {
127127
let reg = parse_reg(p, &mut explicit_reg)?;
128128
if p.eat_keyword(kw::Underscore) {
129-
let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
129+
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
130130
return Err(err);
131131
}
132132
let expr = p.parse_expr()?;
@@ -140,7 +140,7 @@ pub fn parse_asm_args<'a>(
140140
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
141141
let reg = parse_reg(p, &mut explicit_reg)?;
142142
if p.eat_keyword(kw::Underscore) {
143-
let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
143+
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
144144
return Err(err);
145145
}
146146
let expr = p.parse_expr()?;
@@ -157,7 +157,7 @@ pub fn parse_asm_args<'a>(
157157
} else if p.eat_keyword(sym::sym) {
158158
let expr = p.parse_expr()?;
159159
let ast::ExprKind::Path(qself, path) = &expr.kind else {
160-
let err = diag.create_err(errors::AsmSymNoPath { span: expr.span });
160+
let err = dcx.create_err(errors::AsmSymNoPath { span: expr.span });
161161
return Err(err);
162162
};
163163
let sym = ast::InlineAsmSym {
@@ -178,7 +178,7 @@ pub fn parse_asm_args<'a>(
178178
) => {}
179179
ast::ExprKind::MacCall(..) => {}
180180
_ => {
181-
let err = diag.create_err(errors::AsmExpectedOther {
181+
let err = dcx.create_err(errors::AsmExpectedOther {
182182
span: template.span,
183183
is_global_asm,
184184
});
@@ -201,12 +201,12 @@ pub fn parse_asm_args<'a>(
201201
// of the argument available.
202202
if explicit_reg {
203203
if name.is_some() {
204-
diag.emit_err(errors::AsmExplicitRegisterName { span });
204+
dcx.emit_err(errors::AsmExplicitRegisterName { span });
205205
}
206206
args.reg_args.insert(slot);
207207
} else if let Some(name) = name {
208208
if let Some(&prev) = args.named_args.get(&name) {
209-
diag.emit_err(errors::AsmDuplicateArg { span, name, prev: args.operands[prev].1 });
209+
dcx.emit_err(errors::AsmDuplicateArg { span, name, prev: args.operands[prev].1 });
210210
continue;
211211
}
212212
args.named_args.insert(name, slot);
@@ -215,7 +215,7 @@ pub fn parse_asm_args<'a>(
215215
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
216216
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
217217

218-
diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
218+
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
219219
}
220220
}
221221
}
@@ -224,19 +224,19 @@ pub fn parse_asm_args<'a>(
224224
&& args.options.contains(ast::InlineAsmOptions::READONLY)
225225
{
226226
let spans = args.options_spans.clone();
227-
diag.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "nomem", opt2: "readonly" });
227+
dcx.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "nomem", opt2: "readonly" });
228228
}
229229
if args.options.contains(ast::InlineAsmOptions::PURE)
230230
&& args.options.contains(ast::InlineAsmOptions::NORETURN)
231231
{
232232
let spans = args.options_spans.clone();
233-
diag.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "pure", opt2: "noreturn" });
233+
dcx.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "pure", opt2: "noreturn" });
234234
}
235235
if args.options.contains(ast::InlineAsmOptions::PURE)
236236
&& !args.options.intersects(ast::InlineAsmOptions::NOMEM | ast::InlineAsmOptions::READONLY)
237237
{
238238
let spans = args.options_spans.clone();
239-
diag.emit_err(errors::AsmPureCombine { spans });
239+
dcx.emit_err(errors::AsmPureCombine { spans });
240240
}
241241

242242
let mut have_real_output = false;
@@ -263,25 +263,25 @@ pub fn parse_asm_args<'a>(
263263
}
264264
}
265265
if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output {
266-
diag.emit_err(errors::AsmPureNoOutput { spans: args.options_spans.clone() });
266+
dcx.emit_err(errors::AsmPureNoOutput { spans: args.options_spans.clone() });
267267
}
268268
if args.options.contains(ast::InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() {
269-
let err = diag.create_err(errors::AsmNoReturn { outputs_sp });
269+
let err = dcx.create_err(errors::AsmNoReturn { outputs_sp });
270270
// Bail out now since this is likely to confuse MIR
271271
return Err(err);
272272
}
273273

274274
if args.clobber_abis.len() > 0 {
275275
if is_global_asm {
276-
let err = diag.create_err(errors::GlobalAsmClobberAbi {
276+
let err = dcx.create_err(errors::GlobalAsmClobberAbi {
277277
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
278278
});
279279

280280
// Bail out now since this is likely to confuse later stages
281281
return Err(err);
282282
}
283283
if !regclass_outputs.is_empty() {
284-
diag.emit_err(errors::AsmClobberNoReg {
284+
dcx.emit_err(errors::AsmClobberNoReg {
285285
spans: regclass_outputs,
286286
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
287287
});

Diff for: compiler/rustc_builtin_macros/src/test.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,16 @@ pub fn expand_test_or_bench(
389389
}
390390

391391
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
392-
let diag = cx.sess.dcx();
392+
let dcx = cx.sess.dcx();
393393
let msg = "the `#[test]` attribute may only be used on a non-associated function";
394394
let mut err = match item.map(|i| &i.kind) {
395395
// These were a warning before #92959 and need to continue being that to avoid breaking
396396
// stable user code (#94508).
397-
Some(ast::ItemKind::MacCall(_)) => diag.struct_span_warn(attr_sp, msg),
397+
Some(ast::ItemKind::MacCall(_)) => dcx.struct_span_warn(attr_sp, msg),
398398
// `.forget_guarantee()` needed to get these two arms to match types. Because of how
399399
// locally close the `.emit()` call is I'm comfortable with it, but if it can be
400400
// reworked in the future to not need it, it'd be nice.
401-
_ => diag.struct_span_err(attr_sp, msg).forget_guarantee(),
401+
_ => dcx.struct_span_err(attr_sp, msg).forget_guarantee(),
402402
};
403403
if let Some(item) = item {
404404
err.span_label(
@@ -466,7 +466,7 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
466466
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
467467
match attr::find_by_name(&i.attrs, sym::should_panic) {
468468
Some(attr) => {
469-
let sd = cx.sess.dcx();
469+
let dcx = cx.sess.dcx();
470470

471471
match attr.meta_item_list() {
472472
// Handle #[should_panic(expected = "foo")]
@@ -477,7 +477,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
477477
.and_then(|mi| mi.meta_item())
478478
.and_then(|mi| mi.value_str());
479479
if list.len() != 1 || msg.is_none() {
480-
sd.struct_span_warn(
480+
dcx.struct_span_warn(
481481
attr.span,
482482
"argument must be of the form: \
483483
`expected = \"error message\"`",
@@ -535,30 +535,30 @@ fn check_test_signature(
535535
f: &ast::Fn,
536536
) -> Result<(), ErrorGuaranteed> {
537537
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
538-
let sd = cx.sess.dcx();
538+
let dcx = cx.sess.dcx();
539539

540540
if let ast::Unsafe::Yes(span) = f.sig.header.unsafety {
541-
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
541+
return Err(dcx.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
542542
}
543543

544544
if let Some(coroutine_kind) = f.sig.header.coroutine_kind {
545545
match coroutine_kind {
546546
ast::CoroutineKind::Async { span, .. } => {
547-
return Err(sd.emit_err(errors::TestBadFn {
547+
return Err(dcx.emit_err(errors::TestBadFn {
548548
span: i.span,
549549
cause: span,
550550
kind: "async",
551551
}));
552552
}
553553
ast::CoroutineKind::Gen { span, .. } => {
554-
return Err(sd.emit_err(errors::TestBadFn {
554+
return Err(dcx.emit_err(errors::TestBadFn {
555555
span: i.span,
556556
cause: span,
557557
kind: "gen",
558558
}));
559559
}
560560
ast::CoroutineKind::AsyncGen { span, .. } => {
561-
return Err(sd.emit_err(errors::TestBadFn {
561+
return Err(dcx.emit_err(errors::TestBadFn {
562562
span: i.span,
563563
cause: span,
564564
kind: "async gen",
@@ -576,15 +576,15 @@ fn check_test_signature(
576576
};
577577

578578
if !f.sig.decl.inputs.is_empty() {
579-
return Err(sd.span_err(i.span, "functions used as tests can not have any arguments"));
579+
return Err(dcx.span_err(i.span, "functions used as tests can not have any arguments"));
580580
}
581581

582582
if has_should_panic_attr && has_output {
583-
return Err(sd.span_err(i.span, "functions using `#[should_panic]` must return `()`"));
583+
return Err(dcx.span_err(i.span, "functions using `#[should_panic]` must return `()`"));
584584
}
585585

586586
if f.generics.params.iter().any(|param| !matches!(param.kind, GenericParamKind::Lifetime)) {
587-
return Err(sd.span_err(
587+
return Err(dcx.span_err(
588588
i.span,
589589
"functions used as tests can not have any non-lifetime generic parameters",
590590
));

Diff for: compiler/rustc_builtin_macros/src/test_harness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn inject(
4747
features: &Features,
4848
resolver: &mut dyn ResolverExpand,
4949
) {
50-
let span_diagnostic = sess.dcx();
50+
let dcx = sess.dcx();
5151
let panic_strategy = sess.panic_strategy();
5252
let platform_panic_strategy = sess.target.panic_strategy;
5353

@@ -60,7 +60,7 @@ pub fn inject(
6060

6161
// Do this here so that the test_runner crate attribute gets marked as used
6262
// even in non-test builds
63-
let test_runner = get_test_runner(span_diagnostic, krate);
63+
let test_runner = get_test_runner(dcx, krate);
6464

6565
if sess.is_test_crate() {
6666
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
@@ -70,7 +70,7 @@ pub fn inject(
7070
// Silently allow compiling with panic=abort on these platforms,
7171
// but with old behavior (abort if a test fails).
7272
} else {
73-
span_diagnostic.emit_err(errors::TestsNotSupport {});
73+
dcx.emit_err(errors::TestsNotSupport {});
7474
}
7575
PanicStrategy::Unwind
7676
}

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ pub(crate) fn compile_fn(
176176
match module.define_function(codegened_func.func_id, context) {
177177
Ok(()) => {}
178178
Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => {
179-
let handler = rustc_session::EarlyDiagCtxt::new(
179+
let early_dcx = rustc_session::EarlyDiagCtxt::new(
180180
rustc_session::config::ErrorOutputType::default(),
181181
);
182-
handler.early_error(format!(
182+
early_dcx.early_error(format!(
183183
"backend implementation limit exceeded while compiling {name}",
184184
name = codegened_func.symbol_name
185185
));

Diff for: compiler/rustc_codegen_llvm/src/back/lto.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,11 @@ pub(crate) fn run_fat(
200200
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
201201
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
202202
) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> {
203-
let diag_handler = cgcx.create_dcx();
204-
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
203+
let dcx = cgcx.create_dcx();
204+
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &dcx)?;
205205
let symbols_below_threshold =
206206
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
207-
fat_lto(
208-
cgcx,
209-
&diag_handler,
210-
modules,
211-
cached_modules,
212-
upstream_modules,
213-
&symbols_below_threshold,
214-
)
207+
fat_lto(cgcx, &dcx, modules, cached_modules, upstream_modules, &symbols_below_threshold)
215208
}
216209

217210
/// Performs thin LTO by performing necessary global analysis and returning two
@@ -222,8 +215,8 @@ pub(crate) fn run_thin(
222215
modules: Vec<(String, ThinBuffer)>,
223216
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
224217
) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
225-
let diag_handler = cgcx.create_dcx();
226-
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &diag_handler)?;
218+
let dcx = cgcx.create_dcx();
219+
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, &dcx)?;
227220
let symbols_below_threshold =
228221
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
229222
if cgcx.opts.cg.linker_plugin_lto.enabled() {
@@ -232,14 +225,7 @@ pub(crate) fn run_thin(
232225
is deferred to the linker"
233226
);
234227
}
235-
thin_lto(
236-
cgcx,
237-
&diag_handler,
238-
modules,
239-
upstream_modules,
240-
cached_modules,
241-
&symbols_below_threshold,
242-
)
228+
thin_lto(cgcx, &dcx, modules, upstream_modules, cached_modules, &symbols_below_threshold)
243229
}
244230

245231
pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
@@ -714,19 +700,19 @@ pub unsafe fn optimize_thin_module(
714700
thin_module: ThinModule<LlvmCodegenBackend>,
715701
cgcx: &CodegenContext<LlvmCodegenBackend>,
716702
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
717-
let diag_handler = cgcx.create_dcx();
703+
let dcx = cgcx.create_dcx();
718704

719705
let module_name = &thin_module.shared.module_names[thin_module.idx];
720706
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
721-
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, e))?;
707+
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&dcx, e))?;
722708

723709
// Right now the implementation we've got only works over serialized
724710
// modules, so we create a fresh new LLVM context and parse the module
725711
// into that context. One day, however, we may do this for upstream
726712
// crates but for locally codegened modules we may be able to reuse
727713
// that LLVM Context and Module.
728714
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
729-
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
715+
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &dcx)? as *const _;
730716
let mut module = ModuleCodegen {
731717
module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) },
732718
name: thin_module.name().to_string(),
@@ -749,7 +735,7 @@ pub unsafe fn optimize_thin_module(
749735
let _timer =
750736
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
751737
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) {
752-
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
738+
return Err(write::llvm_err(&dcx, LlvmError::PrepareThinLtoModule));
753739
}
754740
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
755741
}
@@ -759,7 +745,7 @@ pub unsafe fn optimize_thin_module(
759745
.prof
760746
.generic_activity_with_arg("LLVM_thin_lto_resolve_weak", thin_module.name());
761747
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
762-
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
748+
return Err(write::llvm_err(&dcx, LlvmError::PrepareThinLtoModule));
763749
}
764750
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
765751
}
@@ -769,7 +755,7 @@ pub unsafe fn optimize_thin_module(
769755
.prof
770756
.generic_activity_with_arg("LLVM_thin_lto_internalize", thin_module.name());
771757
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
772-
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
758+
return Err(write::llvm_err(&dcx, LlvmError::PrepareThinLtoModule));
773759
}
774760
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
775761
}
@@ -778,7 +764,7 @@ pub unsafe fn optimize_thin_module(
778764
let _timer =
779765
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
780766
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) {
781-
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
767+
return Err(write::llvm_err(&dcx, LlvmError::PrepareThinLtoModule));
782768
}
783769
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
784770
}
@@ -790,7 +776,7 @@ pub unsafe fn optimize_thin_module(
790776
// little differently.
791777
{
792778
info!("running thin lto passes over {}", module.name);
793-
run_pass_manager(cgcx, &diag_handler, &mut module, true)?;
779+
run_pass_manager(cgcx, &dcx, &mut module, true)?;
794780
save_temp_bitcode(cgcx, &module, "thin-lto-after-pm");
795781
}
796782
}

0 commit comments

Comments
 (0)