diff options
| author | bors <bors@rust-lang.org> | 2023-08-30 06:16:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-30 06:16:17 +0000 |
| commit | 7659abc63d33223fa366c8781c81698e28a21e6c (patch) | |
| tree | 466c82b0bd0bf04f17096ce9f495ae6ac4a3515d /compiler/rustc_const_eval/src/interpret/eval_context.rs | |
| parent | 82c2eb48ee275638b437fa2a044e9d44de0ca0c6 (diff) | |
| parent | ea2347843c24a59367952b0463505539f1b69a93 (diff) | |
| download | rust-7659abc63d33223fa366c8781c81698e28a21e6c.tar.gz rust-7659abc63d33223fa366c8781c81698e28a21e6c.zip | |
Auto merge of #115370 - matthiaskrgr:rollup-l0e1zuj, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #113565 (Make SIGSEGV handler emit nicer backtraces) - #114704 (parser: not insert dummy field in struct) - #115272 (miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors) - #115313 (Make `get_return_block()` return `Some` only for HIR nodes in body) - #115347 (suggest removing `impl` in generic trait bound position) - #115355 (new solver: handle edge case of a recursion limit of 0) - #115363 (Don't suggest adding parentheses to call an inaccessible method.) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/eval_context.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/eval_context.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 90848dbfbc7..bd3d87470c9 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -25,8 +25,8 @@ use super::{ Scalar, StackPopJump, }; use crate::errors::{self, ErroneousConstUsed}; -use crate::fluent_generated as fluent; use crate::util; +use crate::{fluent_generated as fluent, ReportErrorExt}; pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// Stores the `Machine` instance. @@ -432,6 +432,27 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .map_or(CRATE_HIR_ID, |def_id| self.tcx.hir().local_def_id_to_hir_id(def_id)) } + /// Turn the given error into a human-readable string. Expects the string to be printed, so if + /// `RUSTC_CTFE_BACKTRACE` is set this will show a backtrace of the rustc internals that + /// triggered the error. + /// + /// This is NOT the preferred way to render an error; use `report` from `const_eval` instead. + /// However, this is useful when error messages appear in ICEs. + pub fn format_error(&self, e: InterpErrorInfo<'tcx>) -> String { + let (e, backtrace) = e.into_parts(); + backtrace.print_backtrace(); + // FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the + // label and arguments from the InterpError. + let handler = &self.tcx.sess.parse_sess.span_diagnostic; + #[allow(rustc::untranslatable_diagnostic)] + let mut diag = self.tcx.sess.struct_allow(""); + let msg = e.diagnostic_message(); + e.add_args(handler, &mut diag); + let s = handler.eagerly_translate_to_string(msg, diag.args()); + diag.cancel(); + s + } + #[inline(always)] pub(crate) fn stack(&self) -> &[Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>] { M::stack(self) |
