add second message for livedrop errors

This commit is contained in:
Christian Poveda 2020-06-19 14:46:04 -05:00
parent f315c35a77
commit e75fbaee45
No known key found for this signature in database
GPG key ID: 27525EF5E7420A50
3 changed files with 13 additions and 7 deletions

View file

@ -160,17 +160,20 @@ pub struct InlineAsm;
impl NonConstOp for InlineAsm {}
#[derive(Debug)]
pub struct LiveDrop;
pub struct LiveDrop(pub Option<Span>);
impl NonConstOp for LiveDrop {
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
struct_span_err!(
let mut diagnostic = struct_span_err!(
ccx.tcx.sess,
span,
E0493,
"destructors cannot be evaluated at compile-time"
)
.span_label(span, format!("{}s cannot evaluate destructors", ccx.const_kind()))
.emit();
);
diagnostic.span_label(span, format!("{}s cannot evaluate destructors", ccx.const_kind()));
if let Some(span) = self.0 {
diagnostic.span_label(span, "value is dropped here");
}
diagnostic.emit();
}
}

View file

@ -58,7 +58,7 @@ impl std::ops::Deref for CheckLiveDrops<'mir, 'tcx> {
impl CheckLiveDrops<'mir, 'tcx> {
fn check_live_drop(&self, span: Span) {
ops::non_const(self.ccx, ops::LiveDrop, span);
ops::non_const(self.ccx, ops::LiveDrop(None), span);
}
}

View file

@ -588,7 +588,10 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
};
if needs_drop {
self.check_op_spanned(ops::LiveDrop, err_span);
self.check_op_spanned(
ops::LiveDrop(Some(terminator.source_info.span)),
err_span,
);
}
}