From f422dca3ae8b8a8c9a99b8e6ec0899e08dc072c3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 10:15:45 +1100 Subject: [PATCH] Rename many `DiagCtxt` arguments. --- .../rustc_ast_passes/src/ast_validation.rs | 4 +- .../rustc_attr/src/session_diagnostics.rs | 8 +- .../rustc_borrowck/src/diagnostics/mod.rs | 4 +- compiler/rustc_builtin_macros/src/errors.rs | 13 ++- .../src/proc_macro_harness.rs | 4 +- .../rustc_builtin_macros/src/test_harness.rs | 6 +- .../src/concurrency_limiter.rs | 4 +- compiler/rustc_codegen_gcc/src/back/lto.rs | 20 ++--- compiler/rustc_codegen_gcc/src/back/write.rs | 8 +- compiler/rustc_codegen_gcc/src/errors.rs | 4 +- compiler/rustc_codegen_gcc/src/lib.rs | 10 +-- compiler/rustc_codegen_llvm/src/back/lto.rs | 43 ++++----- compiler/rustc_codegen_llvm/src/back/write.rs | 60 ++++++------- compiler/rustc_codegen_llvm/src/errors.rs | 17 ++-- compiler/rustc_codegen_llvm/src/lib.rs | 18 ++-- compiler/rustc_codegen_ssa/src/back/link.rs | 4 +- compiler/rustc_codegen_ssa/src/errors.rs | 87 +++++++++---------- .../rustc_codegen_ssa/src/traits/write.rs | 6 +- compiler/rustc_const_eval/src/errors.rs | 54 +++++------- compiler/rustc_errors/src/diagnostic.rs | 4 +- .../rustc_errors/src/diagnostic_builder.rs | 40 ++++----- compiler/rustc_errors/src/diagnostic_impls.rs | 16 ++-- compiler/rustc_expand/src/base.rs | 20 ++--- compiler/rustc_hir_analysis/src/errors.rs | 4 +- compiler/rustc_interface/src/interface.rs | 30 +++---- compiler/rustc_metadata/src/errors.rs | 12 +-- compiler/rustc_middle/src/ty/layout.rs | 6 +- compiler/rustc_mir_build/src/errors.rs | 4 +- compiler/rustc_mir_transform/src/errors.rs | 9 +- compiler/rustc_monomorphize/src/errors.rs | 4 +- compiler/rustc_parse/src/errors.rs | 8 +- .../src/lexer/unescape_error_reporting.rs | 47 +++++----- compiler/rustc_passes/src/errors.rs | 20 ++--- compiler/rustc_query_system/src/query/job.rs | 4 +- compiler/rustc_session/src/errors.rs | 4 +- compiler/rustc_session/src/parse.rs | 4 +- compiler/rustc_symbol_mangling/src/errors.rs | 4 +- compiler/rustc_trait_selection/src/errors.rs | 4 +- src/librustdoc/config.rs | 6 +- src/librustdoc/core.rs | 4 +- src/librustdoc/externalfiles.rs | 22 ++--- src/librustdoc/lib.rs | 6 +- src/librustdoc/scrape_examples.rs | 10 +-- src/librustdoc/theme.rs | 4 +- 44 files changed, 317 insertions(+), 353 deletions(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 7a1ebdbee69..9db72c15941 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -696,7 +696,7 @@ impl<'a> AstValidator<'a> { /// Checks that generic parameters are in the correct order, /// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`) fn validate_generic_param_order( - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, generics: &[GenericParam], span: Span, ) { @@ -759,7 +759,7 @@ fn validate_generic_param_order( ordered_params += ">"; for (param_ord, (max_param, spans)) in &out_of_order { - handler.emit_err(errors::OutOfOrderParams { + dcx.emit_err(errors::OutOfOrderParams { spans: spans.clone(), sugg_span: span, param_ord, diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 6573f8c7dc1..ce8e04defb2 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -51,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> { // Manual implementation to be able to format `expected` items correctly. impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::>(); - let mut diag = handler.struct_span_err_with_code( + let mut diag = dcx.struct_span_err_with_code( self.span, fluent::attr_unknown_meta_item, error_code!(E0541), @@ -201,8 +201,8 @@ pub(crate) struct UnsupportedLiteral { } impl<'a> IntoDiagnostic<'a> for UnsupportedLiteral { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut diag = handler.struct_span_err_with_code( + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + let mut diag = dcx.struct_span_err_with_code( self.span, match self.reason { UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index a4e09c0f412..ee321365470 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -624,7 +624,7 @@ impl UseSpans<'_> { /// Add a subdiagnostic to the use of the captured variable, if it exists. pub(super) fn var_subdiag( self, - handler: Option<&rustc_errors::DiagCtxt>, + dcx: Option<&rustc_errors::DiagCtxt>, err: &mut Diagnostic, kind: Option, f: impl FnOnce(Option, Span) -> CaptureVarCause, @@ -646,7 +646,7 @@ impl UseSpans<'_> { }); }; let diag = f(coroutine_kind, path_span); - match handler { + match dcx { Some(hd) => err.eager_subdiagnostic(hd, diag), None => err.subdiagnostic(diag), }; diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index 0523f9acd62..6ffeb401453 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -448,12 +448,12 @@ pub(crate) struct EnvNotDefinedWithUserMessage { // Hand-written implementation to support custom user messages. impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage { #[track_caller] - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { #[expect( rustc::untranslatable_diagnostic, reason = "cannot translate user-provided messages" )] - let mut diag = handler.struct_err(self.msg_from_user.to_string()); + let mut diag = dcx.struct_err(self.msg_from_user.to_string()); diag.set_span(self.span); diag } @@ -802,17 +802,16 @@ pub(crate) struct AsmClobberNoReg { } impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut diag = - handler.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg); + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + let mut diag = dcx.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg); diag.set_span(self.spans.clone()); // eager translation as `span_labels` takes `AsRef` - let lbl1 = handler.eagerly_translate_to_string( + let lbl1 = dcx.eagerly_translate_to_string( crate::fluent_generated::builtin_macros_asm_clobber_abi, [].into_iter(), ); diag.span_labels(self.clobbers, &lbl1); - let lbl2 = handler.eagerly_translate_to_string( + let lbl2 = dcx.eagerly_translate_to_string( crate::fluent_generated::builtin_macros_asm_clobber_outputs, [].into_iter(), ); diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 6539d120698..4fddaa8ab6c 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -52,7 +52,7 @@ pub fn inject( is_proc_macro_crate: bool, has_proc_macro_decls: bool, is_test_crate: bool, - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) { let ecfg = ExpansionConfig::default("proc_macro".to_string(), features); let mut cx = ExtCtxt::new(sess, ecfg, resolver, None); @@ -60,7 +60,7 @@ pub fn inject( let mut collect = CollectProcMacros { macros: Vec::new(), in_root: true, - dcx: handler, + dcx, source_map: sess.source_map(), is_proc_macro_crate, is_test_crate, diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 6fbbef1eda8..ff8d8e43525 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -389,7 +389,7 @@ fn get_test_name(i: &ast::Item) -> Option { attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker) } -fn get_test_runner(sd: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option { +fn get_test_runner(dcx: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option { let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?; let meta_list = test_attr.meta_item_list()?; let span = test_attr.span; @@ -397,11 +397,11 @@ fn get_test_runner(sd: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option match single.meta_item() { Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()), _ => { - sd.emit_err(errors::TestRunnerInvalid { span }); + dcx.emit_err(errors::TestRunnerInvalid { span }); } }, _ => { - sd.emit_err(errors::TestRunnerNargs { span }); + dcx.emit_err(errors::TestRunnerNargs { span }); } } None diff --git a/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs b/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs index 1fb9d7afbc9..9678969134a 100644 --- a/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs +++ b/compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs @@ -46,7 +46,7 @@ impl ConcurrencyLimiter { } } - pub(super) fn acquire(&mut self, handler: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken { + pub(super) fn acquire(&mut self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken { let mut state = self.state.lock().unwrap(); loop { state.assert_invariants(); @@ -64,7 +64,7 @@ impl ConcurrencyLimiter { // Make sure to drop the mutex guard first to prevent poisoning the mutex. drop(state); if let Some(err) = err { - handler.fatal(err); + dcx.fatal(err); } else { // The error was already emitted, but compilation continued. Raise a silent // fatal error. diff --git a/compiler/rustc_codegen_gcc/src/back/lto.rs b/compiler/rustc_codegen_gcc/src/back/lto.rs index ee8da7c6cb7..c21b7686823 100644 --- a/compiler/rustc_codegen_gcc/src/back/lto.rs +++ b/compiler/rustc_codegen_gcc/src/back/lto.rs @@ -61,7 +61,7 @@ struct LtoData { tmp_path: TempDir, } -fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt) -> Result { +fn prepare_lto(cgcx: &CodegenContext, dcx: &DiagCtxt) -> Result { let export_threshold = match cgcx.lto { // We're just doing LTO for our one crate Lto::ThinLocal => SymbolExportLevel::Rust, @@ -106,18 +106,18 @@ fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt // Make sure we actually can run LTO for crate_type in cgcx.crate_types.iter() { if !crate_type_allows_lto(*crate_type) { - diag_handler.emit_err(LtoDisallowed); + dcx.emit_err(LtoDisallowed); return Err(FatalError); } else if *crate_type == CrateType::Dylib { if !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(LtoDylib); + dcx.emit_err(LtoDylib); return Err(FatalError); } } } if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(DynamicLinkingWithLTO); + dcx.emit_err(DynamicLinkingWithLTO); return Err(FatalError); } @@ -154,7 +154,7 @@ fn prepare_lto(cgcx: &CodegenContext, diag_handler: &DiagCtxt upstream_modules.push((module, CString::new(name).unwrap())); } Err(e) => { - diag_handler.emit_err(e); + dcx.emit_err(e); return Err(FatalError); } } @@ -183,16 +183,16 @@ pub(crate) fn run_fat( modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, ) -> Result, FatalError> { - let diag_handler = cgcx.create_dcx(); - let lto_data = prepare_lto(cgcx, &diag_handler)?; + let dcx = cgcx.create_dcx(); + let lto_data = prepare_lto(cgcx, &dcx)?; /*let symbols_below_threshold = lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::>();*/ - fat_lto(cgcx, &diag_handler, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path, + fat_lto(cgcx, &dcx, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path, //&symbols_below_threshold, ) } -fn fat_lto(cgcx: &CodegenContext, _diag_handler: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, +fn fat_lto(cgcx: &CodegenContext, _dcx: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, tmp_path: TempDir, //symbols_below_threshold: &[*const libc::c_char], ) -> Result, FatalError> { let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module"); @@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext, _diag_handler: &DiagCtxt, m let (buffer, name) = serialized_modules.remove(0); info!("no in-memory regular modules to choose from, parsing {:?}", name); ModuleCodegen { - module_llvm: GccContext::parse(cgcx, &name, buffer.data(), diag_handler)?, + module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?, name: name.into_string().unwrap(), kind: ModuleKind::Regular, }*/ diff --git a/compiler/rustc_codegen_gcc/src/back/write.rs b/compiler/rustc_codegen_gcc/src/back/write.rs index c2438d7ca36..2f8a54f529c 100644 --- a/compiler/rustc_codegen_gcc/src/back/write.rs +++ b/compiler/rustc_codegen_gcc/src/back/write.rs @@ -13,7 +13,7 @@ use rustc_target::spec::SplitDebuginfo; use crate::{GccCodegenBackend, GccContext}; use crate::errors::CopyBitcode; -pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { +pub(crate) unsafe fn codegen(cgcx: &CodegenContext, dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name); { let context = &module.module_llvm.context; @@ -127,12 +127,12 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_hand EmitObj::Bitcode => { debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out); if let Err(err) = link_or_copy(&bc_out, &obj_out) { - diag_handler.emit_err(CopyBitcode { err }); + dcx.emit_err(CopyBitcode { err }); } if !config.emit_bc { debug!("removing_bitcode {:?}", bc_out); - ensure_removed(diag_handler, &bc_out); + ensure_removed(dcx, &bc_out); } } @@ -148,7 +148,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, diag_hand )) } -pub(crate) fn link(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, mut _modules: Vec>) -> Result, FatalError> { +pub(crate) fn link(_cgcx: &CodegenContext, _dcx: &DiagCtxt, mut _modules: Vec>) -> Result, FatalError> { unimplemented!(); } diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs index 0261d5cd590..766d90cf724 100644 --- a/compiler/rustc_codegen_gcc/src/errors.rs +++ b/compiler/rustc_codegen_gcc/src/errors.rs @@ -112,8 +112,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); + fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.set_span(span); }; diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index cbe03f4051e..1f3f909d8b4 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -330,7 +330,7 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!() } - unsafe fn optimize(_cgcx: &CodegenContext, _diag_handler: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { + unsafe fn optimize(_cgcx: &CodegenContext, _dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig) -> Result<(), FatalError> { module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level)); Ok(()) } @@ -344,8 +344,8 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - unsafe fn codegen(cgcx: &CodegenContext, diag_handler: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { - back::write::codegen(cgcx, diag_handler, module, config) + unsafe fn codegen(cgcx: &CodegenContext, dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig) -> Result { + back::write::codegen(cgcx, dcx, module, config) } fn prepare_thin(_module: ModuleCodegen) -> (String, Self::ThinBuffer) { @@ -356,8 +356,8 @@ impl WriteBackendMethods for GccCodegenBackend { unimplemented!(); } - fn run_link(cgcx: &CodegenContext, diag_handler: &DiagCtxt, modules: Vec>) -> Result, FatalError> { - back::write::link(cgcx, diag_handler, modules) + fn run_link(cgcx: &CodegenContext, dcx: &DiagCtxt, modules: Vec>) -> Result, FatalError> { + back::write::link(cgcx, dcx, modules) } } diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 4d4b7402c99..7af97dca9cc 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -47,7 +47,7 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool { fn prepare_lto( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, ) -> Result<(Vec, Vec<(SerializedModule, CString)>), FatalError> { let export_threshold = match cgcx.lto { // We're just doing LTO for our one crate @@ -84,23 +84,23 @@ fn prepare_lto( // Make sure we actually can run LTO for crate_type in cgcx.crate_types.iter() { if !crate_type_allows_lto(*crate_type) { - diag_handler.emit_err(LtoDisallowed); + dcx.emit_err(LtoDisallowed); return Err(FatalError); } else if *crate_type == CrateType::Dylib { if !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(LtoDylib); + dcx.emit_err(LtoDylib); return Err(FatalError); } } else if *crate_type == CrateType::ProcMacro { if !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(LtoProcMacro); + dcx.emit_err(LtoProcMacro); return Err(FatalError); } } } if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto { - diag_handler.emit_err(DynamicLinkingWithLTO); + dcx.emit_err(DynamicLinkingWithLTO); return Err(FatalError); } @@ -138,7 +138,7 @@ fn prepare_lto( upstream_modules.push((module, CString::new(name).unwrap())); } Err(e) => { - diag_handler.emit_err(e); + dcx.emit_err(e); return Err(FatalError); } } @@ -250,7 +250,7 @@ pub(crate) fn prepare_thin(module: ModuleCodegen) -> (String, ThinBu fn fat_lto( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, modules: Vec>, cached_modules: Vec<(SerializedModule, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule, CString)>, @@ -316,7 +316,7 @@ fn fat_lto( let (buffer, name) = serialized_modules.remove(0); info!("no in-memory regular modules to choose from, parsing {:?}", name); ModuleCodegen { - module_llvm: ModuleLlvm::parse(cgcx, &name, buffer.data(), diag_handler)?, + module_llvm: ModuleLlvm::parse(cgcx, &name, buffer.data(), dcx)?, name: name.into_string().unwrap(), kind: ModuleKind::Regular, } @@ -333,13 +333,8 @@ fn fat_lto( // The linking steps below may produce errors and diagnostics within LLVM // which we'd like to handle and print, so set up our diagnostic handlers // (which get unregistered when they go out of scope below). - let _handler = DiagnosticHandlers::new( - cgcx, - diag_handler, - llcx, - &module, - CodegenDiagnosticsStage::LTO, - ); + let _handler = + DiagnosticHandlers::new(cgcx, dcx, llcx, &module, CodegenDiagnosticsStage::LTO); // For all other modules we codegened we'll need to link them into our own // bitcode. All modules were codegened in their own LLVM context, however, @@ -367,9 +362,7 @@ fn fat_lto( }); info!("linking {:?}", name); let data = bc_decoded.data(); - linker - .add(data) - .map_err(|()| write::llvm_err(diag_handler, LlvmError::LoadBitcode { name }))?; + linker.add(data).map_err(|()| write::llvm_err(dcx, LlvmError::LoadBitcode { name }))?; serialized_bitcode.push(bc_decoded); } drop(linker); @@ -452,7 +445,7 @@ impl Drop for Linker<'_> { /// they all go out of scope. fn thin_lto( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, modules: Vec<(String, ThinBuffer)>, serialized_modules: Vec<(SerializedModule, CString)>, cached_modules: Vec<(SerializedModule, WorkProduct)>, @@ -527,7 +520,7 @@ fn thin_lto( symbols_below_threshold.as_ptr(), symbols_below_threshold.len() as u32, ) - .ok_or_else(|| write::llvm_err(diag_handler, LlvmError::PrepareThinLtoContext))?; + .ok_or_else(|| write::llvm_err(dcx, LlvmError::PrepareThinLtoContext))?; let data = ThinData(data); @@ -599,7 +592,7 @@ fn thin_lto( // session, overwriting the previous serialized data (if any). if let Some(path) = key_map_path { if let Err(err) = curr_key_map.save_to_file(&path) { - return Err(write::llvm_err(diag_handler, LlvmError::WriteThinLtoKey { err })); + return Err(write::llvm_err(dcx, LlvmError::WriteThinLtoKey { err })); } } @@ -609,7 +602,7 @@ fn thin_lto( pub(crate) fn run_pass_manager( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: &mut ModuleCodegen, thin: bool, ) -> Result<(), FatalError> { @@ -637,7 +630,7 @@ pub(crate) fn run_pass_manager( } let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO }; let opt_level = config.opt_level.unwrap_or(config::OptLevel::No); - write::llvm_optimize(cgcx, diag_handler, module, config, opt_level, opt_stage)?; + write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage)?; } debug!("lto done"); Ok(()) @@ -868,10 +861,10 @@ pub fn parse_module<'a>( cx: &'a llvm::Context, name: &CStr, data: &[u8], - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, ) -> Result<&'a llvm::Module, FatalError> { unsafe { llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()) - .ok_or_else(|| write::llvm_err(diag_handler, LlvmError::ParseBitcode)) + .ok_or_else(|| write::llvm_err(dcx, LlvmError::ParseBitcode)) } } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index d01f7e1d665..773b8e7dc9f 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -45,15 +45,15 @@ use std::slice; use std::str; use std::sync::Arc; -pub fn llvm_err<'a>(handler: &rustc_errors::DiagCtxt, err: LlvmError<'a>) -> FatalError { +pub fn llvm_err<'a>(dcx: &rustc_errors::DiagCtxt, err: LlvmError<'a>) -> FatalError { match llvm::last_error() { - Some(llvm_err) => handler.emit_almost_fatal(WithLlvmError(err, llvm_err)), - None => handler.emit_almost_fatal(err), + Some(llvm_err) => dcx.emit_almost_fatal(WithLlvmError(err, llvm_err)), + None => dcx.emit_almost_fatal(err), } } pub fn write_output_file<'ll>( - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, target: &'ll llvm::TargetMachine, pm: &llvm::PassManager<'ll>, m: &'ll llvm::Module, @@ -93,9 +93,7 @@ pub fn write_output_file<'ll>( } } - result - .into_result() - .map_err(|()| llvm_err(handler, LlvmError::WriteOutput { path: output })) + result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteOutput { path: output })) } } @@ -340,7 +338,7 @@ pub struct DiagnosticHandlers<'a> { impl<'a> DiagnosticHandlers<'a> { pub fn new( cgcx: &'a CodegenContext, - handler: &'a DiagCtxt, + dcx: &'a DiagCtxt, llcx: &'a llvm::Context, module: &ModuleCodegen, stage: CodegenDiagnosticsStage, @@ -375,7 +373,7 @@ impl<'a> DiagnosticHandlers<'a> { .and_then(|dir| dir.to_str().and_then(|p| CString::new(p).ok())); let pgo_available = cgcx.opts.cg.profile_use.is_some(); - let data = Box::into_raw(Box::new((cgcx, handler))); + let data = Box::into_raw(Box::new((cgcx, dcx))); unsafe { let old_handler = llvm::LLVMRustContextGetDiagnosticHandler(llcx); llvm::LLVMRustContextConfigureDiagnosticHandler( @@ -507,7 +505,7 @@ fn get_instr_profile_output_path(config: &ModuleConfig) -> Option { pub(crate) unsafe fn llvm_optimize( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig, opt_level: config::OptLevel, @@ -588,13 +586,13 @@ pub(crate) unsafe fn llvm_optimize( llvm_plugins.as_ptr().cast(), llvm_plugins.len(), ); - result.into_result().map_err(|()| llvm_err(diag_handler, LlvmError::RunLlvmPasses)) + result.into_result().map_err(|()| llvm_err(dcx, LlvmError::RunLlvmPasses)) } // Unsafe due to LLVM calls. pub(crate) unsafe fn optimize( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig, ) -> Result<(), FatalError> { @@ -602,8 +600,7 @@ pub(crate) unsafe fn optimize( let llmod = module.module_llvm.llmod(); let llcx = &*module.module_llvm.llcx; - let _handlers = - DiagnosticHandlers::new(cgcx, diag_handler, llcx, module, CodegenDiagnosticsStage::Opt); + let _handlers = DiagnosticHandlers::new(cgcx, dcx, llcx, module, CodegenDiagnosticsStage::Opt); let module_name = module.name.clone(); let module_name = Some(&module_name[..]); @@ -621,14 +618,14 @@ pub(crate) unsafe fn optimize( _ if cgcx.opts.cg.linker_plugin_lto.enabled() => llvm::OptStage::PreLinkThinLTO, _ => llvm::OptStage::PreLinkNoLTO, }; - return llvm_optimize(cgcx, diag_handler, module, config, opt_level, opt_stage); + return llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage); } Ok(()) } pub(crate) fn link( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, mut modules: Vec>, ) -> Result, FatalError> { use super::lto::{Linker, ModuleBuffer}; @@ -641,9 +638,9 @@ pub(crate) fn link( for module in elements { let _timer = cgcx.prof.generic_activity_with_arg("LLVM_link_module", &*module.name); let buffer = ModuleBuffer::new(module.module_llvm.llmod()); - linker.add(buffer.data()).map_err(|()| { - llvm_err(diag_handler, LlvmError::SerializeModule { name: &module.name }) - })?; + linker + .add(buffer.data()) + .map_err(|()| llvm_err(dcx, LlvmError::SerializeModule { name: &module.name }))?; } drop(linker); Ok(modules.remove(0)) @@ -651,7 +648,7 @@ pub(crate) fn link( pub(crate) unsafe fn codegen( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig, ) -> Result { @@ -662,13 +659,8 @@ pub(crate) unsafe fn codegen( let tm = &*module.module_llvm.tm; let module_name = module.name.clone(); let module_name = Some(&module_name[..]); - let _handlers = DiagnosticHandlers::new( - cgcx, - diag_handler, - llcx, - &module, - CodegenDiagnosticsStage::Codegen, - ); + let _handlers = + DiagnosticHandlers::new(cgcx, dcx, llcx, &module, CodegenDiagnosticsStage::Codegen); if cgcx.msvc_imps_needed { create_msvc_imps(cgcx, llcx, llmod); @@ -726,7 +718,7 @@ pub(crate) unsafe fn codegen( .prof .generic_activity_with_arg("LLVM_module_codegen_emit_bitcode", &*module.name); if let Err(err) = fs::write(&bc_out, data) { - diag_handler.emit_err(WriteBytecode { path: &bc_out, err }); + dcx.emit_err(WriteBytecode { path: &bc_out, err }); } } @@ -776,9 +768,7 @@ pub(crate) unsafe fn codegen( record_artifact_size(&cgcx.prof, "llvm_ir", &out); } - result - .into_result() - .map_err(|()| llvm_err(diag_handler, LlvmError::WriteIr { path: &out }))?; + result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteIr { path: &out }))?; } if config.emit_asm { @@ -797,7 +787,7 @@ pub(crate) unsafe fn codegen( }; with_codegen(tm, llmod, |cpm| { write_output_file( - diag_handler, + dcx, tm, cpm, llmod, @@ -832,7 +822,7 @@ pub(crate) unsafe fn codegen( with_codegen(tm, llmod, |cpm| { write_output_file( - diag_handler, + dcx, tm, cpm, llmod, @@ -847,12 +837,12 @@ pub(crate) unsafe fn codegen( EmitObj::Bitcode => { debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out); if let Err(err) = link_or_copy(&bc_out, &obj_out) { - diag_handler.emit_err(CopyBitcode { err }); + dcx.emit_err(CopyBitcode { err }); } if !config.emit_bc { debug!("removing_bitcode {:?}", bc_out); - ensure_removed(diag_handler, &bc_out); + ensure_removed(dcx, &bc_out); } } diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 12feb4d1b4a..671a225259a 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -102,13 +102,12 @@ pub(crate) struct DynamicLinkingWithLTO; pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>); impl IntoDiagnostic<'_, FatalError> for ParseTargetMachineConfig<'_> { - fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, FatalError> { - let diag: DiagnosticBuilder<'_, FatalError> = self.0.into_diagnostic(handler); + fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, FatalError> { + let diag: DiagnosticBuilder<'_, FatalError> = self.0.into_diagnostic(dcx); let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message"); - let message = handler.eagerly_translate_to_string(message.clone(), diag.args()); + let message = dcx.eagerly_translate_to_string(message.clone(), diag.args()); - let mut diag = - handler.struct_almost_fatal(fluent::codegen_llvm_parse_target_machine_config); + let mut diag = dcx.struct_almost_fatal(fluent::codegen_llvm_parse_target_machine_config); diag.set_arg("error", message); diag } @@ -125,8 +124,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable); + fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = dcx.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable); if let Some(span) = self.span { diag.set_span(span); }; @@ -185,7 +184,7 @@ pub enum LlvmError<'a> { pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String); impl IntoDiagnostic<'_, G> for WithLlvmError<'_> { - fn into_diagnostic(self, handler: &'_ DiagCtxt) -> DiagnosticBuilder<'_, G> { + fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, G> { use LlvmError::*; let msg_with_llvm_err = match &self.0 { WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err, @@ -202,7 +201,7 @@ impl IntoDiagnostic<'_, G> for WithLlvmError<'_> { PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err, ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err, }; - let mut diag = self.0.into_diagnostic(handler); + let mut diag = self.0.into_diagnostic(dcx); diag.set_primary_message(msg_with_llvm_err); diag.set_arg("llvm_err", self.1); diag diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 91fd8548124..1a6f4a2ec55 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -200,10 +200,10 @@ impl WriteBackendMethods for LlvmCodegenBackend { } fn run_link( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, modules: Vec>, ) -> Result, FatalError> { - back::write::link(cgcx, diag_handler, modules) + back::write::link(cgcx, dcx, modules) } fn run_fat_lto( cgcx: &CodegenContext, @@ -221,11 +221,11 @@ impl WriteBackendMethods for LlvmCodegenBackend { } unsafe fn optimize( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig, ) -> Result<(), FatalError> { - back::write::optimize(cgcx, diag_handler, module, config) + back::write::optimize(cgcx, dcx, module, config) } fn optimize_fat( cgcx: &CodegenContext, @@ -242,11 +242,11 @@ impl WriteBackendMethods for LlvmCodegenBackend { } unsafe fn codegen( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig, ) -> Result { - back::write::codegen(cgcx, diag_handler, module, config) + back::write::codegen(cgcx, dcx, module, config) } fn prepare_thin(module: ModuleCodegen) -> (String, Self::ThinBuffer) { back::lto::prepare_thin(module) @@ -447,16 +447,16 @@ impl ModuleLlvm { cgcx: &CodegenContext, name: &CStr, buffer: &[u8], - handler: &DiagCtxt, + dcx: &DiagCtxt, ) -> Result { unsafe { let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names); - let llmod_raw = back::lto::parse_module(llcx, name, buffer, handler)?; + let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx)?; let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, name.to_str().unwrap()); let tm = match (cgcx.tm_factory)(tm_factory_config) { Ok(m) => m, Err(e) => { - return Err(handler.emit_almost_fatal(ParseTargetMachineConfig(e))); + return Err(dcx.emit_almost_fatal(ParseTargetMachineConfig(e))); } }; diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 289b61742ab..b32865a0518 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -52,10 +52,10 @@ use std::path::{Path, PathBuf}; use std::process::{ExitStatus, Output, Stdio}; use std::{env, fmt, fs, io, mem, str}; -pub fn ensure_removed(diag_handler: &DiagCtxt, path: &Path) { +pub fn ensure_removed(dcx: &DiagCtxt, path: &Path) { if let Err(e) = fs::remove_file(path) { if e.kind() != io::ErrorKind::NotFound { - diag_handler.err(format!("failed to remove {}: {}", path.display(), e)); + dcx.err(format!("failed to remove {}: {}", path.display(), e)); } } } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index d8958264458..668d39afbda 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -210,192 +210,191 @@ pub enum LinkRlibError { pub struct ThorinErrorWrapper(pub thorin::Error); impl IntoDiagnostic<'_> for ThorinErrorWrapper { - fn into_diagnostic(self, handler: &DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + fn into_diagnostic(self, dcx: &DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag; match self.0 { thorin::Error::ReadInput(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_read_input_failure); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_read_input_failure); diag } thorin::Error::ParseFileKind(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_file_kind); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_input_file_kind); diag } thorin::Error::ParseObjectFile(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_object_file); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_input_object_file); diag } thorin::Error::ParseArchiveFile(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_archive_file); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_input_archive_file); diag } thorin::Error::ParseArchiveMember(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_archive_member); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_archive_member); diag } thorin::Error::InvalidInputKind => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_invalid_input_kind); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_invalid_input_kind); diag } thorin::Error::DecompressData(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_decompress_data); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_decompress_data); diag } thorin::Error::NamelessSection(_, offset) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_section_without_name); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_section_without_name); diag.set_arg("offset", format!("0x{offset:08x}")); diag } thorin::Error::RelocationWithInvalidSymbol(section, offset) => { - diag = - handler.struct_err(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol); diag.set_arg("section", section); diag.set_arg("offset", format!("0x{offset:08x}")); diag } thorin::Error::MultipleRelocations(section, offset) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_relocations); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_multiple_relocations); diag.set_arg("section", section); diag.set_arg("offset", format!("0x{offset:08x}")); diag } thorin::Error::UnsupportedRelocation(section, offset) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_unsupported_relocation); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_unsupported_relocation); diag.set_arg("section", section); diag.set_arg("offset", format!("0x{offset:08x}")); diag } thorin::Error::MissingDwoName(id) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_dwo_name); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_missing_dwo_name); diag.set_arg("id", format!("0x{id:08x}")); diag } thorin::Error::NoCompilationUnits => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_no_compilation_units); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_no_compilation_units); diag } thorin::Error::NoDie => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_no_die); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_no_die); diag } thorin::Error::TopLevelDieNotUnit => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_top_level_die_not_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_top_level_die_not_unit); diag } thorin::Error::MissingRequiredSection(section) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_required_section); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_missing_required_section); diag.set_arg("section", section); diag } thorin::Error::ParseUnitAbbreviations(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_abbreviations); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_unit_abbreviations); diag } thorin::Error::ParseUnitAttribute(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_attribute); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_unit_attribute); diag } thorin::Error::ParseUnitHeader(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_header); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_unit_header); diag } thorin::Error::ParseUnit(_) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_unit); diag } thorin::Error::IncompatibleIndexVersion(section, format, actual) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_incompatible_index_version); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_incompatible_index_version); diag.set_arg("section", section); diag.set_arg("actual", actual); diag.set_arg("format", format); diag } thorin::Error::OffsetAtIndex(_, index) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_offset_at_index); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_offset_at_index); diag.set_arg("index", index); diag } thorin::Error::StrAtOffset(_, offset) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_str_at_offset); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_str_at_offset); diag.set_arg("offset", format!("0x{offset:08x}")); diag } thorin::Error::ParseIndex(_, section) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_index); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_parse_index); diag.set_arg("section", section); diag } thorin::Error::UnitNotInIndex(unit) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_unit_not_in_index); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_unit_not_in_index); diag.set_arg("unit", format!("0x{unit:08x}")); diag } thorin::Error::RowNotInIndex(_, row) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_row_not_in_index); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_row_not_in_index); diag.set_arg("row", row); diag } thorin::Error::SectionNotInRow => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_section_not_in_row); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_section_not_in_row); diag } thorin::Error::EmptyUnit(unit) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_empty_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_empty_unit); diag.set_arg("unit", format!("0x{unit:08x}")); diag } thorin::Error::MultipleDebugInfoSection => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_debug_info_section); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_multiple_debug_info_section); diag } thorin::Error::MultipleDebugTypesSection => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_debug_types_section); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_multiple_debug_types_section); diag } thorin::Error::NotSplitUnit => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_not_split_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_not_split_unit); diag } thorin::Error::DuplicateUnit(unit) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_duplicate_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_duplicate_unit); diag.set_arg("unit", format!("0x{unit:08x}")); diag } thorin::Error::MissingReferencedUnit(unit) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_referenced_unit); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_missing_referenced_unit); diag.set_arg("unit", format!("0x{unit:08x}")); diag } thorin::Error::NoOutputObjectCreated => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_not_output_object_created); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_not_output_object_created); diag } thorin::Error::MixedInputEncodings => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_mixed_input_encodings); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_mixed_input_encodings); diag } thorin::Error::Io(e) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_io); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_io); diag.set_arg("error", format!("{e}")); diag } thorin::Error::ObjectRead(e) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_object_read); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_object_read); diag.set_arg("error", format!("{e}")); diag } thorin::Error::ObjectWrite(e) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_object_write); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_object_write); diag.set_arg("error", format!("{e}")); diag } thorin::Error::GimliRead(e) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_gimli_read); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_gimli_read); diag.set_arg("error", format!("{e}")); diag } thorin::Error::GimliWrite(e) => { - diag = handler.struct_err(fluent::codegen_ssa_thorin_gimli_write); + diag = dcx.struct_err(fluent::codegen_ssa_thorin_gimli_write); diag.set_arg("error", format!("{e}")); diag } @@ -412,8 +411,8 @@ pub struct LinkingFailed<'a> { } impl IntoDiagnostic<'_> for LinkingFailed<'_> { - fn into_diagnostic(self, handler: &DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::codegen_ssa_linking_failed); + fn into_diagnostic(self, dcx: &DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = dcx.struct_err(fluent::codegen_ssa_linking_failed); diag.set_arg("linker_path", format!("{}", self.linker_path.display())); diag.set_arg("exit_status", format!("{}", self.exit_status)); diff --git a/compiler/rustc_codegen_ssa/src/traits/write.rs b/compiler/rustc_codegen_ssa/src/traits/write.rs index b8a63d259ec..048540894ac 100644 --- a/compiler/rustc_codegen_ssa/src/traits/write.rs +++ b/compiler/rustc_codegen_ssa/src/traits/write.rs @@ -16,7 +16,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { /// Merge all modules into main_module and returning it fn run_link( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, modules: Vec>, ) -> Result, FatalError>; /// Performs fat LTO by merging all modules into a single one and returning it @@ -38,7 +38,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { fn print_statistics(&self); unsafe fn optimize( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: &ModuleCodegen, config: &ModuleConfig, ) -> Result<(), FatalError>; @@ -52,7 +52,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { ) -> Result, FatalError>; unsafe fn codegen( cgcx: &CodegenContext, - diag_handler: &DiagCtxt, + dcx: &DiagCtxt, module: ModuleCodegen, config: &ModuleConfig, ) -> Result; diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index f52d5f12318..6aa673f5603 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -432,11 +432,7 @@ pub struct UndefinedBehavior { pub trait ReportErrorExt { /// Returns the diagnostic message for this error. fn diagnostic_message(&self) -> DiagnosticMessage; - fn add_args( - self, - handler: &DiagCtxt, - builder: &mut DiagnosticBuilder<'_, G>, - ); + fn add_args(self, dcx: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>); fn debug(self) -> String where @@ -454,7 +450,7 @@ pub trait ReportErrorExt { } } -fn bad_pointer_message(msg: CheckInAllocMsg, handler: &DiagCtxt) -> String { +fn bad_pointer_message(msg: CheckInAllocMsg, dcx: &DiagCtxt) -> String { use crate::fluent_generated::*; let msg = match msg { @@ -464,7 +460,7 @@ fn bad_pointer_message(msg: CheckInAllocMsg, handler: &DiagCtxt) -> String { CheckInAllocMsg::InboundsTest => const_eval_in_bounds_test, }; - handler.eagerly_translate_to_string(msg, [].into_iter()) + dcx.eagerly_translate_to_string(msg, [].into_iter()) } impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { @@ -514,7 +510,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { fn add_args( self, - handler: &DiagCtxt, + dcx: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>, ) { use UndefinedBehaviorInfo::*; @@ -525,7 +521,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { builder.set_arg(name, value); }); } - ValidationError(e) => e.add_args(handler, builder), + ValidationError(e) => e.add_args(dcx, builder), Unreachable | DivisionByZero @@ -549,7 +545,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { PointerUseAfterFree(alloc_id, msg) => { builder .set_arg("alloc_id", alloc_id) - .set_arg("bad_pointer_message", bad_pointer_message(msg, handler)); + .set_arg("bad_pointer_message", bad_pointer_message(msg, dcx)); } PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, ptr_size, msg } => { builder @@ -557,14 +553,14 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { .set_arg("alloc_size", alloc_size.bytes()) .set_arg("ptr_offset", ptr_offset) .set_arg("ptr_size", ptr_size.bytes()) - .set_arg("bad_pointer_message", bad_pointer_message(msg, handler)); + .set_arg("bad_pointer_message", bad_pointer_message(msg, dcx)); } DanglingIntPointer(ptr, msg) => { if ptr != 0 { builder.set_arg("pointer", format!("{ptr:#x}[noalloc]")); } - builder.set_arg("bad_pointer_message", bad_pointer_message(msg, handler)); + builder.set_arg("bad_pointer_message", bad_pointer_message(msg, dcx)); } AlignmentCheckFailed(Misalignment { required, has }, msg) => { builder.set_arg("required", required.bytes()); @@ -678,11 +674,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { } } - fn add_args( - self, - handler: &DiagCtxt, - err: &mut DiagnosticBuilder<'_, G>, - ) { + fn add_args(self, dcx: &DiagCtxt, err: &mut DiagnosticBuilder<'_, G>) { use crate::fluent_generated as fluent; use rustc_middle::mir::interpret::ValidationErrorKind::*; @@ -692,12 +684,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { } let message = if let Some(path) = self.path { - handler.eagerly_translate_to_string( + dcx.eagerly_translate_to_string( fluent::const_eval_validation_front_matter_invalid_value_with_path, [("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)), ) } else { - handler.eagerly_translate_to_string( + dcx.eagerly_translate_to_string( fluent::const_eval_validation_front_matter_invalid_value, [].into_iter(), ) @@ -708,7 +700,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { fn add_range_arg( r: WrappingRange, max_hi: u128, - handler: &DiagCtxt, + dcx: &DiagCtxt, err: &mut DiagnosticBuilder<'_, G>, ) { let WrappingRange { start: lo, end: hi } = r; @@ -732,7 +724,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { ("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())), ]; let args = args.iter().map(|(a, b)| (a, b)); - let message = handler.eagerly_translate_to_string(msg, args); + let message = dcx.eagerly_translate_to_string(msg, args); err.set_arg("in_range", message); } @@ -754,7 +746,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { ExpectedKind::EnumTag => fluent::const_eval_validation_expected_enum_tag, ExpectedKind::Str => fluent::const_eval_validation_expected_str, }; - let msg = handler.eagerly_translate_to_string(msg, [].into_iter()); + let msg = dcx.eagerly_translate_to_string(msg, [].into_iter()); err.set_arg("expected", msg); } InvalidEnumTag { value } @@ -765,11 +757,11 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { err.set_arg("value", value); } NullablePtrOutOfRange { range, max_value } | PtrOutOfRange { range, max_value } => { - add_range_arg(range, max_value, handler, err) + add_range_arg(range, max_value, dcx, err) } OutOfRange { range, max_value, value } => { err.set_arg("value", value); - add_range_arg(range, max_value, handler, err); + add_range_arg(range, max_value, dcx, err); } UnalignedPtr { required_bytes, found_bytes, .. } => { err.set_arg("required_bytes", required_bytes); @@ -843,14 +835,14 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> { } fn add_args( self, - handler: &DiagCtxt, + dcx: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>, ) { match self { - InterpError::UndefinedBehavior(ub) => ub.add_args(handler, builder), - InterpError::Unsupported(e) => e.add_args(handler, builder), - InterpError::InvalidProgram(e) => e.add_args(handler, builder), - InterpError::ResourceExhaustion(e) => e.add_args(handler, builder), + InterpError::UndefinedBehavior(ub) => ub.add_args(dcx, builder), + InterpError::Unsupported(e) => e.add_args(dcx, builder), + InterpError::InvalidProgram(e) => e.add_args(dcx, builder), + InterpError::ResourceExhaustion(e) => e.add_args(dcx, builder), InterpError::MachineStop(e) => e.add_args(&mut |name, value| { builder.set_arg(name, value); }), @@ -875,7 +867,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> { } fn add_args( self, - handler: &DiagCtxt, + dcx: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>, ) { match self { @@ -883,7 +875,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> { | InvalidProgramInfo::AlreadyReported(_) | InvalidProgramInfo::ConstPropNonsense => {} InvalidProgramInfo::Layout(e) => { - let diag: DiagnosticBuilder<'_, ()> = e.into_diagnostic().into_diagnostic(handler); + let diag: DiagnosticBuilder<'_, ()> = e.into_diagnostic().into_diagnostic(dcx); for (name, val) in diag.args() { builder.set_arg(name.clone(), val.clone()); } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 7ae90dd07be..be506806065 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -886,13 +886,13 @@ impl Diagnostic { /// interpolated variables). pub fn eager_subdiagnostic( &mut self, - handler: &crate::DiagCtxt, + dcx: &crate::DiagCtxt, subdiagnostic: impl AddToDiagnostic, ) -> &mut Self { subdiagnostic.add_to_diagnostic_with(self, |diag, msg| { let args = diag.args(); let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); - handler.eagerly_translate(msg, args) + dcx.eagerly_translate(msg, args) }); self } diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index c2043d234ae..f681a64ef06 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -21,7 +21,7 @@ use std::thread::panicking; pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `DiagCtxt`. #[must_use] - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, G>; + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, G>; } impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned @@ -29,8 +29,8 @@ where T: IntoDiagnostic<'a, G>, G: EmissionGuarantee, { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, G> { - let mut diag = self.node.into_diagnostic(handler); + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, G> { + let mut diag = self.node.into_diagnostic(dcx); diag.set_span(self.span); diag } @@ -110,7 +110,7 @@ pub trait EmissionGuarantee: Sized { /// Creates a new `DiagnosticBuilder` that will return this type of guarantee. #[track_caller] fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self>; } @@ -166,10 +166,10 @@ impl EmissionGuarantee for ErrorGuaranteed { #[track_caller] fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Error { lint: false }, msg) + DiagnosticBuilder::new(dcx, Level::Error { lint: false }, msg) } } @@ -189,10 +189,10 @@ impl EmissionGuarantee for () { } fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Warning(None), msg) + DiagnosticBuilder::new(dcx, Level::Warning(None), msg) } } @@ -217,10 +217,10 @@ impl EmissionGuarantee for Noted { } fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Note, msg) + DiagnosticBuilder::new(dcx, Level::Note, msg) } } @@ -246,10 +246,10 @@ impl EmissionGuarantee for Bug { } fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Bug, msg) + DiagnosticBuilder::new(dcx, Level::Bug, msg) } } @@ -270,10 +270,10 @@ impl EmissionGuarantee for ! { } fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Fatal, msg) + DiagnosticBuilder::new(dcx, Level::Fatal, msg) } } @@ -294,10 +294,10 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError { } fn make_diagnostic_builder( - handler: &DiagCtxt, + dcx: &DiagCtxt, msg: impl Into, ) -> DiagnosticBuilder<'_, Self> { - DiagnosticBuilder::new(handler, Level::Fatal, msg) + DiagnosticBuilder::new(dcx, Level::Fatal, msg) } } @@ -343,22 +343,22 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { /// `struct_*` methods on [`DiagCtxt`]. #[track_caller] pub(crate) fn new>( - handler: &'a DiagCtxt, + dcx: &'a DiagCtxt, level: Level, message: M, ) -> Self { let diagnostic = Diagnostic::new(level, message); - Self::new_diagnostic(handler, diagnostic) + Self::new_diagnostic(dcx, diagnostic) } /// Creates a new `DiagnosticBuilder` with an already constructed /// diagnostic. #[track_caller] - pub(crate) fn new_diagnostic(handler: &'a DiagCtxt, diagnostic: Diagnostic) -> Self { + pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diagnostic: Diagnostic) -> Self { debug!("Created new diagnostic"); Self { inner: DiagnosticBuilderInner { - state: DiagnosticBuilderState::Emittable(handler), + state: DiagnosticBuilderState::Emittable(dcx), diagnostic: Box::new(diagnostic), }, _marker: PhantomData, diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index b379d683c96..3e4b3ee758a 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -246,18 +246,18 @@ impl IntoDiagnosticArg for hir::def::Res { } impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { - fn into_diagnostic(self, handler: &DiagCtxt) -> DiagnosticBuilder<'_, !> { + fn into_diagnostic(self, dcx: &DiagCtxt) -> DiagnosticBuilder<'_, !> { let mut diag; match self { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { - diag = handler.struct_fatal(fluent::errors_target_invalid_address_space); + diag = dcx.struct_fatal(fluent::errors_target_invalid_address_space); diag.set_arg("addr_space", addr_space); diag.set_arg("cause", cause); diag.set_arg("err", err); diag } TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { - diag = handler.struct_fatal(fluent::errors_target_invalid_bits); + diag = dcx.struct_fatal(fluent::errors_target_invalid_bits); diag.set_arg("kind", kind); diag.set_arg("bit", bit); diag.set_arg("cause", cause); @@ -265,31 +265,31 @@ impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { diag } TargetDataLayoutErrors::MissingAlignment { cause } => { - diag = handler.struct_fatal(fluent::errors_target_missing_alignment); + diag = dcx.struct_fatal(fluent::errors_target_missing_alignment); diag.set_arg("cause", cause); diag } TargetDataLayoutErrors::InvalidAlignment { cause, err } => { - diag = handler.struct_fatal(fluent::errors_target_invalid_alignment); + diag = dcx.struct_fatal(fluent::errors_target_invalid_alignment); diag.set_arg("cause", cause); diag.set_arg("err_kind", err.diag_ident()); diag.set_arg("align", err.align()); diag } TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { - diag = handler.struct_fatal(fluent::errors_target_inconsistent_architecture); + diag = dcx.struct_fatal(fluent::errors_target_inconsistent_architecture); diag.set_arg("dl", dl); diag.set_arg("target", target); diag } TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { - diag = handler.struct_fatal(fluent::errors_target_inconsistent_pointer_width); + diag = dcx.struct_fatal(fluent::errors_target_inconsistent_pointer_width); diag.set_arg("pointer_size", pointer_size); diag.set_arg("target", target); diag } TargetDataLayoutErrors::InvalidBitsSize { err } => { - diag = handler.struct_fatal(fluent::errors_target_invalid_bits_size); + diag = dcx.struct_fatal(fluent::errors_target_invalid_bits_size); diag.set_arg("err", err); diag } diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 30a1095be52..b63609c48e9 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1350,7 +1350,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt<'_>, tts: TokenStream) -> Option Option<(Symbol, Vec)> { @@ -1359,23 +1359,23 @@ pub fn parse_macro_name_and_helper_attrs( // `#[proc_macro_derive(Foo, attributes(A, ..))]` let list = attr.meta_item_list()?; if list.len() != 1 && list.len() != 2 { - diag.emit_err(errors::AttrNoArguments { span: attr.span }); + dcx.emit_err(errors::AttrNoArguments { span: attr.span }); return None; } let Some(trait_attr) = list[0].meta_item() else { - diag.emit_err(errors::NotAMetaItem { span: list[0].span() }); + dcx.emit_err(errors::NotAMetaItem { span: list[0].span() }); return None; }; let trait_ident = match trait_attr.ident() { Some(trait_ident) if trait_attr.is_word() => trait_ident, _ => { - diag.emit_err(errors::OnlyOneWord { span: trait_attr.span }); + dcx.emit_err(errors::OnlyOneWord { span: trait_attr.span }); return None; } }; if !trait_ident.name.can_be_raw() { - diag.emit_err(errors::CannotBeNameOfMacro { + dcx.emit_err(errors::CannotBeNameOfMacro { span: trait_attr.span, trait_ident, macro_type, @@ -1385,29 +1385,29 @@ pub fn parse_macro_name_and_helper_attrs( let attributes_attr = list.get(1); let proc_attrs: Vec<_> = if let Some(attr) = attributes_attr { if !attr.has_name(sym::attributes) { - diag.emit_err(errors::ArgumentNotAttributes { span: attr.span() }); + dcx.emit_err(errors::ArgumentNotAttributes { span: attr.span() }); } attr.meta_item_list() .unwrap_or_else(|| { - diag.emit_err(errors::AttributesWrongForm { span: attr.span() }); + dcx.emit_err(errors::AttributesWrongForm { span: attr.span() }); &[] }) .iter() .filter_map(|attr| { let Some(attr) = attr.meta_item() else { - diag.emit_err(errors::AttributeMetaItem { span: attr.span() }); + dcx.emit_err(errors::AttributeMetaItem { span: attr.span() }); return None; }; let ident = match attr.ident() { Some(ident) if attr.is_word() => ident, _ => { - diag.emit_err(errors::AttributeSingleWord { span: attr.span }); + dcx.emit_err(errors::AttributeSingleWord { span: attr.span }); return None; } }; if !ident.name.can_be_raw() { - diag.emit_err(errors::HelperAttributeNameInvalid { + dcx.emit_err(errors::HelperAttributeNameInvalid { span: attr.span, name: ident, }); diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index a90d2643a51..f461b6a94ec 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -317,8 +317,8 @@ pub struct MissingTypeParams { // Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`. impl<'a> IntoDiagnostic<'a> for MissingTypeParams { #[track_caller] - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut err = handler.struct_span_err_with_code( + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + let mut err = dcx.struct_span_err_with_code( self.span, fluent::hir_analysis_missing_type_params, error_code!(E0393), diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index a46b0e51f75..d86c5e91c47 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -42,7 +42,7 @@ pub struct Compiler { } /// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`. -pub(crate) fn parse_cfg(handler: &DiagCtxt, cfgs: Vec) -> Cfg { +pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { let sess = ParseSess::with_silent_emitter(Some(format!( @@ -54,12 +54,11 @@ pub(crate) fn parse_cfg(handler: &DiagCtxt, cfgs: Vec) -> Cfg { ($reason: expr) => { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - handler - .struct_fatal(format!( - concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), - s - )) - .emit(); + dcx.struct_fatal(format!( + concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), + s + )) + .emit(); }; } @@ -101,7 +100,7 @@ pub(crate) fn parse_cfg(handler: &DiagCtxt, cfgs: Vec) -> Cfg { } /// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`. -pub(crate) fn parse_check_cfg(handler: &DiagCtxt, specs: Vec) -> CheckCfg { +pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec) -> CheckCfg { // If any --check-cfg is passed then exhaustive_values and exhaustive_names // are enabled by default. let exhaustive_names = !specs.is_empty(); @@ -118,12 +117,11 @@ pub(crate) fn parse_check_cfg(handler: &DiagCtxt, specs: Vec) -> CheckCf ($reason:expr) => { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - handler - .struct_fatal(format!( - concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"), - s - )) - .emit() + dcx.struct_fatal(format!( + concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"), + s + )) + .emit() }; } @@ -433,7 +431,7 @@ pub fn run_compiler(config: Config, f: impl FnOnce(&Compiler) -> R + Se } pub fn try_print_query_stack( - handler: &DiagCtxt, + dcx: &DiagCtxt, num_frames: Option, file: Option, ) { @@ -447,7 +445,7 @@ pub fn try_print_query_stack( ty::print::with_no_queries!(print_query_stack( QueryCtxt::new(icx.tcx), icx.query, - handler, + dcx, num_frames, file, )) diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index e1379bada52..206c15edd78 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -498,9 +498,9 @@ pub(crate) struct MultipleCandidates { impl IntoDiagnostic<'_> for MultipleCandidates { fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::metadata_multiple_candidates); + let mut diag = dcx.struct_err(fluent::metadata_multiple_candidates); diag.set_arg("crate_name", self.crate_name); diag.set_arg("flavor", self.flavor); diag.code(error_code!(E0464)); @@ -597,9 +597,9 @@ impl IntoDiagnostic<'_> for InvalidMetadataFiles { #[track_caller] fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::metadata_invalid_meta_files); + let mut diag = dcx.struct_err(fluent::metadata_invalid_meta_files); diag.set_arg("crate_name", self.crate_name); diag.set_arg("add_info", self.add_info); diag.code(error_code!(E0786)); @@ -627,9 +627,9 @@ impl IntoDiagnostic<'_> for CannotFindCrate { #[track_caller] fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::metadata_cannot_find_crate); + let mut diag = dcx.struct_err(fluent::metadata_cannot_find_crate); diag.set_arg("crate_name", self.crate_name); diag.set_arg("current_crate", self.current_crate); diag.set_arg("add_info", self.add_info); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 451bbb883be..225dd217807 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1273,13 +1273,13 @@ pub enum FnAbiError<'tcx> { } impl<'a, 'b> IntoDiagnostic<'a, !> for FnAbiError<'b> { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, !> { + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, !> { match self { - Self::Layout(e) => e.into_diagnostic().into_diagnostic(handler), + Self::Layout(e) => e.into_diagnostic().into_diagnostic(dcx), Self::AdjustForForeignAbi(call::AdjustForForeignAbiError::Unsupported { arch, abi, - }) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diagnostic(handler), + }) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diagnostic(dcx), } } } diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 9f3e04f1292..db2624cac02 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -461,8 +461,8 @@ pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> { } impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> { - fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_span_err_with_code( + fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = dcx.struct_span_err_with_code( self.span, fluent::mir_build_non_exhaustive_patterns_type_not_empty, error_code!(E0004), diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index 25d73904e7c..a09db02de90 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -64,15 +64,12 @@ pub(crate) struct RequiresUnsafe { // but this would result in a lot of duplication. impl<'sess> IntoDiagnostic<'sess> for RequiresUnsafe { #[track_caller] - fn into_diagnostic( - self, - handler: &'sess DiagCtxt, - ) -> DiagnosticBuilder<'sess, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::mir_transform_requires_unsafe); + fn into_diagnostic(self, dcx: &'sess DiagCtxt) -> DiagnosticBuilder<'sess, ErrorGuaranteed> { + let mut diag = dcx.struct_err(fluent::mir_transform_requires_unsafe); diag.code(rustc_errors::DiagnosticId::Error("E0133".to_string())); diag.set_span(self.span); diag.span_label(self.span, self.details.label()); - let desc = handler.eagerly_translate_to_string(self.details.label(), [].into_iter()); + let desc = dcx.eagerly_translate_to_string(self.details.label(), [].into_iter()); diag.set_arg("details", desc); diag.set_arg("op_in_unsafe_fn_allowed", self.op_in_unsafe_fn_allowed); self.details.add_subdiagnostics(&mut diag); diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index f4361aded89..247b2245583 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -51,9 +51,9 @@ impl IntoDiagnostic<'_> for UnusedGenericParamsHint { #[track_caller] fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::monomorphize_unused_generic_params); + let mut diag = dcx.struct_err(fluent::monomorphize_unused_generic_params); diag.set_span(self.span); for (span, name) in self.param_spans.into_iter().zip(self.param_names) { // FIXME: I can figure out how to do a label with a fluent string with a fixed message, diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 2806416c16d..008adcc83d0 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1042,11 +1042,11 @@ impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier { #[track_caller] fn into_diagnostic( self, - handler: &'a rustc_errors::DiagCtxt, + dcx: &'a rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = handler.struct_err(match token_descr { + let mut diag = dcx.struct_err(match token_descr { Some(TokenDescription::ReservedIdentifier) => { fluent::parse_expected_identifier_found_reserved_identifier_str } @@ -1099,11 +1099,11 @@ impl<'a> IntoDiagnostic<'a> for ExpectedSemi { #[track_caller] fn into_diagnostic( self, - handler: &'a rustc_errors::DiagCtxt, + dcx: &'a rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = handler.struct_err(match token_descr { + let mut diag = dcx.struct_err(match token_descr { Some(TokenDescription::ReservedIdentifier) => { fluent::parse_expected_semi_found_reserved_identifier_str } diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index d384db77107..775082adbe8 100644 --- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs +++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs @@ -10,7 +10,7 @@ use rustc_span::{BytePos, Span}; use crate::errors::{MoreThanOneCharNote, MoreThanOneCharSugg, NoBraceUnicodeSub, UnescapeError}; pub(crate) fn emit_unescape_error( - handler: &DiagCtxt, + dcx: &DiagCtxt, // interior part of the literal, between quotes lit: &str, // full span of the literal, including quotes and any prefix @@ -33,12 +33,10 @@ pub(crate) fn emit_unescape_error( }; match error { EscapeError::LoneSurrogateUnicodeEscape => { - handler - .emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: true }); + dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: true }); } EscapeError::OutOfRangeUnicodeEscape => { - handler - .emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: false }); + dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: false }); } EscapeError::MoreThanOneChar => { use unicode_normalization::{char::is_combining_mark, UnicodeNormalization}; @@ -104,7 +102,7 @@ pub(crate) fn emit_unescape_error( sugg, } }); - handler.emit_err(UnescapeError::MoreThanOneChar { + dcx.emit_err(UnescapeError::MoreThanOneChar { span: full_lit_span, note, suggestion: sugg, @@ -112,7 +110,7 @@ pub(crate) fn emit_unescape_error( } EscapeError::EscapeOnlyChar => { let (c, char_span) = last_char(); - handler.emit_err(UnescapeError::EscapeOnlyChar { + dcx.emit_err(UnescapeError::EscapeOnlyChar { span: err_span, char_span, escaped_sugg: c.escape_default().to_string(), @@ -122,11 +120,11 @@ pub(crate) fn emit_unescape_error( } EscapeError::BareCarriageReturn => { let double_quotes = mode.in_double_quotes(); - handler.emit_err(UnescapeError::BareCr { span: err_span, double_quotes }); + dcx.emit_err(UnescapeError::BareCr { span: err_span, double_quotes }); } EscapeError::BareCarriageReturnInRawString => { assert!(mode.in_double_quotes()); - handler.emit_err(UnescapeError::BareCrRawString(err_span)); + dcx.emit_err(UnescapeError::BareCrRawString(err_span)); } EscapeError::InvalidEscape => { let (c, span) = last_char(); @@ -137,7 +135,7 @@ pub(crate) fn emit_unescape_error( "unknown character escape" }; let ec = escaped_char(c); - let mut diag = handler.struct_span_err(span, format!("{label}: `{ec}`")); + let mut diag = dcx.struct_span_err(span, format!("{label}: `{ec}`")); diag.span_label(span, label); if c == '{' || c == '}' && matches!(mode, Mode::Str | Mode::RawStr) { diag.help( @@ -166,13 +164,13 @@ pub(crate) fn emit_unescape_error( diag.emit(); } EscapeError::TooShortHexEscape => { - handler.emit_err(UnescapeError::TooShortHexEscape(err_span)); + dcx.emit_err(UnescapeError::TooShortHexEscape(err_span)); } EscapeError::InvalidCharInHexEscape | EscapeError::InvalidCharInUnicodeEscape => { let (c, span) = last_char(); let is_hex = error == EscapeError::InvalidCharInHexEscape; let ch = escaped_char(c); - handler.emit_err(UnescapeError::InvalidCharInEscape { span, is_hex, ch }); + dcx.emit_err(UnescapeError::InvalidCharInEscape { span, is_hex, ch }); } EscapeError::NonAsciiCharInByte => { let (c, span) = last_char(); @@ -182,7 +180,7 @@ pub(crate) fn emit_unescape_error( Mode::RawByteStr => "raw byte string literal", _ => panic!("non-is_byte literal paired with NonAsciiCharInByte"), }; - let mut err = handler.struct_span_err(span, format!("non-ASCII character in {desc}")); + let mut err = dcx.struct_span_err(span, format!("non-ASCII character in {desc}")); let postfix = if unicode_width::UnicodeWidthChar::width(c).unwrap_or(1) == 0 { format!(" but is {c:?}") } else { @@ -218,21 +216,20 @@ pub(crate) fn emit_unescape_error( err.emit(); } EscapeError::OutOfRangeHexEscape => { - handler.emit_err(UnescapeError::OutOfRangeHexEscape(err_span)); + dcx.emit_err(UnescapeError::OutOfRangeHexEscape(err_span)); } EscapeError::LeadingUnderscoreUnicodeEscape => { let (c, span) = last_char(); - handler.emit_err(UnescapeError::LeadingUnderscoreUnicodeEscape { + dcx.emit_err(UnescapeError::LeadingUnderscoreUnicodeEscape { span, ch: escaped_char(c), }); } EscapeError::OverlongUnicodeEscape => { - handler.emit_err(UnescapeError::OverlongUnicodeEscape(err_span)); + dcx.emit_err(UnescapeError::OverlongUnicodeEscape(err_span)); } EscapeError::UnclosedUnicodeEscape => { - handler - .emit_err(UnescapeError::UnclosedUnicodeEscape(err_span, err_span.shrink_to_hi())); + dcx.emit_err(UnescapeError::UnclosedUnicodeEscape(err_span, err_span.shrink_to_hi())); } EscapeError::NoBraceInUnicodeEscape => { let mut suggestion = "\\u{".to_owned(); @@ -251,30 +248,30 @@ pub(crate) fn emit_unescape_error( } else { (Some(err_span), NoBraceUnicodeSub::Help) }; - handler.emit_err(UnescapeError::NoBraceInUnicodeEscape { span: err_span, label, sub }); + dcx.emit_err(UnescapeError::NoBraceInUnicodeEscape { span: err_span, label, sub }); } EscapeError::UnicodeEscapeInByte => { - handler.emit_err(UnescapeError::UnicodeEscapeInByte(err_span)); + dcx.emit_err(UnescapeError::UnicodeEscapeInByte(err_span)); } EscapeError::EmptyUnicodeEscape => { - handler.emit_err(UnescapeError::EmptyUnicodeEscape(err_span)); + dcx.emit_err(UnescapeError::EmptyUnicodeEscape(err_span)); } EscapeError::ZeroChars => { - handler.emit_err(UnescapeError::ZeroChars(err_span)); + dcx.emit_err(UnescapeError::ZeroChars(err_span)); } EscapeError::LoneSlash => { - handler.emit_err(UnescapeError::LoneSlash(err_span)); + dcx.emit_err(UnescapeError::LoneSlash(err_span)); } EscapeError::UnskippedWhitespaceWarning => { let (c, char_span) = last_char(); - handler.emit_warning(UnescapeError::UnskippedWhitespace { + dcx.emit_warning(UnescapeError::UnskippedWhitespace { span: err_span, ch: escaped_char(c), char_span, }); } EscapeError::MultipleSkippedLinesWarning => { - handler.emit_warning(UnescapeError::MultipleSkippedLinesWarning(err_span)); + dcx.emit_warning(UnescapeError::MultipleSkippedLinesWarning(err_span)); } } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 89abb276dbf..8f8da211d31 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -867,9 +867,9 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel { #[track_caller] fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::passes_invalid_attr_at_crate_level); + let mut diag = dcx.struct_err(fluent::passes_invalid_attr_at_crate_level); diag.set_span(self.span); diag.set_arg("name", self.name); // Only emit an error with a suggestion if we can create a string out @@ -1020,9 +1020,9 @@ impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> { #[track_caller] fn into_diagnostic( self, - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_span_err_with_code( + let mut diag = dcx.struct_span_err_with_code( self.span, fluent::passes_break_non_loop, error_code!(E0571), @@ -1169,9 +1169,9 @@ impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock { #[track_caller] fn into_diagnostic( self, - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_span_err_with_code( + let mut diag = dcx.struct_span_err_with_code( self.span, fluent::passes_naked_functions_asm_block, error_code!(E0787), @@ -1285,9 +1285,9 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr { #[track_caller] fn into_diagnostic( self, - handler: &'a rustc_errors::DiagCtxt, + dcx: &'a rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut diag = handler.struct_span_err_with_code( + let mut diag = dcx.struct_span_err_with_code( DUMMY_SP, fluent::passes_no_main_function, error_code!(E0601), @@ -1348,9 +1348,9 @@ impl IntoDiagnostic<'_> for DuplicateLangItem { #[track_caller] fn into_diagnostic( self, - handler: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err_with_code( + let mut diag = dcx.struct_err_with_code( match self.duplicate { Duplicate::Plain => fluent::passes_duplicate_lang_item, Duplicate::Crate => fluent::passes_duplicate_lang_item_crate, diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 8c63105d670..2a34ffb75f2 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -610,7 +610,7 @@ pub(crate) fn report_cycle<'a>( pub fn print_query_stack( qcx: Qcx, mut current_query: Option, - handler: &DiagCtxt, + dcx: &DiagCtxt, num_frames: Option, mut file: Option, ) -> usize { @@ -638,7 +638,7 @@ pub fn print_query_stack( ), ); diag.span = query_info.job.span.into(); - handler.force_print_diagnostic(diag); + dcx.force_print_diagnostic(diag); count_printed += 1; } diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 129ce2679c7..c3360815ac9 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -17,9 +17,9 @@ impl<'a> IntoDiagnostic<'a> for FeatureGateError { #[track_caller] fn into_diagnostic( self, - handler: &'a rustc_errors::DiagCtxt, + dcx: &'a rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> { - let mut diag = handler.struct_err(self.explain); + let mut diag = dcx.struct_err(self.explain); diag.set_span(self.span); diag.code(error_code!(E0658)); diag diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index c5c12f31b77..377976e6188 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -230,9 +230,9 @@ impl ParseSess { ParseSess::with_dcx(handler, sm) } - pub fn with_dcx(handler: DiagCtxt, source_map: Lrc) -> Self { + pub fn with_dcx(dcx: DiagCtxt, source_map: Lrc) -> Self { Self { - dcx: handler, + dcx, unstable_features: UnstableFeatures::from_environment(None), config: Cfg::default(), check_config: CheckCfg::default(), diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs index 48f3b4e735c..ff253b6f467 100644 --- a/compiler/rustc_symbol_mangling/src/errors.rs +++ b/compiler/rustc_symbol_mangling/src/errors.rs @@ -16,12 +16,12 @@ pub struct TestOutput { impl IntoDiagnostic<'_> for TestOutput { fn into_diagnostic( self, - handler: &'_ rustc_errors::DiagCtxt, + dcx: &'_ rustc_errors::DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { let TestOutput { span, kind, content } = self; #[allow(rustc::untranslatable_diagnostic)] - let mut diag = handler.struct_err(format!("{kind}({content})")); + let mut diag = dcx.struct_err(format!("{kind}({content})")); diag.set_span(span); diag } diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 83904452d8d..b0ec8b3a4fa 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -61,9 +61,9 @@ impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> { #[track_caller] fn into_diagnostic( self, - handler: &DiagCtxt, + dcx: &DiagCtxt, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(fluent::trait_selection_negative_positive_conflict); + let mut diag = dcx.struct_err(fluent::trait_selection_negative_positive_conflict); diag.set_arg("trait_desc", self.trait_desc.print_only_trait_path().to_string()); diag.set_arg( "self_desc", diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 659c61d718c..47bb2d883e3 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -803,12 +803,12 @@ impl Options { } /// Prints deprecation warnings for deprecated options -fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::DiagCtxt) { +fn check_deprecated_options(matches: &getopts::Matches, dcx: &rustc_errors::DiagCtxt) { let deprecated_flags = []; for &flag in deprecated_flags.iter() { if matches.opt_present(flag) { - diag.struct_warn(format!("the `{flag}` flag is deprecated")) + dcx.struct_warn(format!("the `{flag}` flag is deprecated")) .note( "see issue #44136 \ for more information", @@ -821,7 +821,7 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Dia for &flag in removed_flags.iter() { if matches.opt_present(flag) { - let mut err = diag.struct_warn(format!("the `{flag}` flag no longer functions")); + let mut err = dcx.struct_warn(format!("the `{flag}` flag no longer functions")); err.note( "see issue #44136 \ for more information", diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index f014dcefbc7..19298066159 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -385,9 +385,9 @@ pub(crate) fn run_global_ctxt( ); } - fn report_deprecated_attr(name: &str, diag: &rustc_errors::DiagCtxt, sp: Span) { + fn report_deprecated_attr(name: &str, dcx: &rustc_errors::DiagCtxt, sp: Span) { let mut msg = - diag.struct_span_warn(sp, format!("the `#![doc({name})]` attribute is deprecated")); + dcx.struct_span_warn(sp, format!("the `#![doc({name})]` attribute is deprecated")); msg.note( "see issue #44136 \ for more information", diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 50b2a7e2fd9..8bc0cdf3a95 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -27,15 +27,15 @@ impl ExternalHtml { md_before_content: &[String], md_after_content: &[String], nightly_build: bool, - diag: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, id_map: &mut IdMap, edition: Edition, playground: &Option, ) -> Option { let codes = ErrorCodes::from(nightly_build); - let ih = load_external_files(in_header, diag)?; - let bc = load_external_files(before_content, diag)?; - let m_bc = load_external_files(md_before_content, diag)?; + let ih = load_external_files(in_header, dcx)?; + let bc = load_external_files(before_content, dcx)?; + let m_bc = load_external_files(md_before_content, dcx)?; let bc = format!( "{bc}{}", Markdown { @@ -51,8 +51,8 @@ impl ExternalHtml { } .into_string() ); - let ac = load_external_files(after_content, diag)?; - let m_ac = load_external_files(md_after_content, diag)?; + let ac = load_external_files(after_content, dcx)?; + let m_ac = load_external_files(md_after_content, dcx)?; let ac = format!( "{ac}{}", Markdown { @@ -79,13 +79,13 @@ pub(crate) enum LoadStringError { pub(crate) fn load_string>( file_path: P, - diag: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> Result { let file_path = file_path.as_ref(); let contents = match fs::read(file_path) { Ok(bytes) => bytes, Err(e) => { - diag.struct_err(format!( + dcx.struct_err(format!( "error reading `{file_path}`: {e}", file_path = file_path.display() )) @@ -96,16 +96,16 @@ pub(crate) fn load_string>( match str::from_utf8(&contents) { Ok(s) => Ok(s.to_string()), Err(_) => { - diag.struct_err(format!("error reading `{}`: not UTF-8", file_path.display())).emit(); + dcx.struct_err(format!("error reading `{}`: not UTF-8", file_path.display())).emit(); Err(LoadStringError::BadUtf8) } } } -fn load_external_files(names: &[String], diag: &rustc_errors::DiagCtxt) -> Option { +fn load_external_files(names: &[String], dcx: &rustc_errors::DiagCtxt) -> Option { let mut out = String::new(); for name in names { - let Ok(s) = load_string(name, diag) else { return None }; + let Ok(s) = load_string(name, dcx) else { return None }; out.push_str(&s); out.push('\n'); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index fb11ee30c3d..02f608a515b 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -673,11 +673,11 @@ fn usage(argv0: &str) { /// A result type used by several functions under `main()`. type MainResult = Result<(), ErrorGuaranteed>; -fn wrap_return(diag: &rustc_errors::DiagCtxt, res: Result<(), String>) -> MainResult { +fn wrap_return(dcx: &rustc_errors::DiagCtxt, res: Result<(), String>) -> MainResult { match res { - Ok(()) => diag.has_errors().map_or(Ok(()), Err), + Ok(()) => dcx.has_errors().map_or(Ok(()), Err), Err(err) => { - let reported = diag.struct_err(err).emit(); + let reported = dcx.struct_err(err).emit(); Err(reported) } } diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index eba7af064be..a343d7afcee 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -40,7 +40,7 @@ pub(crate) struct ScrapeExamplesOptions { impl ScrapeExamplesOptions { pub(crate) fn new( matches: &getopts::Matches, - diag: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> Result, i32> { let output_path = matches.opt_str("scrape-examples-output-path"); let target_crates = matches.opt_strs("scrape-examples-target-crate"); @@ -52,11 +52,11 @@ impl ScrapeExamplesOptions { scrape_tests, })), (Some(_), false, _) | (None, true, _) => { - diag.err("must use --scrape-examples-output-path and --scrape-examples-target-crate together"); + dcx.err("must use --scrape-examples-output-path and --scrape-examples-target-crate together"); Err(1) } (None, false, true) => { - diag.err("must use --scrape-examples-output-path and --scrape-examples-target-crate with --scrape-tests"); + dcx.err("must use --scrape-examples-output-path and --scrape-examples-target-crate with --scrape-tests"); Err(1) } (None, false, false) => Ok(None), @@ -341,7 +341,7 @@ pub(crate) fn run( // options. pub(crate) fn load_call_locations( with_examples: Vec, - diag: &rustc_errors::DiagCtxt, + dcx: &rustc_errors::DiagCtxt, ) -> Result { let inner = || { let mut all_calls: AllCallLocations = FxHashMap::default(); @@ -359,7 +359,7 @@ pub(crate) fn load_call_locations( }; inner().map_err(|e: String| { - diag.err(format!("failed to load examples: {e}")); + dcx.err(format!("failed to load examples: {e}")); 1 }) } diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 0a974615828..98010b056c9 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -236,7 +236,7 @@ pub(crate) fn get_differences( pub(crate) fn test_theme_against>( f: &P, origin: &FxHashMap, - diag: &DiagCtxt, + dcx: &DiagCtxt, ) -> (bool, Vec) { let against = match fs::read_to_string(f) .map_err(|e| e.to_string()) @@ -244,7 +244,7 @@ pub(crate) fn test_theme_against>( { Ok(c) => c, Err(e) => { - diag.struct_err(e).emit(); + dcx.struct_err(e).emit(); return (false, vec![]); } };