@@ -4,17 +4,20 @@ use crate::hir::map::definitions::DefPathData;
44use crate :: mir;
55use crate :: ty:: layout:: { Align , LayoutError , Size } ;
66use crate :: ty:: query:: TyCtxtAt ;
7+ use crate :: ty:: tls;
78use crate :: ty:: { self , layout, Ty } ;
89
910use backtrace:: Backtrace ;
1011use hir:: GeneratorKind ;
12+ use rustc_data_structures:: sync:: Lock ;
1113use rustc_errors:: { struct_span_err, DiagnosticBuilder } ;
1214use rustc_hir as hir;
1315use rustc_macros:: HashStable ;
16+ use rustc_session:: CtfeBacktrace ;
1417use rustc_span:: symbol:: Symbol ;
1518use rustc_span:: { Pos , Span } ;
1619use rustc_target:: spec:: abi:: Abi ;
17- use std:: { any:: Any , env , fmt} ;
20+ use std:: { any:: Any , fmt} ;
1821
1922#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , RustcEncodable , RustcDecodable ) ]
2023pub enum ErrorHandled {
@@ -241,21 +244,26 @@ impl From<ErrorHandled> for InterpErrorInfo<'tcx> {
241244
242245impl < ' tcx > From < InterpError < ' tcx > > for InterpErrorInfo < ' tcx > {
243246 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+ } ) ;
248255
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
256264 }
257- _ => None ,
258265 } ;
266+
259267 InterpErrorInfo { kind, backtrace }
260268 }
261269}
0 commit comments