Skip to content

Commit

Permalink
Do not construct def_path_str for MustNotSuspend.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 23, 2023
1 parent 3050938 commit 9450b75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
34 changes: 27 additions & 7 deletions compiler/rustc_mir_transform/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down

0 comments on commit 9450b75

Please sign in to comment.