Skip to content

Commit 9450b75

Browse files
committed
Do not construct def_path_str for MustNotSuspend.
1 parent 3050938 commit 9450b75

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

compiler/rustc_mir_transform/src/errors.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use rustc_errors::{
44
};
55
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
66
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
7+
use rustc_middle::ty::TyCtxt;
78
use rustc_session::lint::{self, Lint};
9+
use rustc_span::def_id::DefId;
810
use rustc_span::Span;
911

1012
#[derive(LintDiagnostic)]
@@ -237,20 +239,38 @@ pub(crate) struct FnItemRef {
237239
pub ident: String,
238240
}
239241

240-
#[derive(LintDiagnostic)]
241-
#[diag(mir_transform_must_not_suspend)]
242-
pub(crate) struct MustNotSupend<'a> {
243-
#[label]
242+
pub(crate) struct MustNotSupend<'tcx, 'a> {
243+
pub tcx: TyCtxt<'tcx>,
244244
pub yield_sp: Span,
245-
#[subdiagnostic]
246245
pub reason: Option<MustNotSuspendReason>,
247-
#[help]
248246
pub src_sp: Span,
249247
pub pre: &'a str,
250-
pub def_path: String,
248+
pub def_id: DefId,
251249
pub post: &'a str,
252250
}
253251

252+
// Needed for def_path_str
253+
impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
254+
fn decorate_lint<'b>(
255+
self,
256+
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
257+
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
258+
diag.span_label(self.yield_sp, crate::fluent_generated::_subdiag::label);
259+
if let Some(reason) = self.reason {
260+
diag.subdiagnostic(reason);
261+
}
262+
diag.span_help(self.src_sp, crate::fluent_generated::_subdiag::help);
263+
diag.set_arg("pre", self.pre);
264+
diag.set_arg("def_path", self.tcx.def_path_str(self.def_id));
265+
diag.set_arg("post", self.post);
266+
diag
267+
}
268+
269+
fn msg(&self) -> rustc_errors::DiagnosticMessage {
270+
crate::fluent_generated::mir_transform_must_not_suspend
271+
}
272+
}
273+
254274
#[derive(Subdiagnostic)]
255275
#[note(mir_transform_note)]
256276
pub(crate) struct MustNotSuspendReason {

compiler/rustc_mir_transform/src/generator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,11 +1954,12 @@ fn check_must_not_suspend_def(
19541954
hir_id,
19551955
data.source_span,
19561956
errors::MustNotSupend {
1957+
tcx,
19571958
yield_sp: data.yield_span,
19581959
reason,
19591960
src_sp: data.source_span,
19601961
pre: data.descr_pre,
1961-
def_path: tcx.def_path_str(def_id),
1962+
def_id,
19621963
post: data.descr_post,
19631964
},
19641965
);

0 commit comments

Comments
 (0)