@@ -162,7 +162,15 @@ fn report_msg<'tcx>(
162
162
} else {
163
163
tcx. sess . diagnostic ( ) . span_note_diag ( span, title)
164
164
} ;
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.
166
174
if !helps. is_empty ( ) {
167
175
// Add visual separator before backtrace.
168
176
helps. last_mut ( ) . unwrap ( ) . push_str ( "\n " ) ;
@@ -198,7 +206,7 @@ pub fn register_diagnostic(e: NonHaltingDiagnostic) {
198
206
/// after a step was taken.
199
207
pub struct TopFrameInfo < ' tcx > {
200
208
stack_size : usize ,
201
- instance : ty:: Instance < ' tcx > ,
209
+ instance : Option < ty:: Instance < ' tcx > > ,
202
210
span : Span ,
203
211
}
204
212
@@ -209,11 +217,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
209
217
DIAGNOSTICS . with ( |diagnostics| assert ! ( diagnostics. borrow( ) . is_empty( ) ) ) ;
210
218
211
219
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
+ }
212
224
let frame = this. frame ( ) ;
213
225
214
226
TopFrameInfo {
215
227
stack_size : this. active_thread_stack ( ) . len ( ) ,
216
- instance : frame. instance ,
228
+ instance : Some ( frame. instance ) ,
217
229
span : frame. current_source_info ( ) . map_or ( DUMMY_SP , |si| si. span ) ,
218
230
}
219
231
}
@@ -237,15 +249,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
237
249
if stacktrace. len ( ) < info. stack_size {
238
250
assert ! ( stacktrace. len( ) == info. stack_size-1 , "we should never pop more than one frame at once" ) ;
239
251
let frame_info = FrameInfo {
240
- instance : info. instance ,
252
+ instance : info. instance . unwrap ( ) ,
241
253
span : info. span ,
242
254
lint_root : None ,
243
255
} ;
244
256
stacktrace. insert ( 0 , frame_info) ;
245
- } else {
257
+ } else if let Some ( instance ) = info . instance {
246
258
// Adjust topmost frame.
247
259
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" ) ;
249
261
}
250
262
251
263
// Show diagnostics.
0 commit comments