Skip to content

Commit e75fbae

Browse files
committed
add second message for livedrop errors
1 parent f315c35 commit e75fbae

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/librustc_mir/transform/check_consts/ops.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,20 @@ pub struct InlineAsm;
160160
impl NonConstOp for InlineAsm {}
161161

162162
#[derive(Debug)]
163-
pub struct LiveDrop;
163+
pub struct LiveDrop(pub Option<Span>);
164164
impl NonConstOp for LiveDrop {
165165
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
166-
struct_span_err!(
166+
let mut diagnostic = struct_span_err!(
167167
ccx.tcx.sess,
168168
span,
169169
E0493,
170170
"destructors cannot be evaluated at compile-time"
171-
)
172-
.span_label(span, format!("{}s cannot evaluate destructors", ccx.const_kind()))
173-
.emit();
171+
);
172+
diagnostic.span_label(span, format!("{}s cannot evaluate destructors", ccx.const_kind()));
173+
if let Some(span) = self.0 {
174+
diagnostic.span_label(span, "value is dropped here");
175+
}
176+
diagnostic.emit();
174177
}
175178
}
176179

src/librustc_mir/transform/check_consts/post_drop_elaboration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl std::ops::Deref for CheckLiveDrops<'mir, 'tcx> {
5858

5959
impl CheckLiveDrops<'mir, 'tcx> {
6060
fn check_live_drop(&self, span: Span) {
61-
ops::non_const(self.ccx, ops::LiveDrop, span);
61+
ops::non_const(self.ccx, ops::LiveDrop(None), span);
6262
}
6363
}
6464

src/librustc_mir/transform/check_consts/validation.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,10 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
588588
};
589589

590590
if needs_drop {
591-
self.check_op_spanned(ops::LiveDrop, err_span);
591+
self.check_op_spanned(
592+
ops::LiveDrop(Some(terminator.source_info.span)),
593+
err_span,
594+
);
592595
}
593596
}
594597

0 commit comments

Comments
 (0)