@@ -22,12 +22,15 @@ pub enum ConstEvalErrKind {
2222 Panic { msg : Symbol , line : u32 , col : u32 , file : Symbol } ,
2323}
2424
25- // The errors become `MachineStop` with plain strings when being raised.
25+ // Non-panic errors become `MachineStop` with plain strings when being raised.
2626// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
2727// handle these.
2828impl < ' tcx > Into < InterpErrorInfo < ' tcx > > for ConstEvalErrKind {
2929 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+ }
3134 }
3235}
3336
@@ -150,13 +153,14 @@ impl<'tcx> ConstEvalErr<'tcx> {
150153 } ;
151154 trace ! ( "reporting const eval failure at {:?}" , self . span) ;
152155
153- let err_msg = match & self . error {
156+ let ( err_msg, is_panic ) = match & self . error {
154157 InterpError :: MachineStop ( msg) => {
155158 // A custom error (`ConstEvalErrKind` in `librustc_mir/interp/const_eval/error.rs`).
156159 // 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 )
158161 }
159- err => err. to_string ( ) ,
162+ InterpError :: Panic ( msg) => ( msg. to_string ( ) , true ) ,
163+ err => ( err. to_string ( ) , false ) ,
160164 } ;
161165
162166 let finish = |mut err : DiagnosticBuilder < ' _ > , span_msg : Option < String > | {
@@ -193,7 +197,13 @@ impl<'tcx> ConstEvalErr<'tcx> {
193197 rustc_session:: lint:: builtin:: CONST_ERR ,
194198 hir_id,
195199 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+ } ,
197207 ) ;
198208 ErrorHandled :: Linted
199209 } else {
0 commit comments