rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
This commit is contained in:
parent
461e807801
commit
bb8d4307eb
104 changed files with 705 additions and 550 deletions
|
@ -1,4 +1,3 @@
|
|||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
@ -247,11 +246,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
if ecx.tcx.is_ctfe_mir_available(def.did) {
|
||||
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
|
||||
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
|
||||
ecx.tcx.sess.delay_span_bug(
|
||||
let guar = ecx.tcx.sess.delay_span_bug(
|
||||
rustc_span::DUMMY_SP,
|
||||
"This is likely a const item that is missing from its impl",
|
||||
);
|
||||
throw_inval!(AlreadyReported(ErrorGuaranteed {}));
|
||||
throw_inval!(AlreadyReported(guar));
|
||||
} else {
|
||||
let path = ecx.tcx.def_path_str(def.did);
|
||||
Err(ConstEvalErrKind::NeedsRfc(format!("calling extern function `{}`", path))
|
||||
|
|
|
@ -406,8 +406,11 @@ pub fn intern_const_alloc_recursive<
|
|||
} else if ecx.memory.dead_alloc_map.contains_key(&alloc_id) {
|
||||
// Codegen does not like dangling pointers, and generally `tcx` assumes that
|
||||
// all allocations referenced anywhere actually exist. So, make sure we error here.
|
||||
ecx.tcx.sess.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
|
||||
return Err(ErrorGuaranteed);
|
||||
let reported = ecx
|
||||
.tcx
|
||||
.sess
|
||||
.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
|
||||
return Err(reported);
|
||||
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
|
||||
// We have hit an `AllocId` that is neither in local or global memory and isn't
|
||||
// marked as dangling by local memory. That should be impossible.
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::fmt::Write;
|
||||
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout};
|
||||
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer};
|
||||
use rustc_middle::ty::{ConstInt, Ty};
|
||||
use rustc_middle::ty::{ConstInt, DelaySpanBugEmitted, Ty};
|
||||
use rustc_middle::{mir, ty};
|
||||
use rustc_target::abi::{Abi, HasDataLayout, Size, TagEncoding};
|
||||
use rustc_target::abi::{VariantIdx, Variants};
|
||||
|
@ -565,7 +564,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
|
||||
match val.val() {
|
||||
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
|
||||
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorGuaranteed)),
|
||||
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => {
|
||||
throw_inval!(AlreadyReported(reported))
|
||||
}
|
||||
ty::ConstKind::Unevaluated(uv) => {
|
||||
let instance = self.resolve(uv.def, uv.substs)?;
|
||||
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
|
||||
|
|
|
@ -259,7 +259,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
|||
self.tcx.sess.diagnostic().emit_diagnostic(&error);
|
||||
}
|
||||
} else {
|
||||
assert!(self.tcx.sess.has_errors());
|
||||
assert!(self.tcx.sess.has_errors().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,8 +327,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
|||
|
||||
match op.importance() {
|
||||
ops::DiagnosticImportance::Primary => {
|
||||
self.error_emitted = Some(ErrorGuaranteed);
|
||||
err.emit();
|
||||
let reported = err.emit();
|
||||
self.error_emitted = Some(reported);
|
||||
}
|
||||
|
||||
ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue