Note the type when unable to drop values in compile time
This commit is contained in:
parent
4d44e09cb1
commit
2ce1cd511f
37 changed files with 158 additions and 150 deletions
|
@ -1009,7 +1009,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
|
||||
if needs_non_const_drop {
|
||||
self.check_op_spanned(
|
||||
ops::LiveDrop { dropped_at: Some(terminator.source_info.span) },
|
||||
ops::LiveDrop {
|
||||
dropped_at: Some(terminator.source_info.span),
|
||||
dropped_ty: ty_of_dropped_place,
|
||||
},
|
||||
err_span,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -422,10 +422,11 @@ impl<'tcx> NonConstOp<'tcx> for InlineAsm {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LiveDrop {
|
||||
pub struct LiveDrop<'tcx> {
|
||||
pub dropped_at: Option<Span>,
|
||||
pub dropped_ty: Ty<'tcx>,
|
||||
}
|
||||
impl<'tcx> NonConstOp<'tcx> for LiveDrop {
|
||||
impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
|
||||
fn build_error(
|
||||
&self,
|
||||
ccx: &ConstCx<'_, 'tcx>,
|
||||
|
@ -435,9 +436,13 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop {
|
|||
ccx.tcx.sess,
|
||||
span,
|
||||
E0493,
|
||||
"destructors cannot be evaluated at compile-time"
|
||||
"destructor of `{}` cannot be evaluated at compile-time",
|
||||
self.dropped_ty,
|
||||
);
|
||||
err.span_label(
|
||||
span,
|
||||
format!("the destructor for this type cannot be evaluated in {}s", ccx.const_kind()),
|
||||
);
|
||||
err.span_label(span, format!("{}s cannot evaluate destructors", ccx.const_kind()));
|
||||
if let Some(span) = self.dropped_at {
|
||||
err.span_label(span, "value is dropped here");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::{self, BasicBlock, Location};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_span::{symbol::sym, Span};
|
||||
|
||||
use super::check::Qualifs;
|
||||
|
@ -58,9 +58,9 @@ impl<'mir, 'tcx> std::ops::Deref for CheckLiveDrops<'mir, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl CheckLiveDrops<'_, '_> {
|
||||
fn check_live_drop(&self, span: Span) {
|
||||
ops::LiveDrop { dropped_at: None }.build_error(self.ccx, span).emit();
|
||||
impl<'tcx> CheckLiveDrops<'_, 'tcx> {
|
||||
fn check_live_drop(&self, span: Span, dropped_ty: Ty<'tcx>) {
|
||||
ops::LiveDrop { dropped_at: None, dropped_ty }.build_error(self.ccx, span).emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
|
|||
}
|
||||
|
||||
if dropped_place.is_indirect() {
|
||||
self.check_live_drop(terminator.source_info.span);
|
||||
self.check_live_drop(terminator.source_info.span, dropped_ty);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
|
|||
if self.qualifs.needs_non_const_drop(self.ccx, dropped_place.local, location) {
|
||||
// Use the span where the dropped local was declared for the error.
|
||||
let span = self.body.local_decls[dropped_place.local].source_info.span;
|
||||
self.check_live_drop(span);
|
||||
self.check_live_drop(span, dropped_ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue