[Miri] Use a session variable instead of checking for an env var always · rust-lang/rust@5357f83 (original) (raw)

`@@ -5,15 +5,18 @@ use crate::mir;

`

5

5

`use crate::mir::interpret::ConstValue;

`

6

6

`use crate::ty::layout::{Align, LayoutError, Size};

`

7

7

`use crate::ty::query::TyCtxtAt;

`

``

8

`+

use crate::ty::tls;

`

8

9

`use crate::ty::{self, layout, Ty};

`

9

10

``

10

11

`use backtrace::Backtrace;

`

``

12

`+

use rustc_data_structures::sync::Lock;

`

11

13

`use rustc_errors::{struct_span_err, DiagnosticBuilder};

`

12

14

`use rustc_hir as hir;

`

13

15

`use rustc_macros::HashStable;

`

``

16

`+

use rustc_session::CtfeBacktrace;

`

14

17

`use rustc_span::{Pos, Span};

`

15

18

`use rustc_target::spec::abi::Abi;

`

16

``

`-

use std::{any::Any, env, fmt};

`

``

19

`+

use std::{any::Any, fmt};

`

17

20

``

18

21

`#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]

`

19

22

`pub enum ErrorHandled {

`

`@@ -257,21 +260,25 @@ impl From for InterpErrorInfo<'_> {

`

257

260

``

258

261

`impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {

`

259

262

`fn from(kind: InterpError<'tcx>) -> Self {

`

260

``

`-

let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {

`

261

``

`` -

// Matching RUST_BACKTRACE -- we treat "0" the same as "not present".

``

262

``

`-

Ok(ref val) if val != "0" => {

`

263

``

`-

let mut backtrace = Backtrace::new_unresolved();

`

``

263

`+

let capture_backtrace = tls::with_context_opt(|ctxt| {

`

``

264

`+

if let Some(ctxt) = ctxt {

`

``

265

`+

*Lock::borrow(&ctxt.tcx.sess.ctfe_backtrace)

`

``

266

`+

} else {

`

``

267

`+

CtfeBacktrace::Disabled

`

``

268

`+

}

`

``

269

`+

});

`

264

270

``

265

``

`-

if val == "immediate" {

`

266

``

`-

// Print it now.

`

267

``

`-

print_backtrace(&mut backtrace);

`

268

``

`-

None

`

269

``

`-

} else {

`

270

``

`-

Some(Box::new(backtrace))

`

271

``

`-

}

`

``

271

`+

let backtrace = match capture_backtrace {

`

``

272

`+

CtfeBacktrace::Disabled => None,

`

``

273

`+

CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),

`

``

274

`+

CtfeBacktrace::Immediate => {

`

``

275

`+

// Print it now.

`

``

276

`+

let mut backtrace = Backtrace::new_unresolved();

`

``

277

`+

print_backtrace(&mut backtrace);

`

``

278

`+

None

`

272

279

`}

`

273

``

`-

_ => None,

`

274

280

`};

`

``

281

+

275

282

`InterpErrorInfo { kind, backtrace }

`

276

283

`}

`

277

284

`}

`