@@ -164,6 +164,20 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
164
164
}
165
165
}
166
166
167
+ impl < ' mir , ' tcx , Tag , Extra > Frame < ' mir , ' tcx , Tag , Extra > {
168
+ /// Return the `SourceInfo` of the current instruction.
169
+ pub fn current_source_info ( & self ) -> Option < mir:: SourceInfo > {
170
+ self . block . map ( |block| {
171
+ let block = & self . body . basic_blocks ( ) [ block] ;
172
+ if self . stmt < block. statements . len ( ) {
173
+ block. statements [ self . stmt ] . source_info
174
+ } else {
175
+ block. terminator ( ) . source_info
176
+ }
177
+ } )
178
+ }
179
+ }
180
+
167
181
impl < ' mir , ' tcx , M : Machine < ' mir , ' tcx > > HasDataLayout for InterpCx < ' mir , ' tcx , M > {
168
182
#[ inline]
169
183
fn data_layout ( & self ) -> & layout:: TargetDataLayout {
@@ -828,34 +842,28 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
828
842
pub fn generate_stacktrace ( & self , explicit_span : Option < Span > ) -> Vec < FrameInfo < ' tcx > > {
829
843
let mut last_span = None ;
830
844
let mut frames = Vec :: new ( ) ;
831
- for & Frame { instance , span , body , block , stmt , .. } in self . stack ( ) . iter ( ) . rev ( ) {
845
+ for frame in self . stack ( ) . iter ( ) . rev ( ) {
832
846
// make sure we don't emit frames that are duplicates of the previous
833
- if explicit_span == Some ( span) {
834
- last_span = Some ( span) ;
847
+ if explicit_span == Some ( frame . span ) {
848
+ last_span = Some ( frame . span ) ;
835
849
continue ;
836
850
}
837
851
if let Some ( last) = last_span {
838
- if last == span {
852
+ if last == frame . span {
839
853
continue ;
840
854
}
841
855
} else {
842
- last_span = Some ( span) ;
856
+ last_span = Some ( frame . span ) ;
843
857
}
844
858
845
- let lint_root = block. and_then ( |block| {
846
- let block = & body. basic_blocks ( ) [ block] ;
847
- let source_info = if stmt < block. statements . len ( ) {
848
- block. statements [ stmt] . source_info
849
- } else {
850
- block. terminator ( ) . source_info
851
- } ;
852
- match & body. source_scopes [ source_info. scope ] . local_data {
859
+ let lint_root = frame. current_source_info ( ) . and_then ( |source_info| {
860
+ match & frame. body . source_scopes [ source_info. scope ] . local_data {
853
861
mir:: ClearCrossCrate :: Set ( data) => Some ( data. lint_root ) ,
854
862
mir:: ClearCrossCrate :: Clear => None ,
855
863
}
856
864
} ) ;
857
865
858
- frames. push ( FrameInfo { call_site : span, instance, lint_root } ) ;
866
+ frames. push ( FrameInfo { call_site : frame . span , instance : frame . instance , lint_root } ) ;
859
867
}
860
868
trace ! ( "generate stacktrace: {:#?}, {:?}" , frames, explicit_span) ;
861
869
frames
0 commit comments