@@ -4,17 +4,20 @@ use crate::hir::map::definitions::DefPathData;
4
4
use crate :: mir;
5
5
use crate :: ty:: layout:: { Align , LayoutError , Size } ;
6
6
use crate :: ty:: query:: TyCtxtAt ;
7
+ use crate :: ty:: tls;
7
8
use crate :: ty:: { self , layout, Ty } ;
8
9
9
10
use backtrace:: Backtrace ;
10
11
use hir:: GeneratorKind ;
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:: symbol:: Symbol ;
15
18
use rustc_span:: { Pos , Span } ;
16
19
use rustc_target:: spec:: abi:: Abi ;
17
- use std:: { any:: Any , env , fmt} ;
20
+ use std:: { any:: Any , fmt} ;
18
21
19
22
#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , RustcEncodable , RustcDecodable ) ]
20
23
pub enum ErrorHandled {
@@ -241,21 +244,26 @@ impl From<ErrorHandled> for InterpErrorInfo<'tcx> {
241
244
242
245
impl < ' tcx > From < InterpError < ' tcx > > for InterpErrorInfo < ' tcx > {
243
246
fn from ( kind : InterpError < ' tcx > ) -> Self {
244
- let backtrace = match env:: var ( "RUSTC_CTFE_BACKTRACE" ) {
245
- // Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
246
- Ok ( ref val) if val != "0" => {
247
- let mut backtrace = Backtrace :: new_unresolved ( ) ;
247
+ let capture_backtrace = tls:: with_context_opt ( |ctxt| {
248
+ if let Some ( ctxt) = ctxt {
249
+ let l = Lock :: borrow ( & ctxt. tcx . sess . ctfe_backtrace ) ;
250
+ * l
251
+ } else {
252
+ CtfeBacktrace :: Disabled
253
+ }
254
+ } ) ;
248
255
249
- if val == "immediate" {
250
- // Print it now.
251
- print_backtrace ( & mut backtrace) ;
252
- None
253
- } else {
254
- Some ( Box :: new ( backtrace) )
255
- }
256
+ let backtrace = match capture_backtrace {
257
+ CtfeBacktrace :: Disabled => None ,
258
+ CtfeBacktrace :: Capture => Some ( Box :: new ( Backtrace :: new_unresolved ( ) ) ) ,
259
+ CtfeBacktrace :: Immediate => {
260
+ // Print it now.
261
+ let mut backtrace = Backtrace :: new_unresolved ( ) ;
262
+ print_backtrace ( & mut backtrace) ;
263
+ None
256
264
}
257
- _ => None ,
258
265
} ;
266
+
259
267
InterpErrorInfo { kind, backtrace }
260
268
}
261
269
}
0 commit comments