@@ -162,7 +162,15 @@ fn report_msg<'tcx>(
162162 } else {
163163 tcx. sess . diagnostic ( ) . span_note_diag ( span, title)
164164 } ;
165- err. span_label ( span, span_msg) ;
165+ // Show main message.
166+ if span != DUMMY_SP {
167+ err. span_label ( span, span_msg) ;
168+ } else {
169+ // Make sure we show the message even when it is a dummy span.
170+ err. note ( & span_msg) ;
171+ err. note ( "(no span available)" ) ;
172+ }
173+ // Show help messages.
166174 if !helps. is_empty ( ) {
167175 // Add visual separator before backtrace.
168176 helps. last_mut ( ) . unwrap ( ) . push_str ( "\n " ) ;
@@ -198,7 +206,7 @@ pub fn register_diagnostic(e: NonHaltingDiagnostic) {
198206/// after a step was taken.
199207pub struct TopFrameInfo < ' tcx > {
200208 stack_size : usize ,
201- instance : ty:: Instance < ' tcx > ,
209+ instance : Option < ty:: Instance < ' tcx > > ,
202210 span : Span ,
203211}
204212
@@ -209,11 +217,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
209217 DIAGNOSTICS . with ( |diagnostics| assert ! ( diagnostics. borrow( ) . is_empty( ) ) ) ;
210218
211219 let this = self . eval_context_ref ( ) ;
220+ if this. active_thread_stack ( ) . is_empty ( ) {
221+ // Diagnostics can happen even with the emoty stack (e.g. deallocation thread-local statics).
222+ return TopFrameInfo { stack_size : 0 , instance : None , span : DUMMY_SP } ;
223+ }
212224 let frame = this. frame ( ) ;
213225
214226 TopFrameInfo {
215227 stack_size : this. active_thread_stack ( ) . len ( ) ,
216- instance : frame. instance ,
228+ instance : Some ( frame. instance ) ,
217229 span : frame. current_source_info ( ) . map_or ( DUMMY_SP , |si| si. span ) ,
218230 }
219231 }
@@ -237,15 +249,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
237249 if stacktrace. len ( ) < info. stack_size {
238250 assert ! ( stacktrace. len( ) == info. stack_size-1 , "we should never pop more than one frame at once" ) ;
239251 let frame_info = FrameInfo {
240- instance : info. instance ,
252+ instance : info. instance . unwrap ( ) ,
241253 span : info. span ,
242254 lint_root : None ,
243255 } ;
244256 stacktrace. insert ( 0 , frame_info) ;
245- } else {
257+ } else if let Some ( instance ) = info . instance {
246258 // Adjust topmost frame.
247259 stacktrace[ 0 ] . span = info. span ;
248- assert_eq ! ( stacktrace[ 0 ] . instance, info . instance, "we should not pop and push a frame in one step" ) ;
260+ assert_eq ! ( stacktrace[ 0 ] . instance, instance, "we should not pop and push a frame in one step" ) ;
249261 }
250262
251263 // Show diagnostics.
0 commit comments