1
1
use std:: cell:: RefCell ;
2
+ use std:: fmt;
2
3
3
4
use rustc_span:: DUMMY_SP ;
4
5
@@ -12,6 +13,26 @@ pub enum TerminationInfo {
12
13
ExperimentalUb { msg : String , url : String }
13
14
}
14
15
16
+ impl fmt:: Debug for TerminationInfo {
17
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
18
+ use TerminationInfo :: * ;
19
+ match self {
20
+ Exit ( code) =>
21
+ write ! ( f, "the evaluated program completed with exit code {}" , code) ,
22
+ Abort ( None ) =>
23
+ write ! ( f, "the evaluated program aborted execution" ) ,
24
+ Abort ( Some ( msg) ) =>
25
+ write ! ( f, "the evaluated program aborted execution: {}" , msg) ,
26
+ UnsupportedInIsolation ( msg) =>
27
+ write ! ( f, "{}" , msg) ,
28
+ ExperimentalUb { msg, .. } =>
29
+ write ! ( f, "{}" , msg) ,
30
+ }
31
+ }
32
+ }
33
+
34
+ impl MachineStopType for TerminationInfo { }
35
+
15
36
/// Miri specific diagnostics
16
37
pub enum NonHaltingDiagnostic {
17
38
PoppedTrackedPointerTag ( Item ) ,
@@ -25,21 +46,18 @@ pub fn report_error<'tcx, 'mir>(
25
46
) -> Option < i64 > {
26
47
use InterpError :: * ;
27
48
28
- e. print_backtrace ( ) ;
29
- let ( title, msg, helps) = match e. kind {
30
- MachineStop ( info) => {
49
+ let ( title, helps) = match e. kind {
50
+ MachineStop ( ref info) => {
31
51
let info = info. downcast_ref :: < TerminationInfo > ( ) . expect ( "invalid MachineStop payload" ) ;
32
52
use TerminationInfo :: * ;
33
- let ( title, msg ) = match info {
53
+ let title = match info {
34
54
Exit ( code) => return Some ( * code) ,
35
- Abort ( None ) =>
36
- ( "abnormal termination" , format ! ( "the evaluated program aborted execution" ) ) ,
37
- Abort ( Some ( msg) ) =>
38
- ( "abnormal termination" , format ! ( "the evaluated program aborted execution: {}" , msg) ) ,
39
- UnsupportedInIsolation ( msg) =>
40
- ( "unsupported operation" , format ! ( "{}" , msg) ) ,
41
- ExperimentalUb { msg, .. } =>
42
- ( "Undefined Behavior" , format ! ( "{}" , msg) ) ,
55
+ Abort ( _) =>
56
+ "abnormal termination" ,
57
+ UnsupportedInIsolation ( _) =>
58
+ "unsupported operation" ,
59
+ ExperimentalUb { .. } =>
60
+ "Undefined Behavior" ,
43
61
} ;
44
62
let helps = match info {
45
63
UnsupportedInIsolation ( _) =>
@@ -51,16 +69,16 @@ pub fn report_error<'tcx, 'mir>(
51
69
] ,
52
70
_ => vec ! [ ] ,
53
71
} ;
54
- ( title, msg , helps)
72
+ ( title, helps)
55
73
}
56
74
_ => {
57
- let ( title, msg ) = match e. kind {
75
+ let title = match e. kind {
58
76
Unsupported ( _) =>
59
- ( "unsupported operation" , e . to_string ( ) ) ,
77
+ "unsupported operation" ,
60
78
UndefinedBehavior ( _) =>
61
- ( "Undefined Behavior" , e . to_string ( ) ) ,
79
+ "Undefined Behavior" ,
62
80
ResourceExhaustion ( _) =>
63
- ( "resource exhaustion" , e . to_string ( ) ) ,
81
+ "resource exhaustion" ,
64
82
_ =>
65
83
bug ! ( "This error should be impossible in Miri: {}" , e) ,
66
84
} ;
@@ -76,9 +94,12 @@ pub fn report_error<'tcx, 'mir>(
76
94
] ,
77
95
_ => vec ! [ ] ,
78
96
} ;
79
- ( title, msg , helps)
97
+ ( title, helps)
80
98
}
81
99
} ;
100
+
101
+ e. print_backtrace ( ) ;
102
+ let msg = e. to_string ( ) ;
82
103
report_msg ( ecx, & format ! ( "{}: {}" , title, msg) , msg, & helps, true )
83
104
}
84
105
0 commit comments