Skip to content

Commit 30b32c6

Browse files
committed
Miri: port error backtraces to std::backtrace
1 parent bf45975 commit 30b32c6

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3977,7 +3977,6 @@ name = "rustc_middle"
39773977
version = "0.0.0"
39783978
dependencies = [
39793979
"arena",
3980-
"backtrace",
39813980
"bitflags",
39823981
"byteorder",
39833982
"log",

src/librustc_middle/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ rustc_index = { path = "../librustc_index" }
3030
rustc_serialize = { path = "../libserialize", package = "serialize" }
3131
rustc_ast = { path = "../librustc_ast" }
3232
rustc_span = { path = "../librustc_span" }
33-
backtrace = "0.3.40"
3433
byteorder = { version = "1.3" }
3534
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3635
measureme = "0.7.1"

src/librustc_middle/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! This API is completely unstable and subject to change.
2424
2525
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
26+
#![feature(backtrace)]
2627
#![feature(bool_to_option)]
2728
#![feature(box_patterns)]
2829
#![feature(box_syntax)]

src/librustc_middle/mir/interpret/error.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::ty::query::TyCtxtAt;
66
use crate::ty::tls;
77
use crate::ty::{self, layout, Ty};
88

9-
use backtrace::Backtrace;
109
use rustc_data_structures::sync::Lock;
1110
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorReported};
1211
use rustc_hir as hir;
@@ -15,7 +14,7 @@ use rustc_macros::HashStable;
1514
use rustc_session::CtfeBacktrace;
1615
use rustc_span::{def_id::DefId, Pos, Span};
1716
use rustc_target::abi::{Align, Size};
18-
use std::{any::Any, fmt, mem};
17+
use std::{any::Any, backtrace::Backtrace, fmt, mem};
1918

2019
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
2120
pub enum ErrorHandled {
@@ -219,16 +218,15 @@ impl fmt::Display for InterpErrorInfo<'_> {
219218
}
220219

221220
impl InterpErrorInfo<'_> {
222-
pub fn print_backtrace(&mut self) {
223-
if let Some(ref mut backtrace) = self.backtrace {
224-
print_backtrace(&mut *backtrace);
221+
pub fn print_backtrace(&self) {
222+
if let Some(backtrace) = self.backtrace.as_ref() {
223+
print_backtrace(backtrace);
225224
}
226225
}
227226
}
228227

229-
fn print_backtrace(backtrace: &mut Backtrace) {
230-
backtrace.resolve();
231-
eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace);
228+
fn print_backtrace(backtrace: &Backtrace) {
229+
eprintln!("\n\nAn error occurred in miri:\n{}", backtrace);
232230
}
233231

234232
impl From<ErrorHandled> for InterpErrorInfo<'_> {
@@ -255,11 +253,11 @@ impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
255253

256254
let backtrace = match capture_backtrace {
257255
CtfeBacktrace::Disabled => None,
258-
CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),
256+
CtfeBacktrace::Capture => Some(Box::new(Backtrace::force_capture())),
259257
CtfeBacktrace::Immediate => {
260258
// Print it now.
261-
let mut backtrace = Backtrace::new_unresolved();
262-
print_backtrace(&mut backtrace);
259+
let backtrace = Backtrace::force_capture();
260+
print_backtrace(&backtrace);
263261
None
264262
}
265263
};

src/librustc_mir/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Error for ConstEvalErrKind {}
5252
/// Should be called only if the error is actually going to to be reported!
5353
pub fn error_to_const_error<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>(
5454
ecx: &InterpCx<'mir, 'tcx, M>,
55-
mut error: InterpErrorInfo<'tcx>,
55+
error: InterpErrorInfo<'tcx>,
5656
) -> ConstEvalErr<'tcx> {
5757
error.print_backtrace();
5858
let stacktrace = ecx.generate_stacktrace();

0 commit comments

Comments
 (0)