1
- use std:: fmt;
1
+ use std:: fmt:: { self , Write } ;
2
2
use std:: num:: NonZeroU64 ;
3
3
4
4
use log:: trace;
5
5
6
- use rustc_const_eval:: ReportErrorExt ;
7
6
use rustc_errors:: DiagnosticMessage ;
8
7
use rustc_span:: { source_map:: DUMMY_SP , SpanData , Symbol } ;
9
8
use rustc_target:: abi:: { Align , Size } ;
@@ -271,27 +270,30 @@ pub fn report_error<'tcx, 'mir>(
271
270
} ;
272
271
( title, helps)
273
272
} else {
274
- #[ rustfmt:: skip]
275
273
let title = match e. kind ( ) {
276
- UndefinedBehavior ( UndefinedBehaviorInfo :: ValidationError ( e) ) if matches ! ( e. kind, ValidationErrorKind :: PointerAsInt { .. } | ValidationErrorKind :: PartialPointer ) =>
277
- bug ! ( "This validation error should be impossible in Miri: {:?}" , e. kind) ,
278
- UndefinedBehavior ( _) =>
279
- "Undefined Behavior" ,
280
- ResourceExhaustion ( _) =>
281
- "resource exhaustion" ,
274
+ UndefinedBehavior ( UndefinedBehaviorInfo :: ValidationError ( validation_err) )
275
+ if matches ! (
276
+ validation_err. kind,
277
+ ValidationErrorKind :: PointerAsInt { .. } | ValidationErrorKind :: PartialPointer
278
+ ) =>
279
+ {
280
+ ecx. handle_ice ( ) ; // print interpreter backtrace
281
+ bug ! ( "This validation error should be impossible in Miri: {}" , ecx. format_error( e) ) ;
282
+ }
283
+ UndefinedBehavior ( _) => "Undefined Behavior" ,
284
+ ResourceExhaustion ( _) => "resource exhaustion" ,
282
285
Unsupported (
283
286
// We list only the ones that can actually happen.
284
- UnsupportedOpInfo :: Unsupported ( _)
285
- ) =>
286
- "unsupported operation" ,
287
+ UnsupportedOpInfo :: Unsupported ( _) | UnsupportedOpInfo :: UnsizedLocal ,
288
+ ) => "unsupported operation" ,
287
289
InvalidProgram (
288
290
// We list only the ones that can actually happen.
289
- InvalidProgramInfo :: AlreadyReported ( _) |
290
- InvalidProgramInfo :: Layout ( .. )
291
- ) =>
292
- "post-monomorphization error" ,
293
- kind =>
294
- bug ! ( "This error should be impossible in Miri: {kind:?}" ) ,
291
+ InvalidProgramInfo :: AlreadyReported ( _) | InvalidProgramInfo :: Layout ( .. ) ,
292
+ ) => "post-monomorphization error" ,
293
+ _ => {
294
+ ecx . handle_ice ( ) ; // print interpreter backtrace
295
+ bug ! ( "This error should be impossible in Miri: {}" , ecx . format_error ( e ) ) ;
296
+ }
295
297
} ;
296
298
#[ rustfmt:: skip]
297
299
let helps = match e. kind ( ) {
@@ -333,30 +335,23 @@ pub fn report_error<'tcx, 'mir>(
333
335
334
336
let stacktrace = ecx. generate_stacktrace ( ) ;
335
337
let ( stacktrace, was_pruned) = prune_stacktrace ( stacktrace, & ecx. machine ) ;
336
- let ( e, backtrace) = e. into_parts ( ) ;
337
- backtrace. print_backtrace ( ) ;
338
-
339
- // We want to dump the allocation if this is `InvalidUninitBytes`. Since `add_args` consumes
340
- // the `InterpError`, we extract the variables it before that.
341
- let extra = match e {
342
- UndefinedBehavior ( UndefinedBehaviorInfo :: InvalidUninitBytes ( Some ( ( alloc_id, access) ) ) ) =>
343
- Some ( ( alloc_id, access) ) ,
344
- _ => None ,
345
- } ;
346
338
347
- // FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the
348
- // label and arguments from the InterpError.
349
- let e = {
350
- let handler = & ecx. tcx . sess . parse_sess . span_diagnostic ;
351
- let mut diag = ecx. tcx . sess . struct_allow ( "" ) ;
352
- let msg = e. diagnostic_message ( ) ;
353
- e. add_args ( handler, & mut diag) ;
354
- let s = handler. eagerly_translate_to_string ( msg, diag. args ( ) ) ;
355
- diag. cancel ( ) ;
356
- s
357
- } ;
339
+ // We want to dump the allocation if this is `InvalidUninitBytes`. Since `format_error` consumes `e`, we compute the outut early.
340
+ let mut extra = String :: new ( ) ;
341
+ match e. kind ( ) {
342
+ UndefinedBehavior ( UndefinedBehaviorInfo :: InvalidUninitBytes ( Some ( ( alloc_id, access) ) ) ) => {
343
+ writeln ! (
344
+ extra,
345
+ "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:" ,
346
+ range = access. bad,
347
+ )
348
+ . unwrap ( ) ;
349
+ writeln ! ( extra, "{:?}" , ecx. dump_alloc( * alloc_id) ) . unwrap ( ) ;
350
+ }
351
+ _ => { }
352
+ }
358
353
359
- msg. insert ( 0 , e ) ;
354
+ msg. insert ( 0 , ecx . format_error ( e ) ) ;
360
355
361
356
report_msg (
362
357
DiagLevel :: Error ,
@@ -375,6 +370,8 @@ pub fn report_error<'tcx, 'mir>(
375
370
) ;
376
371
}
377
372
373
+ eprint ! ( "{extra}" ) ; // newlines are already in the string
374
+
378
375
// Debug-dump all locals.
379
376
for ( i, frame) in ecx. active_thread_stack ( ) . iter ( ) . enumerate ( ) {
380
377
trace ! ( "-------------------" ) ;
@@ -385,15 +382,6 @@ pub fn report_error<'tcx, 'mir>(
385
382
}
386
383
}
387
384
388
- // Extra output to help debug specific issues.
389
- if let Some ( ( alloc_id, access) ) = extra {
390
- eprintln ! (
391
- "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:" ,
392
- range = access. bad,
393
- ) ;
394
- eprintln ! ( "{:?}" , ecx. dump_alloc( alloc_id) ) ;
395
- }
396
-
397
385
None
398
386
}
399
387
0 commit comments