@@ -279,6 +279,32 @@ impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
279279 }
280280 } )
281281 }
282+
283+ #[ must_use]
284+ pub fn generate_stacktrace_from_stack ( stack : & [ Self ] ) -> Vec < FrameInfo < ' tcx > > {
285+ let mut frames = Vec :: new ( ) ;
286+ // This deliberately does *not* honor `requires_caller_location` since it is used for much
287+ // more than just panics.
288+ for frame in stack. iter ( ) . rev ( ) {
289+ let span = match frame. loc {
290+ Left ( loc) => {
291+ // If the stacktrace passes through MIR-inlined source scopes, add them.
292+ let mir:: SourceInfo { mut span, scope } = * frame. body . source_info ( loc) ;
293+ let mut scope_data = & frame. body . source_scopes [ scope] ;
294+ while let Some ( ( instance, call_span) ) = scope_data. inlined {
295+ frames. push ( FrameInfo { span, instance } ) ;
296+ span = call_span;
297+ scope_data = & frame. body . source_scopes [ scope_data. parent_scope . unwrap ( ) ] ;
298+ }
299+ span
300+ }
301+ Right ( span) => span,
302+ } ;
303+ frames. push ( FrameInfo { span, instance : frame. instance } ) ;
304+ }
305+ trace ! ( "generate stacktrace: {:#?}" , frames) ;
306+ frames
307+ }
282308}
283309
284310// FIXME: only used by miri, should be removed once translatable.
@@ -1166,37 +1192,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11661192 PlacePrinter { ecx : self , place : * place. place ( ) }
11671193 }
11681194
1169- #[ must_use]
1170- pub fn generate_stacktrace_from_stack (
1171- stack : & [ Frame < ' mir , ' tcx , M :: Provenance , M :: FrameExtra > ] ,
1172- ) -> Vec < FrameInfo < ' tcx > > {
1173- let mut frames = Vec :: new ( ) ;
1174- // This deliberately does *not* honor `requires_caller_location` since it is used for much
1175- // more than just panics.
1176- for frame in stack. iter ( ) . rev ( ) {
1177- let span = match frame. loc {
1178- Left ( loc) => {
1179- // If the stacktrace passes through MIR-inlined source scopes, add them.
1180- let mir:: SourceInfo { mut span, scope } = * frame. body . source_info ( loc) ;
1181- let mut scope_data = & frame. body . source_scopes [ scope] ;
1182- while let Some ( ( instance, call_span) ) = scope_data. inlined {
1183- frames. push ( FrameInfo { span, instance } ) ;
1184- span = call_span;
1185- scope_data = & frame. body . source_scopes [ scope_data. parent_scope . unwrap ( ) ] ;
1186- }
1187- span
1188- }
1189- Right ( span) => span,
1190- } ;
1191- frames. push ( FrameInfo { span, instance : frame. instance } ) ;
1192- }
1193- trace ! ( "generate stacktrace: {:#?}" , frames) ;
1194- frames
1195- }
1196-
11971195 #[ must_use]
11981196 pub fn generate_stacktrace ( & self ) -> Vec < FrameInfo < ' tcx > > {
1199- Self :: generate_stacktrace_from_stack ( self . stack ( ) )
1197+ Frame :: generate_stacktrace_from_stack ( self . stack ( ) )
12001198 }
12011199}
12021200
0 commit comments