Do not construct def_path_str for MustNotSuspend.

This commit is contained in:
Camille GILLOT 2023-05-16 10:47:50 +00:00
parent 3050938abd
commit 9450b75986
2 changed files with 29 additions and 8 deletions

View File

@ -4,7 +4,9 @@ use rustc_errors::{
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{self, Lint};
use rustc_span::def_id::DefId;
use rustc_span::Span;
#[derive(LintDiagnostic)]
@ -237,20 +239,38 @@ pub(crate) struct FnItemRef {
pub ident: String,
}
#[derive(LintDiagnostic)]
#[diag(mir_transform_must_not_suspend)]
pub(crate) struct MustNotSupend<'a> {
#[label]
pub(crate) struct MustNotSupend<'tcx, 'a> {
pub tcx: TyCtxt<'tcx>,
pub yield_sp: Span,
#[subdiagnostic]
pub reason: Option<MustNotSuspendReason>,
#[help]
pub src_sp: Span,
pub pre: &'a str,
pub def_path: String,
pub def_id: DefId,
pub post: &'a str,
}
// Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
fn decorate_lint<'b>(
self,
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
diag.span_label(self.yield_sp, crate::fluent_generated::_subdiag::label);
if let Some(reason) = self.reason {
diag.subdiagnostic(reason);
}
diag.span_help(self.src_sp, crate::fluent_generated::_subdiag::help);
diag.set_arg("pre", self.pre);
diag.set_arg("def_path", self.tcx.def_path_str(self.def_id));
diag.set_arg("post", self.post);
diag
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
crate::fluent_generated::mir_transform_must_not_suspend
}
}
#[derive(Subdiagnostic)]
#[note(mir_transform_note)]
pub(crate) struct MustNotSuspendReason {

View File

@ -1954,11 +1954,12 @@ fn check_must_not_suspend_def(
hir_id,
data.source_span,
errors::MustNotSupend {
tcx,
yield_sp: data.yield_span,
reason,
src_sp: data.source_span,
pre: data.descr_pre,
def_path: tcx.def_path_str(def_id),
def_id,
post: data.descr_post,
},
);