@@ -22,12 +22,15 @@ pub enum ConstEvalErrKind {
22
22
Panic { msg : Symbol , line : u32 , col : u32 , file : Symbol } ,
23
23
}
24
24
25
- // The errors become `MachineStop` with plain strings when being raised.
25
+ // Non-panic errors become `MachineStop` with plain strings when being raised.
26
26
// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
27
27
// handle these.
28
28
impl < ' tcx > Into < InterpErrorInfo < ' tcx > > for ConstEvalErrKind {
29
29
fn into ( self ) -> InterpErrorInfo < ' tcx > {
30
- err_machine_stop ! ( self . to_string( ) ) . into ( )
30
+ match self {
31
+ ConstEvalErrKind :: Panic { msg, .. } => InterpError :: Panic ( msg) . into ( ) ,
32
+ _ => err_machine_stop ! ( self . to_string( ) ) . into ( ) ,
33
+ }
31
34
}
32
35
}
33
36
@@ -150,13 +153,14 @@ impl<'tcx> ConstEvalErr<'tcx> {
150
153
} ;
151
154
trace ! ( "reporting const eval failure at {:?}" , self . span) ;
152
155
153
- let err_msg = match & self . error {
156
+ let ( err_msg, is_panic ) = match & self . error {
154
157
InterpError :: MachineStop ( msg) => {
155
158
// A custom error (`ConstEvalErrKind` in `librustc_mir/interp/const_eval/error.rs`).
156
159
// Should be turned into a string by now.
157
- msg. downcast_ref :: < String > ( ) . expect ( "invalid MachineStop payload" ) . clone ( )
160
+ ( msg. downcast_ref :: < String > ( ) . expect ( "invalid MachineStop payload" ) . clone ( ) , false )
158
161
}
159
- err => err. to_string ( ) ,
162
+ InterpError :: Panic ( msg) => ( msg. to_string ( ) , true ) ,
163
+ err => ( err. to_string ( ) , false ) ,
160
164
} ;
161
165
162
166
let finish = |mut err : DiagnosticBuilder < ' _ > , span_msg : Option < String > | {
@@ -193,7 +197,13 @@ impl<'tcx> ConstEvalErr<'tcx> {
193
197
rustc_session:: lint:: builtin:: CONST_ERR ,
194
198
hir_id,
195
199
tcx. span ,
196
- |lint| finish ( lint. build ( message) , Some ( err_msg) ) ,
200
+ |lint| {
201
+ if is_panic {
202
+ finish ( lint. build ( & err_msg) , None )
203
+ } else {
204
+ finish ( lint. build ( message) , Some ( err_msg) )
205
+ }
206
+ } ,
197
207
) ;
198
208
ErrorHandled :: Linted
199
209
} else {
0 commit comments