From 09af8a667c0fa456bbe62fa462f4b0f42f2845ec Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 06:21:26 +1100 Subject: [PATCH] Rename `Session::span_diagnostic` as `Session::dcx`. --- compiler/rustc_ast_lowering/src/path.rs | 2 +- .../rustc_ast_passes/src/ast_validation.rs | 2 +- compiler/rustc_ast_passes/src/feature_gate.rs | 4 +- compiler/rustc_attr/src/builtin.rs | 2 +- .../src/diagnostics/conflict_errors.rs | 4 +- .../rustc_borrowck/src/diagnostics/mod.rs | 6 +- .../src/diagnostics/outlives_suggestion.rs | 4 +- compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_borrowck/src/nll.rs | 4 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../src/alloc_error_handler.rs | 2 +- .../src/global_allocator.rs | 2 +- compiler/rustc_builtin_macros/src/test.rs | 8 +- .../rustc_builtin_macros/src/test_harness.rs | 2 +- .../rustc_codegen_cranelift/src/driver/aot.rs | 2 +- compiler/rustc_codegen_llvm/src/back/write.rs | 4 +- compiler/rustc_codegen_ssa/src/back/link.rs | 10 +-- compiler/rustc_codegen_ssa/src/back/write.rs | 12 +-- .../rustc_codegen_ssa/src/codegen_attrs.rs | 32 +++---- .../rustc_const_eval/src/const_eval/error.rs | 2 +- compiler/rustc_const_eval/src/errors.rs | 2 +- .../src/interpret/eval_context.rs | 2 +- .../src/transform/check_consts/check.rs | 2 +- .../src/transform/validate.rs | 4 +- compiler/rustc_expand/src/base.rs | 10 +-- compiler/rustc_expand/src/mbe/macro_rules.rs | 14 ++-- compiler/rustc_expand/src/proc_macro.rs | 4 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 13 +-- .../src/coherence/orphan.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 14 +--- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- compiler/rustc_hir_typeck/src/lib.rs | 2 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 12 +-- .../src/infer/error_reporting/note.rs | 12 +-- compiler/rustc_interface/src/interface.rs | 4 +- compiler/rustc_interface/src/passes.rs | 6 +- compiler/rustc_interface/src/queries.rs | 2 +- compiler/rustc_interface/src/tests.rs | 8 +- compiler/rustc_lint/src/expect.rs | 2 +- compiler/rustc_lint/src/levels.rs | 2 +- compiler/rustc_metadata/src/creader.rs | 2 +- compiler/rustc_metadata/src/fs.rs | 2 +- compiler/rustc_middle/src/lint.rs | 4 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/util/bug.rs | 4 +- .../rustc_mir_build/src/build/custom/mod.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 4 +- .../rustc_query_system/src/dep_graph/graph.rs | 2 +- compiler/rustc_query_system/src/query/job.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 5 +- compiler/rustc_session/src/session.rs | 84 +++++++++---------- .../error_reporting/type_err_ctxt_ext.rs | 2 +- .../src/traits/object_safety.rs | 4 +- src/librustdoc/core.rs | 4 +- src/librustdoc/doctest.rs | 2 +- src/librustdoc/lib.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 2 +- src/librustdoc/scrape_examples.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- src/tools/miri/src/diagnostics.rs | 6 +- 66 files changed, 176 insertions(+), 204 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index efd80af5ef4..d323c16165b 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -139,7 +139,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // We should've returned in the for loop above. - self.tcx.sess.diagnostic().span_bug( + self.tcx.sess.dcx().span_bug( p.span, format!( "lower_qpath: no final extension segment in {}..{}", diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 3460a373d4f..7ed29056f0e 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -221,7 +221,7 @@ impl<'a> AstValidator<'a> { } fn err_handler(&self) -> &rustc_errors::DiagCtxt { - self.session.diagnostic() + self.session.dcx() } fn check_lifetime(&self, ident: Ident) { diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index ac55c6cabd0..142cdd15e64 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -102,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> { } Err(abi::AbiDisabled::Unrecognized) => { if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) { - self.sess.diagnostic().span_delayed_bug( + self.sess.dcx().span_delayed_bug( span, format!( "unrecognized ABI not caught in lowering: {}", @@ -654,7 +654,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate) if all_stable { err.sugg = Some(attr.span); } - sess.diagnostic().emit_err(err); + sess.dcx().emit_err(err); } } } diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index a6930fe0a17..0959e8d3043 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec { assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}"); use ReprAttr::*; let mut acc = Vec::new(); - let diagnostic = sess.diagnostic(); + let diagnostic = sess.dcx(); if let Some(items) = attr.meta_item_list() { for item in items { diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2f366001d4b..db0f4559a6b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1138,7 +1138,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }); } else { issued_spans.var_subdiag( - Some(self.infcx.tcx.sess.diagnostic()), + Some(self.infcx.tcx.sess.dcx()), &mut err, Some(issued_borrow.kind), |kind, var_span| { @@ -1155,7 +1155,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); borrow_spans.var_subdiag( - Some(self.infcx.tcx.sess.diagnostic()), + Some(self.infcx.tcx.sess.dcx()), &mut err, Some(gen_borrow_kind), |kind, var_span| { diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 19517a2560a..a4e09c0f412 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -124,7 +124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let did = did.expect_local(); if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) { diag.eager_subdiagnostic( - self.infcx.tcx.sess.diagnostic(), + self.infcx.tcx.sess.dcx(), OnClosureNote::InvokedTwice { place_name: &ty::place_to_string_for_capture( self.infcx.tcx, @@ -146,7 +146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let did = did.expect_local(); if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) { diag.eager_subdiagnostic( - self.infcx.tcx.sess.diagnostic(), + self.infcx.tcx.sess.dcx(), OnClosureNote::MovedTwice { place_name: &ty::place_to_string_for_capture(self.infcx.tcx, hir_place), span: *span, @@ -1150,7 +1150,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { && self.infcx.can_eq(self.param_env, ty, self_ty) { err.eager_subdiagnostic( - self.infcx.tcx.sess.diagnostic(), + self.infcx.tcx.sess.dcx(), CaptureReasonSuggest::FreshReborrow { span: move_span.shrink_to_hi(), }, diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 94981c45582..66275888c50 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -206,7 +206,7 @@ impl OutlivesSuggestionBuilder { // If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a // list of diagnostics. let mut diag = if suggested.len() == 1 { - mbcx.infcx.tcx.sess.diagnostic().struct_help(match suggested.last().unwrap() { + mbcx.infcx.tcx.sess.dcx().struct_help(match suggested.last().unwrap() { SuggestedConstraint::Outlives(a, bs) => { let bs: SmallVec<[String; 2]> = bs.iter().map(|r| r.to_string()).collect(); format!("add bound `{a}: {}`", bs.join(" + ")) @@ -223,7 +223,7 @@ impl OutlivesSuggestionBuilder { .infcx .tcx .sess - .diagnostic() + .dcx() .struct_help("the following changes may resolve your lifetime errors"); // Add suggestions. diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 7e0e598cd9f..43f48f579a3 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2503,7 +2503,7 @@ mod error { self.errors.buffered.sort_by_key(|diag| diag.sort_span); for diag in self.errors.buffered.drain(..) { - self.infcx.tcx.sess.diagnostic().emit_diagnostic(diag); + self.infcx.tcx.sess.dcx().emit_diagnostic(diag); } } diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index c88d9d81fe1..6781c6a756f 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -280,7 +280,7 @@ pub(super) fn dump_annotation<'tcx>( let def_span = tcx.def_span(body.source.def_id()); let mut err = if let Some(closure_region_requirements) = closure_region_requirements { - let mut err = tcx.sess.diagnostic().struct_span_note(def_span, "external requirements"); + let mut err = tcx.sess.dcx().struct_span_note(def_span, "external requirements"); regioncx.annotate(tcx, &mut err); @@ -299,7 +299,7 @@ pub(super) fn dump_annotation<'tcx>( err } else { - let mut err = tcx.sess.diagnostic().struct_span_note(def_span, "no external requirements"); + let mut err = tcx.sess.dcx().struct_span_note(def_span, "no external requirements"); regioncx.annotate(tcx, &mut err); err diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 98c21693cf0..5247d5f6981 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -268,7 +268,7 @@ fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) { // We sometimes see MIR failures (notably predicate failures) due to // the fact that we check rvalue sized predicates here. So use `span_delayed_bug` // to avoid reporting bugs in those cases. - tcx.sess.diagnostic().span_delayed_bug(span, msg); + tcx.sess.dcx().span_delayed_bug(span, msg); } enum FieldAccessError { diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index e13d217ef01..dffda8acc8d 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -31,7 +31,7 @@ pub fn expand( { (item, true, ecx.with_def_site_ctxt(fn_kind.sig.span)) } else { - ecx.sess.diagnostic().emit_err(errors::AllocErrorMustBeFn { span: item.span() }); + ecx.sess.dcx().emit_err(errors::AllocErrorMustBeFn { span: item.span() }); return vec![orig_item]; }; diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 6dc75e3ba4c..00c7907cdb4 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -34,7 +34,7 @@ pub fn expand( { (item, true, ecx.with_def_site_ctxt(ty.span)) } else { - ecx.sess.diagnostic().emit_err(errors::AllocMustStatics { span: item.span() }); + ecx.sess.dcx().emit_err(errors::AllocMustStatics { span: item.span() }); return vec![orig_item]; }; diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index e5b274304e7..7a262091121 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -389,7 +389,7 @@ pub fn expand_test_or_bench( } fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) { - let diag = cx.sess.diagnostic(); + let diag = cx.sess.dcx(); let msg = "the `#[test]` attribute may only be used on a non-associated function"; let mut err = match item.map(|i| &i.kind) { // These were a warning before #92959 and need to continue being that to avoid breaking @@ -466,7 +466,7 @@ fn should_ignore_message(i: &ast::Item) -> Option { fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic { match attr::find_by_name(&i.attrs, sym::should_panic) { Some(attr) => { - let sd = cx.sess.diagnostic(); + let sd = cx.sess.dcx(); match attr.meta_item_list() { // Handle #[should_panic(expected = "foo")] @@ -535,7 +535,7 @@ fn check_test_signature( f: &ast::Fn, ) -> Result<(), ErrorGuaranteed> { let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic); - let sd = cx.sess.diagnostic(); + let sd = cx.sess.dcx(); if let ast::Unsafe::Yes(span) = f.sig.header.unsafety { return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" })); @@ -601,7 +601,7 @@ fn check_bench_signature( // N.B., inadequate check, but we're running // well before resolve, can't get too deep. if f.sig.decl.inputs.len() != 1 { - return Err(cx.sess.diagnostic().emit_err(errors::BenchSig { span: i.span })); + return Err(cx.sess.dcx().emit_err(errors::BenchSig { span: i.span })); } Ok(()) } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 6ba81553742..6fbbef1eda8 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -47,7 +47,7 @@ pub fn inject( features: &Features, resolver: &mut dyn ResolverExpand, ) { - let span_diagnostic = sess.diagnostic(); + let span_diagnostic = sess.dcx(); let panic_strategy = sess.panic_strategy(); let platform_panic_strategy = sess.target.panic_strategy; diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index 11229dd421e..b3ab533df3d 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -422,7 +422,7 @@ pub(crate) fn run_aot( backend_config.clone(), global_asm_config.clone(), cgu.name(), - concurrency_limiter.acquire(tcx.sess.diagnostic()), + concurrency_limiter.acquire(tcx.sess.dcx()), ), module_codegen, Some(rustc_middle::dep_graph::hash_result), diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 6dee6cb3a69..d01f7e1d665 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -105,7 +105,7 @@ pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine // system/tcx is set up. let features = llvm_util::global_llvm_features(sess, false); target_machine_factory(sess, config::OptLevel::No, &features)(config) - .unwrap_or_else(|err| llvm_err(sess.diagnostic(), err).raise()) + .unwrap_or_else(|err| llvm_err(sess.dcx(), err).raise()) } pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMachine { @@ -128,7 +128,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMach tcx.backend_optimization_level(()), tcx.global_backend_features(()), )(config) - .unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), err).raise()) + .unwrap_or_else(|err| llvm_err(tcx.sess.dcx(), err).raise()) } pub fn to_llvm_opt_settings( diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 5d287e73c2d..289b61742ab 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -143,7 +143,7 @@ pub fn link_binary<'a>( } } if sess.opts.json_artifact_notifications { - sess.diagnostic().emit_artifact_notification(&out_filename, "link"); + sess.dcx().emit_artifact_notification(&out_filename, "link"); } if sess.prof.enabled() { @@ -183,13 +183,13 @@ pub fn link_binary<'a>( |preserve_objects: bool, preserve_dwarf_objects: bool, module: &CompiledModule| { if !preserve_objects { if let Some(ref obj) = module.object { - ensure_removed(sess.diagnostic(), obj); + ensure_removed(sess.dcx(), obj); } } if !preserve_dwarf_objects { if let Some(ref dwo_obj) = module.dwarf_object { - ensure_removed(sess.diagnostic(), dwo_obj); + ensure_removed(sess.dcx(), dwo_obj); } } }; @@ -208,7 +208,7 @@ pub fn link_binary<'a>( // Remove the temporary files if output goes to stdout for temp in tempfiles_for_stdout_output { - ensure_removed(sess.diagnostic(), &temp); + ensure_removed(sess.dcx(), &temp); } // If no requested outputs require linking, then the object temporaries should @@ -933,7 +933,7 @@ fn link_natively<'a>( command: &cmd, escaped_output, }; - sess.diagnostic().emit_err(err); + sess.dcx().emit_err(err); // If MSVC's `link.exe` was expected but the return code // is not a Microsoft LNK error then suggest a way to fix or // install the Visual Studio build tools. diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d1c6d2ea5af..18509c583f5 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -558,7 +558,7 @@ fn produce_final_output_artifacts( } if !sess.opts.cg.save_temps && !keep_numbered { // The user just wants `foo.x`, not `foo.#module-name#.x`. - ensure_removed(sess.diagnostic(), &path); + ensure_removed(sess.dcx(), &path); } } else { let extension = crate_output @@ -649,19 +649,19 @@ fn produce_final_output_artifacts( for module in compiled_modules.modules.iter() { if let Some(ref path) = module.object { if !keep_numbered_objects { - ensure_removed(sess.diagnostic(), path); + ensure_removed(sess.dcx(), path); } } if let Some(ref path) = module.dwarf_object { if !keep_numbered_objects { - ensure_removed(sess.diagnostic(), path); + ensure_removed(sess.dcx(), path); } } if let Some(ref path) = module.bytecode { if !keep_numbered_bitcode { - ensure_removed(sess.diagnostic(), path); + ensure_removed(sess.dcx(), path); } } } @@ -669,7 +669,7 @@ fn produce_final_output_artifacts( if !user_wants_bitcode { if let Some(ref allocator_module) = compiled_modules.allocator_module { if let Some(ref path) = allocator_module.bytecode { - ensure_removed(sess.diagnostic(), path); + ensure_removed(sess.dcx(), path); } } } @@ -1842,7 +1842,7 @@ impl SharedEmitterMain { match message { Ok(SharedEmitterMessage::Diagnostic(diag)) => { - let handler = sess.diagnostic(); + let handler = sess.dcx(); let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msg); if let Some(code) = diag.code { d.code(code); diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 015ea10d721..e529956b1ba 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -386,7 +386,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { [sym::arm, sym::a32] | [sym::arm, sym::t32] => { if !tcx.sess.target.has_thumb_interworking { struct_span_err!( - tcx.sess.diagnostic(), + tcx.sess.dcx(), attr.span, E0779, "target does not support `#[instruction_set]`" @@ -403,7 +403,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } _ => { struct_span_err!( - tcx.sess.diagnostic(), + tcx.sess.dcx(), attr.span, E0779, "invalid instruction set specified", @@ -415,7 +415,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } [] => { struct_span_err!( - tcx.sess.diagnostic(), + tcx.sess.dcx(), attr.span, E0778, "`#[instruction_set]` requires an argument" @@ -425,7 +425,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } _ => { struct_span_err!( - tcx.sess.diagnostic(), + tcx.sess.dcx(), attr.span, E0779, "cannot specify more than one instruction set" @@ -443,7 +443,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { rustc_attr::parse_alignment(&literal.kind) .map_err(|msg| { struct_span_err!( - tcx.sess.diagnostic(), + tcx.sess.dcx(), attr.span, E0589, "invalid `repr(align)` attribute: {}", @@ -469,27 +469,17 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { Some(MetaItemKind::List(ref items)) => { inline_span = Some(attr.span); if items.len() != 1 { - struct_span_err!( - tcx.sess.diagnostic(), - attr.span, - E0534, - "expected one argument" - ) - .emit(); + struct_span_err!(tcx.sess.dcx(), attr.span, E0534, "expected one argument") + .emit(); InlineAttr::None } else if list_contains_name(items, sym::always) { InlineAttr::Always } else if list_contains_name(items, sym::never) { InlineAttr::Never } else { - struct_span_err!( - tcx.sess.diagnostic(), - items[0].span(), - E0535, - "invalid argument" - ) - .help("valid inline arguments are `always` and `never`") - .emit(); + struct_span_err!(tcx.sess.dcx(), items[0].span(), E0535, "invalid argument") + .help("valid inline arguments are `always` and `never`") + .emit(); InlineAttr::None } @@ -503,7 +493,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if !attr.has_name(sym::optimize) { return ia; } - let err = |sp, s| struct_span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s).emit(); + let err = |sp, s| struct_span_err!(tcx.sess.dcx(), sp, E0722, "{}", s).emit(); match attr.meta_kind() { Some(MetaItemKind::Word) => { err(attr.span, "expected one argument"); diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index 26cf3b3f2b0..8f18cd78d3f 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -154,7 +154,7 @@ where let mut err = tcx.sess.create_err(err); let msg = error.diagnostic_message(); - error.add_args(tcx.sess.diagnostic(), &mut err); + error.add_args(tcx.sess.dcx(), &mut err); // Use *our* span to label the interp error err.span_label(our_span, msg); diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 5275c0ff14c..f52d5f12318 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -444,7 +444,7 @@ pub trait ReportErrorExt { { ty::tls::with(move |tcx| { let mut builder = tcx.sess.struct_allow(DiagnosticMessage::Str(String::new().into())); - let handler = tcx.sess.diagnostic(); + let handler = tcx.sess.dcx(); let message = self.diagnostic_message(); self.add_args(handler, &mut builder); let s = handler.eagerly_translate_to_string(message, builder.args()); diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 847d6503f20..2cce007898d 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -473,7 +473,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { backtrace.print_backtrace(); // FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the // label and arguments from the InterpError. - let handler = self.tcx.sess.diagnostic(); + let handler = self.tcx.sess.dcx(); #[allow(rustc::untranslatable_diagnostic)] let mut diag = self.tcx.sess.struct_allow(""); let msg = e.diagnostic_message(); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index bb17602d3ba..949606ed6c9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -278,7 +278,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { let secondary_errors = mem::take(&mut self.secondary_errors); if self.error_emitted.is_none() { for error in secondary_errors { - self.tcx.sess.diagnostic().emit_diagnostic(error); + self.tcx.sess.dcx().emit_diagnostic(error); } } else { assert!(self.tcx.sess.has_errors().is_some()); diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index eaf4abf39b7..cca5b90abb9 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -130,7 +130,7 @@ impl<'a, 'tcx> CfgChecker<'a, 'tcx> { let span = self.body.source_info(location).span; // We use `span_delayed_bug` as we might see broken MIR when other errors have already // occurred. - self.tcx.sess.diagnostic().span_delayed_bug( + self.tcx.sess.dcx().span_delayed_bug( span, format!( "broken MIR in {:?} ({}) at {:?}:\n{}", @@ -571,7 +571,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { fn visit_source_scope(&mut self, scope: SourceScope) { if self.body.source_scopes.get(scope).is_none() { - self.tcx.sess.diagnostic().span_delayed_bug( + self.tcx.sess.dcx().span_delayed_bug( self.body.span, format!( "broken MIR in {:?} ({}):\ninvalid source scope {:?}", diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 5d7f8a3c7c3..30a1095be52 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -790,7 +790,7 @@ impl SyntaxExtension { .map(|attr| { // Override `helper_attrs` passed above if it's a built-in macro, // marking `proc_macro_derive` macros as built-in is not a realistic use case. - parse_macro_name_and_helper_attrs(sess.diagnostic(), attr, "built-in").map_or_else( + parse_macro_name_and_helper_attrs(sess.dcx(), attr, "built-in").map_or_else( || (Some(name), Vec::new()), |(name, helper_attrs)| (Some(name), helper_attrs), ) @@ -1119,7 +1119,7 @@ impl<'a> ExtCtxt<'a> { sp: S, msg: impl Into, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - self.sess.diagnostic().struct_span_err(sp, msg) + self.sess.dcx().struct_span_err(sp, msg) } #[track_caller] @@ -1143,10 +1143,10 @@ impl<'a> ExtCtxt<'a> { #[rustc_lint_diagnostics] #[track_caller] pub fn span_err>(&self, sp: S, msg: impl Into) { - self.sess.diagnostic().span_err(sp, msg); + self.sess.dcx().span_err(sp, msg); } pub fn span_bug>(&self, sp: S, msg: impl Into) -> ! { - self.sess.diagnostic().span_bug(sp, msg); + self.sess.dcx().span_bug(sp, msg); } pub fn trace_macros_diag(&mut self) { for (span, notes) in self.expansions.iter() { @@ -1160,7 +1160,7 @@ impl<'a> ExtCtxt<'a> { self.expansions.clear(); } pub fn bug(&self, msg: &'static str) -> ! { - self.sess.diagnostic().bug(msg); + self.sess.dcx().bug(msg); } pub fn trace_macros(&self) -> bool { self.ecfg.trace_mac diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 9a3be8be1ed..024d2b8fb83 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -482,14 +482,14 @@ pub fn compile_declarative_macro( let s = parse_failure_msg(&token); let sp = token.span.substitute_dummy(def.span); - let mut err = sess.diagnostic().struct_span_err(sp, s); + let mut err = sess.dcx().struct_span_err(sp, s); err.span_label(sp, msg); annotate_doc_comment(&mut err, sess.source_map(), sp); err.emit(); return dummy_syn_ext(); } Error(sp, msg) => { - sess.diagnostic().struct_span_err(sp.substitute_dummy(def.span), msg).emit(); + sess.dcx().struct_span_err(sp.substitute_dummy(def.span), msg).emit(); return dummy_syn_ext(); } ErrorReported(_) => { @@ -518,10 +518,10 @@ pub fn compile_declarative_macro( valid &= check_lhs_nt_follows(&sess.parse_sess, def, &tt); return tt; } - sess.diagnostic().span_bug(def.span, "wrong-structured lhs") + sess.dcx().span_bug(def.span, "wrong-structured lhs") }) .collect::>(), - _ => sess.diagnostic().span_bug(def.span, "wrong-structured lhs"), + _ => sess.dcx().span_bug(def.span, "wrong-structured lhs"), }; let rhses = match &argument_map[&MacroRulesNormalizedIdent::new(rhs_nm)] { @@ -540,10 +540,10 @@ pub fn compile_declarative_macro( .pop() .unwrap(); } - sess.diagnostic().span_bug(def.span, "wrong-structured rhs") + sess.dcx().span_bug(def.span, "wrong-structured rhs") }) .collect::>(), - _ => sess.diagnostic().span_bug(def.span, "wrong-structured rhs"), + _ => sess.dcx().span_bug(def.span, "wrong-structured rhs"), }; for rhs in &rhses { @@ -599,7 +599,7 @@ pub fn compile_declarative_macro( mbe::TokenTree::Delimited(.., delimited) => { mbe::macro_parser::compute_locs(&delimited.tts) } - _ => sess.diagnostic().span_bug(def.span, "malformed macro lhs"), + _ => sess.dcx().span_bug(def.span, "malformed macro lhs"), } }) .collect() diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index d08026b9c14..429bfa61450 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -156,7 +156,7 @@ impl MultiItemModifier for DeriveProcMacro { } }; - let error_count_before = ecx.sess.diagnostic().err_count(); + let error_count_before = ecx.sess.dcx().err_count(); let mut parser = rustc_parse::stream_to_parser(&ecx.sess.parse_sess, stream, Some("proc-macro derive")); let mut items = vec![]; @@ -179,7 +179,7 @@ impl MultiItemModifier for DeriveProcMacro { } // fail if there have been errors emitted - if ecx.sess.diagnostic().err_count() > error_count_before { + if ecx.sess.dcx().err_count() > error_count_before { ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span }); } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 64026cdfff4..b2ff7959106 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1607,15 +1607,10 @@ fn check_method_receiver<'tcx>( } fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) -> ErrorGuaranteed { - struct_span_err!( - tcx.sess.diagnostic(), - span, - E0307, - "invalid `self` parameter type: {receiver_ty}" - ) - .note("type of `self` must be `Self` or a type that dereferences to it") - .help(HELP_FOR_SELF_TYPE) - .emit() + struct_span_err!(tcx.sess.dcx(), span, E0307, "invalid `self` parameter type: {receiver_ty}") + .note("type of `self` must be `Self` or a type that dereferences to it") + .help(HELP_FOR_SELF_TYPE) + .emit() } /// Returns whether `receiver_ty` would be considered a valid receiver type for `self_ty`. If diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 88128d22a3d..d33cfe4ad4d 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -453,7 +453,7 @@ fn lint_auto_trait_impl<'tcx>( impl_def_id: LocalDefId, ) { if trait_ref.args.len() != 1 { - tcx.sess.diagnostic().span_delayed_bug( + tcx.sess.dcx().span_delayed_bug( tcx.def_span(impl_def_id), "auto traits cannot have generic parameters", ); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index d176665e4c0..688d32fa32d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -672,7 +672,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { hir::TraitItemKind::Const(ty, body_id) => { tcx.ensure().type_of(def_id); - if !tcx.sess.diagnostic().has_stashed_diagnostic(ty.span, StashKey::ItemNoType) + if !tcx.sess.dcx().has_stashed_diagnostic(ty.span, StashKey::ItemNoType) && !(is_suggestable_infer_ty(ty) && body_id.is_some()) { // Account for `const C: _;`. diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 174217d3b70..15d546537dd 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -574,7 +574,7 @@ fn infer_placeholder_type<'a>( // then the user may have written e.g. `const A = 42;`. // In this case, the parser has stashed a diagnostic for // us to improve in typeck so we do that now. - match tcx.sess.diagnostic().steal_diagnostic(span, StashKey::ItemNoType) { + match tcx.sess.dcx().steal_diagnostic(span, StashKey::ItemNoType) { Some(mut err) => { if !ty.references_error() { // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index baca2be06e6..51f38240033 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -417,7 +417,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Some(mut diag) = self .tcx .sess - .diagnostic() + .dcx() .steal_diagnostic(segment.ident.span, StashKey::CallIntoMethod) { // Try suggesting `foo(a)` -> `a.foo()` if possible. diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 80265cf31e6..7bd2c3f8b6b 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1436,12 +1436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length && let Some(span) = self.tcx.hir().opt_span(hir_id) { - match self - .tcx - .sess - .diagnostic() - .steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) - { + match self.tcx.sess.dcx().steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) { Some(mut err) => { err.span_suggestion( span, @@ -2002,11 +1997,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { != range_def_id { // Suppress any range expr type mismatches - if let Some(mut diag) = self - .tcx - .sess - .diagnostic() - .steal_diagnostic(last_expr_field.span, StashKey::MaybeFruTypo) + if let Some(mut diag) = + self.tcx.sess.dcx().steal_diagnostic(last_expr_field.span, StashKey::MaybeFruTypo) { diag.delay_as_bug(); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 3bee42eb89c..24b577fd3c5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -848,7 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Some(mut diag) = self .tcx .sess - .diagnostic() + .dcx() .steal_diagnostic(qself.span, StashKey::TraitMissingMethod) { diag.emit(); @@ -884,7 +884,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Some(mut diag) = self .tcx .sess - .diagnostic() + .dcx() .steal_diagnostic(qself.span, StashKey::TraitMissingMethod) { if trait_missing_method { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 3f97b24aa59..17022f1fd37 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1852,7 +1852,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { for (span, code) in errors_causecode { let Some(mut diag) = - self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::MaybeForgetReturn) + self.tcx.sess.dcx().steal_diagnostic(span, StashKey::MaybeForgetReturn) else { continue; }; diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index f1f893623f6..d26c78867ae 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -413,7 +413,7 @@ enum TupleArgumentsFlag { } fn fatally_break_rust(tcx: TyCtxt<'_>) { - let handler = tcx.sess.diagnostic(); + let handler = tcx.sess.dcx(); handler.span_bug_no_panic( MultiSpan::new(), "It looks like you're trying to break rust; would you like some ICE?", diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 8fb703fa7f5..7595f21d9f1 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1929,7 +1929,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; }; let Some(mut diag) = - self.tcx.sess.diagnostic().steal_diagnostic(seg1.ident.span, StashKey::CallAssocMethod) + self.tcx.sess.dcx().steal_diagnostic(seg1.ident.span, StashKey::CallAssocMethod) else { return; }; diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 5e562d9453f..d0cf4575c8f 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -505,7 +505,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { if !errors_buffer.is_empty() { errors_buffer.sort_by_key(|diag| diag.span.primary_span()); for diag in errors_buffer { - self.tcx().sess.diagnostic().emit_diagnostic(diag); + self.tcx().sess.dcx().emit_diagnostic(diag); } } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 1caa9aa8cd6..817a4451dd1 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -376,7 +376,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0283 => AmbiguousImpl { span, source_kind, @@ -386,7 +386,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0284 => AmbiguousReturn { span, source_kind, @@ -396,7 +396,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), } } } @@ -583,7 +583,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0283 => AmbiguousImpl { span, source_kind, @@ -593,7 +593,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0284 => AmbiguousReturn { span, source_kind, @@ -603,7 +603,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(self.tcx.sess.diagnostic()), + .into_diagnostic(self.tcx.sess.dcx()), } } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 1e365848e07..859c10ef142 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -140,7 +140,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: reference_valid.into_iter().chain(content_valid).collect(), } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateObjectBound(span) => { let object_valid = note_and_explain::RegionExplanation::new( @@ -161,7 +161,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: object_valid.into_iter().chain(pointer_valid).collect(), } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateParamBound(span, ty, opt_span) => { let prefix = match *sub { @@ -177,7 +177,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx, sub, opt_span, prefix, suffix, ); FulfillReqLifetime { span, ty: self.resolve_vars_if_possible(ty), note } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateRegionParamBound(span) => { let param_instantiated = note_and_explain::RegionExplanation::new( @@ -198,7 +198,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: param_instantiated.into_iter().chain(param_must_outlive).collect(), } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } infer::ReferenceOutlivesReferent(ty, span) => { let pointer_valid = note_and_explain::RegionExplanation::new( @@ -220,7 +220,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ty: self.resolve_vars_if_possible(ty), notes: pointer_valid.into_iter().chain(data_valid).collect(), } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => { let mut err = self.report_extra_impl_obligation( @@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: instantiated.into_iter().chain(must_outlive).collect(), } - .into_diagnostic(self.tcx.sess.diagnostic()) + .into_diagnostic(self.tcx.sess.dcx()) } }; if sub.is_error() || sup.is_error() { diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 3a2550ae1f3..a46b0e51f75 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -382,12 +382,12 @@ pub fn run_compiler(config: Config, f: impl FnOnce(&Compiler) -> R + Se codegen_backend.init(&sess); - let cfg = parse_cfg(&sess.diagnostic(), config.crate_cfg); + let cfg = parse_cfg(&sess.dcx(), config.crate_cfg); let mut cfg = config::build_configuration(&sess, cfg); util::add_configuration(&mut cfg, &mut sess, &*codegen_backend); sess.parse_sess.config = cfg; - let mut check_cfg = parse_check_cfg(&sess.diagnostic(), config.crate_check_cfg); + let mut check_cfg = parse_check_cfg(&sess.dcx(), config.crate_check_cfg); check_cfg.fill_well_known(&sess.target); sess.parse_sess.check_config = check_cfg; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 9b59ead0463..21beb90d73f 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -56,7 +56,7 @@ pub fn parse<'a>(sess: &'a Session) -> PResult<'a, ast::Crate> { } if let Some(ref s) = sess.opts.unstable_opts.show_span { - rustc_ast_passes::show_span::run(sess.diagnostic(), s, &krate); + rustc_ast_passes::show_span::run(sess.dcx(), s, &krate); } if sess.opts.unstable_opts.hir_stats { @@ -267,7 +267,7 @@ fn configure_and_expand( is_proc_macro_crate, has_proc_macro_decls, is_test_crate, - sess.diagnostic(), + sess.dcx(), ) }); @@ -526,7 +526,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P match result { Ok(_) => { if sess.opts.json_artifact_notifications { - sess.diagnostic().emit_artifact_notification(deps_filename, "dep-info"); + sess.dcx().emit_artifact_notification(deps_filename, "dep-info"); } } Err(error) => { diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index e9611c74a68..8a553b95e8e 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -228,7 +228,7 @@ impl<'tcx> Queries<'tcx> { // If we have any delayed bugs, for example because we created TyKind::Error earlier, // it's likely that codegen will only cause more ICEs, obscuring the original problem - self.compiler.sess.diagnostic().flush_delayed(); + self.compiler.sess.dcx().flush_delayed(); // Hook for UI tests. Self::check_for_rustc_errors_attr(tcx); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 076dd78b0e0..12547799db8 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -52,7 +52,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, Cfg) { Arc::default(), Default::default(), ); - let cfg = parse_cfg(&sess.diagnostic(), matches.opt_strs("cfg")); + let cfg = parse_cfg(&sess.dcx(), matches.opt_strs("cfg")); (sess, cfg) } @@ -143,20 +143,20 @@ fn test_can_print_warnings() { rustc_span::create_default_session_globals_then(|| { let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap(); let (sess, _) = mk_session(matches); - assert!(!sess.diagnostic().can_emit_warnings()); + assert!(!sess.dcx().can_emit_warnings()); }); rustc_span::create_default_session_globals_then(|| { let matches = optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap(); let (sess, _) = mk_session(matches); - assert!(sess.diagnostic().can_emit_warnings()); + assert!(sess.dcx().can_emit_warnings()); }); rustc_span::create_default_session_globals_then(|| { let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap(); let (sess, _) = mk_session(matches); - assert!(sess.diagnostic().can_emit_warnings()); + assert!(sess.dcx().can_emit_warnings()); }); } diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index 047a214a8b2..5dcc1bce5ff 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -16,7 +16,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { } let lint_expectations = tcx.lint_expectations(()); - let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids(); + let fulfilled_expectations = tcx.sess.dcx().steal_fulfilled_expectation_ids(); tracing::debug!(?lint_expectations, ?fulfilled_expectations); diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 8c8ff3fc650..6eff2bfe13c 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -144,7 +144,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp builder.add_id(hir::CRATE_HIR_ID); tcx.hir().walk_toplevel_module(&mut builder); - tcx.sess.diagnostic().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids); + tcx.sess.dcx().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids); builder.provider.expectations } diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 301e3f2620d..972c84b10f4 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -267,7 +267,7 @@ impl CStore { let unused_externs = self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::>(); let unused_externs = unused_externs.iter().map(String::as_str).collect::>(); - tcx.sess.diagnostic().emit_unused_externs( + tcx.sess.dcx().emit_unused_externs( level, json_unused_externs.is_loud(), &unused_externs, diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index c95ef01faa7..e80afcc482e 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -91,7 +91,7 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> (EncodedMetadata, bool) { } }; if tcx.sess.opts.json_artifact_notifications { - tcx.sess.diagnostic().emit_artifact_notification(out_filename.as_path(), "metadata"); + tcx.sess.dcx().emit_artifact_notification(out_filename.as_path(), "metadata"); } (filename, None) } else { diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index bbdec8541ac..c49c4ee819c 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -324,11 +324,11 @@ pub fn struct_lint_level( (Level::Warn | Level::ForceWarn(None), Some(span)) => sess.struct_span_warn(span, ""), (Level::Warn | Level::ForceWarn(None), None) => sess.struct_warn(""), (Level::Deny | Level::Forbid, Some(span)) => { - let mut builder = sess.diagnostic().struct_err_lint(""); + let mut builder = sess.dcx().struct_err_lint(""); builder.set_span(span); builder } - (Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""), + (Level::Deny | Level::Forbid, None) => sess.dcx().struct_err_lint(""), }; err.set_is_lint(); diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 6513bf501e1..96de9c447b6 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1484,7 +1484,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { if let Some(diag) = tcx .sess - .diagnostic() + .dcx() .steal_diagnostic(tcx.def_span(opaque_def_id), StashKey::OpaqueHiddenTypeMismatch) { diag.cancel(); diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index 21c1a93fde8..5c9dd18aeac 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -31,8 +31,8 @@ fn opt_span_bug_fmt>( tls::with_opt(move |tcx| { let msg = format!("{location}: {args}"); match (tcx, span) { - (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, msg), - (Some(tcx), None) => tcx.sess.diagnostic().bug(msg), + (Some(tcx), Some(span)) => tcx.sess.dcx().span_bug(span, msg), + (Some(tcx), None) => tcx.sess.dcx().bug(msg), (None, _) => panic_any(msg), } }) diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index 8c68a58d406..ead20539e25 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -92,7 +92,7 @@ pub(super) fn build_custom_mir<'tcx>( pctxt.parse_body(expr)?; }; if let Err(err) = res { - tcx.sess.diagnostic().span_fatal( + tcx.sess.dcx().span_fatal( err.span, format!("Could not parse {}, found: {:?}", err.expected, err.item_description), ) diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index feceff10f95..a68bfcd06d5 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -371,7 +371,7 @@ fn collect_items_rec<'tcx>( // current step of mono items collection. // // FIXME: don't rely on global state, instead bubble up errors. Note: this is very hard to do. - let error_count = tcx.sess.diagnostic().err_count(); + let error_count = tcx.sess.dcx().err_count(); match starting_item.node { MonoItem::Static(def_id) => { @@ -459,7 +459,7 @@ fn collect_items_rec<'tcx>( // Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the // mono item graph. - if tcx.sess.diagnostic().err_count() > error_count + if tcx.sess.dcx().err_count() > error_count && starting_item.node.is_generic_fn(tcx) && starting_item.node.is_user_defined() { diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 3b8ccb67bbe..d11444c8dfe 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -924,7 +924,7 @@ impl DepGraphData { // Promote the previous diagnostics to the current session. qcx.store_side_effects(dep_node_index, side_effects.clone()); - let handle = qcx.dep_context().sess().diagnostic(); + let handle = qcx.dep_context().sess().dcx(); for diagnostic in side_effects.diagnostics { handle.emit_diagnostic(diagnostic); diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 8847bc72974..8c63105d670 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -604,7 +604,7 @@ pub(crate) fn report_cycle<'a>( note_span: (), }; - cycle_diag.into_diagnostic(sess.diagnostic()) + cycle_diag.into_diagnostic(sess.dcx()) } pub fn print_query_stack( diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index ca225416e36..1001286b6c2 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -205,10 +205,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> { fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) { if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() { - self.tcx - .sess - .diagnostic() - .bug(format!("built-in macro `{name}` was already registered")); + self.tcx.sess.dcx().bug(format!("built-in macro `{name}` was already registered")); } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 8428d6a6c66..fe66b483451 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -289,7 +289,7 @@ impl Session { /// Invoked all the way at the end to finish off diagnostics printing. pub fn finish_diagnostics(&self, registry: &Registry) { self.check_miri_unleashed_features(); - self.diagnostic().print_error_count(registry); + self.dcx().print_error_count(registry); self.emit_future_breakage(); } @@ -298,11 +298,11 @@ impl Session { return; } - let diags = self.diagnostic().take_future_breakage_diagnostics(); + let diags = self.dcx().take_future_breakage_diagnostics(); if diags.is_empty() { return; } - self.diagnostic().emit_future_breakage_report(diags); + self.dcx().emit_future_breakage_report(diags); } /// Returns true if the crate is a testing one. @@ -317,7 +317,7 @@ impl Session { sp: S, msg: impl Into, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_span_warn(sp, msg) + self.dcx().struct_span_warn(sp, msg) } #[rustc_lint_diagnostics] #[track_caller] @@ -327,7 +327,7 @@ impl Session { msg: impl Into, id: lint::LintExpectationId, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_span_warn_with_expectation(sp, msg, id) + self.dcx().struct_span_warn_with_expectation(sp, msg, id) } #[rustc_lint_diagnostics] #[track_caller] @@ -337,12 +337,12 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_span_warn_with_code(sp, msg, code) + self.dcx().struct_span_warn_with_code(sp, msg, code) } #[rustc_lint_diagnostics] #[track_caller] pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_warn(msg) + self.dcx().struct_warn(msg) } #[rustc_lint_diagnostics] #[track_caller] @@ -351,7 +351,7 @@ impl Session { msg: impl Into, id: lint::LintExpectationId, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_warn_with_expectation(msg, id) + self.dcx().struct_warn_with_expectation(msg, id) } #[rustc_lint_diagnostics] #[track_caller] @@ -360,12 +360,12 @@ impl Session { sp: S, msg: impl Into, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_span_allow(sp, msg) + self.dcx().struct_span_allow(sp, msg) } #[rustc_lint_diagnostics] #[track_caller] pub fn struct_allow(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_allow(msg) + self.dcx().struct_allow(msg) } #[rustc_lint_diagnostics] #[track_caller] @@ -374,7 +374,7 @@ impl Session { msg: impl Into, id: lint::LintExpectationId, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_expect(msg, id) + self.dcx().struct_expect(msg, id) } #[rustc_lint_diagnostics] #[track_caller] @@ -383,7 +383,7 @@ impl Session { sp: S, msg: impl Into, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - self.diagnostic().struct_span_err(sp, msg) + self.dcx().struct_span_err(sp, msg) } #[rustc_lint_diagnostics] #[track_caller] @@ -393,7 +393,7 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - self.diagnostic().struct_span_err_with_code(sp, msg, code) + self.dcx().struct_span_err_with_code(sp, msg, code) } // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] @@ -411,7 +411,7 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - self.diagnostic().struct_err_with_code(msg, code) + self.dcx().struct_err_with_code(msg, code) } #[rustc_lint_diagnostics] #[track_caller] @@ -420,7 +420,7 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_warn_with_code(msg, code) + self.dcx().struct_warn_with_code(msg, code) } #[rustc_lint_diagnostics] #[track_caller] @@ -429,7 +429,7 @@ impl Session { sp: S, msg: impl Into, ) -> DiagnosticBuilder<'_, !> { - self.diagnostic().struct_span_fatal(sp, msg) + self.dcx().struct_span_fatal(sp, msg) } #[rustc_lint_diagnostics] pub fn struct_span_fatal_with_code>( @@ -438,17 +438,17 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> DiagnosticBuilder<'_, !> { - self.diagnostic().struct_span_fatal_with_code(sp, msg, code) + self.dcx().struct_span_fatal_with_code(sp, msg, code) } #[rustc_lint_diagnostics] pub fn struct_fatal(&self, msg: impl Into) -> DiagnosticBuilder<'_, !> { - self.diagnostic().struct_fatal(msg) + self.dcx().struct_fatal(msg) } #[rustc_lint_diagnostics] #[track_caller] pub fn span_fatal>(&self, sp: S, msg: impl Into) -> ! { - self.diagnostic().span_fatal(sp, msg) + self.dcx().span_fatal(sp, msg) } #[rustc_lint_diagnostics] pub fn span_fatal_with_code>( @@ -457,11 +457,11 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> ! { - self.diagnostic().span_fatal_with_code(sp, msg, code) + self.dcx().span_fatal_with_code(sp, msg, code) } #[rustc_lint_diagnostics] pub fn fatal(&self, msg: impl Into) -> ! { - self.diagnostic().fatal(msg) + self.dcx().fatal(msg) } #[rustc_lint_diagnostics] #[track_caller] @@ -470,7 +470,7 @@ impl Session { sp: S, msg: impl Into, ) -> ErrorGuaranteed { - self.diagnostic().span_err(sp, msg) + self.dcx().span_err(sp, msg) } #[rustc_lint_diagnostics] pub fn span_err_with_code>( @@ -479,13 +479,13 @@ impl Session { msg: impl Into, code: DiagnosticId, ) -> ErrorGuaranteed { - self.diagnostic().span_err_with_code(sp, msg, code) + self.dcx().span_err_with_code(sp, msg, code) } #[rustc_lint_diagnostics] #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn err(&self, msg: impl Into) -> ErrorGuaranteed { - self.diagnostic().err(msg) + self.dcx().err(msg) } #[track_caller] pub fn create_err<'a>( @@ -546,23 +546,23 @@ impl Session { } #[inline] pub fn err_count(&self) -> usize { - self.diagnostic().err_count() + self.dcx().err_count() } pub fn has_errors(&self) -> Option { - self.diagnostic().has_errors() + self.dcx().has_errors() } pub fn has_errors_or_span_delayed_bugs(&self) -> Option { - self.diagnostic().has_errors_or_span_delayed_bugs() + self.dcx().has_errors_or_span_delayed_bugs() } pub fn is_compilation_going_to_fail(&self) -> Option { - self.diagnostic().is_compilation_going_to_fail() + self.dcx().is_compilation_going_to_fail() } pub fn abort_if_errors(&self) { - self.diagnostic().abort_if_errors(); + self.dcx().abort_if_errors(); } pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> { - if let Some(reported) = self.diagnostic().has_errors_or_lint_errors() { - let _ = self.diagnostic().emit_stashed_diagnostics(); + if let Some(reported) = self.dcx().has_errors_or_lint_errors() { + let _ = self.dcx().emit_stashed_diagnostics(); Err(reported) } else { Ok(()) @@ -590,7 +590,7 @@ impl Session { #[allow(rustc::diagnostic_outside_of_impl)] #[track_caller] pub fn span_warn>(&self, sp: S, msg: impl Into) { - self.diagnostic().span_warn(sp, msg) + self.dcx().span_warn(sp, msg) } #[rustc_lint_diagnostics] @@ -602,14 +602,14 @@ impl Session { msg: impl Into, code: DiagnosticId, ) { - self.diagnostic().span_warn_with_code(sp, msg, code) + self.dcx().span_warn_with_code(sp, msg, code) } #[rustc_lint_diagnostics] #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn warn(&self, msg: impl Into) { - self.diagnostic().warn(msg) + self.dcx().warn(msg) } /// Ensures that compilation cannot succeed. @@ -634,7 +634,7 @@ impl Session { sp: S, msg: impl Into, ) -> ErrorGuaranteed { - self.diagnostic().span_delayed_bug(sp, msg) + self.dcx().span_delayed_bug(sp, msg) } /// Used for code paths of expensive computations that should only take place when @@ -651,14 +651,14 @@ impl Session { return; } - self.diagnostic().good_path_delayed_bug(msg) + self.dcx().good_path_delayed_bug(msg) } #[rustc_lint_diagnostics] #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn note(&self, msg: impl Into) { - self.diagnostic().note(msg) + self.dcx().note(msg) } #[track_caller] @@ -666,18 +666,18 @@ impl Session { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn span_note>(&self, sp: S, msg: impl Into) { - self.diagnostic().span_note(sp, msg) + self.dcx().span_note(sp, msg) } #[rustc_lint_diagnostics] #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] pub fn struct_note(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { - self.diagnostic().struct_note(msg) + self.dcx().struct_note(msg) } #[inline] - pub fn diagnostic(&self) -> &DiagCtxt { + pub fn dcx(&self) -> &DiagCtxt { &self.parse_sess.dcx } @@ -881,7 +881,7 @@ impl Session { let mut fuel = self.optimization_fuel.lock(); ret = fuel.remaining != 0; if fuel.remaining == 0 && !fuel.out_of_fuel { - if self.diagnostic().can_emit_warnings() { + if self.dcx().can_emit_warnings() { // We only call `msg` in case we can actually emit warnings. // Otherwise, this could cause a `good_path_delayed_bug` to // trigger (issue #79546). @@ -1221,7 +1221,7 @@ impl Session { } pub fn teach(&self, code: &DiagnosticId) -> bool { - self.opts.unstable_opts.teach && self.diagnostic().must_teach(code) + self.opts.unstable_opts.teach && self.dcx().must_teach(code) } pub fn edition(&self) -> Edition { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 5cc934e7bc5..9ee091bbd1e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -3395,7 +3395,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { }; if let Some(diag) = - self.tcx.sess.diagnostic().steal_diagnostic(self.tcx.def_span(def_id), StashKey::Cycle) + self.tcx.sess.dcx().steal_diagnostic(self.tcx.def_span(def_id), StashKey::Cycle) { diag.cancel(); } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 47a79bfa9ab..7ac37315fe0 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -594,9 +594,7 @@ fn virtual_call_violations_for_method<'tcx>( // would already have reported an error at the definition of the // auto trait. if pred_trait_ref.args.len() != 1 { - tcx.sess - .diagnostic() - .span_delayed_bug(span, "auto traits cannot have generic parameters"); + tcx.sess.dcx().span_delayed_bug(span, "auto traits cannot have generic parameters"); } return false; } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ca6a8cefed7..8cac1df38e2 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -408,7 +408,7 @@ pub(crate) fn run_global_ctxt( // Process all of the crate attributes, extracting plugin metadata along // with the passes which we are supposed to run. for attr in krate.module.attrs.lists(sym::doc) { - let diag = ctxt.sess().diagnostic(); + let diag = ctxt.sess().dcx(); let name = attr.name_or_empty(); // `plugins = "..."`, `no_default_passes`, and `passes = "..."` have no effect @@ -448,7 +448,7 @@ pub(crate) fn run_global_ctxt( tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc))); - if tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() { + if tcx.sess.dcx().has_errors_or_lint_errors().is_some() { rustc_errors::FatalError.raise(); } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index dbfa5f395d4..c4000f099e5 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -150,7 +150,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { collector }); - if compiler.sess.diagnostic().has_errors_or_lint_errors().is_some() { + if compiler.sess.dcx().has_errors_or_lint_errors().is_some() { FatalError.raise(); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 20eb88b5945..f26dd07293e 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -803,7 +803,7 @@ fn main_args( compiler.enter(|queries| { let mut gcx = abort_on_err(queries.global_ctxt(), sess); - if sess.diagnostic().has_errors_or_lint_errors().is_some() { + if sess.dcx().has_errors_or_lint_errors().is_some() { sess.fatal("Compilation failed, aborting rustdoc"); } diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index b6f73d3fdcd..df2e8584b84 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -22,7 +22,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> let tcx = cx.tcx; // We need to check if there are errors before running this pass because it would crash when // we try to get auto and blanket implementations. - if tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() { + if tcx.sess.dcx().has_errors_or_lint_errors().is_some() { return krate; } diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 0103a9a6d66..eba7af064be 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -311,7 +311,7 @@ pub(crate) fn run( // The visitor might have found a type error, which we need to // promote to a fatal error - if tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() { + if tcx.sess.dcx().has_errors_or_lint_errors().is_some() { return Err(String::from("Compilation failed, aborting rustdoc")); } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 42ff1210f23..907ea6d309c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -163,7 +163,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { .iter() .filter_map(|attr| { Cfg::parse(attr.meta_item()?) - .map_err(|e| self.cx.sess().diagnostic().span_err(e.span, e.msg)) + .map_err(|e| self.cx.sess().dcx().span_err(e.span, e.msg)) .ok() }) .collect::>() diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index e0f59144975..a70a9d4602e 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -384,7 +384,7 @@ pub fn report_error<'tcx, 'mir>( // Include a note like `std` does when we omit frames from a backtrace if was_pruned { - ecx.tcx.sess.diagnostic().note( + ecx.tcx.sess.dcx().note( "some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace", ); } @@ -431,7 +431,7 @@ pub fn report_leaks<'mir, 'tcx>( ); } if any_pruned { - ecx.tcx.sess.diagnostic().note( + ecx.tcx.sess.dcx().note( "some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace", ); } @@ -456,7 +456,7 @@ pub fn report_msg<'tcx>( let mut err = match diag_level { DiagLevel::Error => sess.struct_span_err(span, title).forget_guarantee(), DiagLevel::Warning => sess.struct_span_warn(span, title), - DiagLevel::Note => sess.diagnostic().struct_span_note(span, title), + DiagLevel::Note => sess.dcx().struct_span_note(span, title), }; // Show main message.