Rename `Session::span_diagnostic` as `Session::dcx`.

This commit is contained in:
Nicholas Nethercote 2023-12-18 06:21:26 +11:00
parent 9df1576e1d
commit 09af8a667c
66 changed files with 176 additions and 204 deletions

View File

@ -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 {}..{}",

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
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 {

View File

@ -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| {

View File

@ -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(),
},

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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

View File

@ -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 {

View File

@ -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];
};

View File

@ -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];
};

View File

@ -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<Symbol> {
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(())
}

View File

@ -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;

View File

@ -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),

View File

@ -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(

View File

@ -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.

View File

@ -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);

View File

@ -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");

View File

@ -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);

View File

@ -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());

View File

@ -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();

View File

@ -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());

View File

@ -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 {:?}",

View File

@ -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<DiagnosticMessage>,
) -> 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<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
self.sess.diagnostic().span_err(sp, msg);
self.sess.dcx().span_err(sp, msg);
}
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
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

View File

@ -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::<Vec<mbe::TokenTree>>(),
_ => 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::<Vec<mbe::TokenTree>>(),
_ => 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()

View File

@ -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 });
}

View File

@ -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

View File

@ -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",
);

View File

@ -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: _;`.

View File

@ -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)

View File

@ -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.

View File

@ -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();
}

View File

@ -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 {

View File

@ -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;
};

View File

@ -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?",

View File

@ -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;
};

View File

@ -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);
}
}
}

View File

@ -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()),
}
}
}

View File

@ -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() {

View File

@ -382,12 +382,12 @@ pub fn run_compiler<R: Send>(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;

View File

@ -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) => {

View File

@ -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);

View File

@ -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());
});
}

View File

@ -16,7 +16,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
}
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);

View File

@ -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
}

View File

@ -267,7 +267,7 @@ impl CStore {
let unused_externs =
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();
tcx.sess.diagnostic().emit_unused_externs(
tcx.sess.dcx().emit_unused_externs(
level,
json_unused_externs.is_loud(),
&unused_externs,

View File

@ -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 {

View File

@ -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();

View File

@ -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();

View File

@ -31,8 +31,8 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
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),
}
})

View File

@ -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),
)

View File

@ -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()
{

View File

@ -924,7 +924,7 @@ impl<D: Deps> DepGraphData<D> {
// 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);

View File

@ -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<Qcx: QueryContext>(

View File

@ -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"));
}
}

View File

@ -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<DiagnosticMessage>,
) -> 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<DiagnosticMessage>,
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<DiagnosticMessage>,
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<DiagnosticMessage>) -> 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<DiagnosticMessage>,
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<DiagnosticMessage>,
) -> 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<DiagnosticMessage>) -> 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<DiagnosticMessage>,
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<DiagnosticMessage>,
) -> 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<DiagnosticMessage>,
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<DiagnosticMessage>,
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<DiagnosticMessage>,
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<DiagnosticMessage>,
) -> 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<S: Into<MultiSpan>>(
@ -438,17 +438,17 @@ impl Session {
msg: impl Into<DiagnosticMessage>,
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<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
self.diagnostic().struct_fatal(msg)
self.dcx().struct_fatal(msg)
}
#[rustc_lint_diagnostics]
#[track_caller]
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
self.diagnostic().span_fatal(sp, msg)
self.dcx().span_fatal(sp, msg)
}
#[rustc_lint_diagnostics]
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
@ -457,11 +457,11 @@ impl Session {
msg: impl Into<DiagnosticMessage>,
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<DiagnosticMessage>) -> ! {
self.diagnostic().fatal(msg)
self.dcx().fatal(msg)
}
#[rustc_lint_diagnostics]
#[track_caller]
@ -470,7 +470,7 @@ impl Session {
sp: S,
msg: impl Into<DiagnosticMessage>,
) -> ErrorGuaranteed {
self.diagnostic().span_err(sp, msg)
self.dcx().span_err(sp, msg)
}
#[rustc_lint_diagnostics]
pub fn span_err_with_code<S: Into<MultiSpan>>(
@ -479,13 +479,13 @@ impl Session {
msg: impl Into<DiagnosticMessage>,
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<DiagnosticMessage>) -> 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<ErrorGuaranteed> {
self.diagnostic().has_errors()
self.dcx().has_errors()
}
pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
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<ErrorGuaranteed> {
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<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
self.diagnostic().span_warn(sp, msg)
self.dcx().span_warn(sp, msg)
}
#[rustc_lint_diagnostics]
@ -602,14 +602,14 @@ impl Session {
msg: impl Into<DiagnosticMessage>,
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<DiagnosticMessage>) {
self.diagnostic().warn(msg)
self.dcx().warn(msg)
}
/// Ensures that compilation cannot succeed.
@ -634,7 +634,7 @@ impl Session {
sp: S,
msg: impl Into<DiagnosticMessage>,
) -> 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<DiagnosticMessage>) {
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<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
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<DiagnosticMessage>) -> 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 {

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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");
}

View File

@ -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;
}

View File

@ -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"));
}

View File

@ -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::<Vec<_>>()

View File

@ -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.