@@ -4,6 +4,7 @@ use crate::ty::{
44 VariantIdx ,
55} ;
66use crate :: { Error , Opaque , Span , Symbol } ;
7+ use std:: borrow:: Cow ;
78use std:: io;
89/// The SMIR representation of a single function.
910#[ derive( Clone , Debug ) ]
@@ -264,51 +265,63 @@ pub enum AssertMessage {
264265}
265266
266267impl AssertMessage {
267- pub fn description ( & self ) -> Result < & ' static str , Error > {
268+ pub fn description ( & self ) -> Result < Cow < ' static , str > , Error > {
268269 match self {
269- AssertMessage :: Overflow ( BinOp :: Add , _, _) => Ok ( "attempt to add with overflow" ) ,
270- AssertMessage :: Overflow ( BinOp :: Sub , _, _) => Ok ( "attempt to subtract with overflow" ) ,
271- AssertMessage :: Overflow ( BinOp :: Mul , _, _) => Ok ( "attempt to multiply with overflow" ) ,
272- AssertMessage :: Overflow ( BinOp :: Div , _, _) => Ok ( "attempt to divide with overflow" ) ,
270+ AssertMessage :: Overflow ( BinOp :: Add , _, _) => Ok ( "attempt to add with overflow" . into ( ) ) ,
271+ AssertMessage :: Overflow ( BinOp :: Sub , _, _) => {
272+ Ok ( "attempt to subtract with overflow" . into ( ) )
273+ }
274+ AssertMessage :: Overflow ( BinOp :: Mul , _, _) => {
275+ Ok ( "attempt to multiply with overflow" . into ( ) )
276+ }
277+ AssertMessage :: Overflow ( BinOp :: Div , _, _) => {
278+ Ok ( "attempt to divide with overflow" . into ( ) )
279+ }
273280 AssertMessage :: Overflow ( BinOp :: Rem , _, _) => {
274- Ok ( "attempt to calculate the remainder with overflow" )
281+ Ok ( "attempt to calculate the remainder with overflow" . into ( ) )
282+ }
283+ AssertMessage :: OverflowNeg ( _) => Ok ( "attempt to negate with overflow" . into ( ) ) ,
284+ AssertMessage :: Overflow ( BinOp :: Shr , _, _) => {
285+ Ok ( "attempt to shift right with overflow" . into ( ) )
286+ }
287+ AssertMessage :: Overflow ( BinOp :: Shl , _, _) => {
288+ Ok ( "attempt to shift left with overflow" . into ( ) )
275289 }
276- AssertMessage :: OverflowNeg ( _) => Ok ( "attempt to negate with overflow" ) ,
277- AssertMessage :: Overflow ( BinOp :: Shr , _, _) => Ok ( "attempt to shift right with overflow" ) ,
278- AssertMessage :: Overflow ( BinOp :: Shl , _, _) => Ok ( "attempt to shift left with overflow" ) ,
279290 AssertMessage :: Overflow ( op, _, _) => Err ( error ! ( "`{:?}` cannot overflow" , op) ) ,
280- AssertMessage :: DivisionByZero ( _) => Ok ( "attempt to divide by zero" ) ,
291+ AssertMessage :: DivisionByZero ( _) => Ok ( "attempt to divide by zero" . into ( ) ) ,
281292 AssertMessage :: RemainderByZero ( _) => {
282- Ok ( "attempt to calculate the remainder with a divisor of zero" )
293+ Ok ( "attempt to calculate the remainder with a divisor of zero" . into ( ) )
283294 }
284295 AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Coroutine ) => {
285- Ok ( "coroutine resumed after completion" )
296+ Ok ( "coroutine resumed after completion" . into ( ) )
286297 }
287298 AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Async ( _) ) => {
288- Ok ( "`async fn` resumed after completion" )
299+ Ok ( "`async fn` resumed after completion" . into ( ) )
289300 }
290301 AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Gen ( _) ) => {
291- Ok ( "`async gen fn` resumed after completion" )
302+ Ok ( "`async gen fn` resumed after completion" . into ( ) )
292303 }
293304 AssertMessage :: ResumedAfterReturn ( CoroutineKind :: AsyncGen ( _) ) => {
294- Ok ( "`gen fn` should just keep returning `AssertMessage::None` after completion" )
305+ Ok ( "`gen fn` should just keep returning `AssertMessage::None` after completion"
306+ . into ( ) )
295307 }
296308 AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Coroutine ) => {
297- Ok ( "coroutine resumed after panicking" )
309+ Ok ( "coroutine resumed after panicking" . into ( ) )
298310 }
299311 AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Async ( _) ) => {
300- Ok ( "`async fn` resumed after panicking" )
312+ Ok ( "`async fn` resumed after panicking" . into ( ) )
301313 }
302314 AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Gen ( _) ) => {
303- Ok ( "`async gen fn` resumed after panicking" )
315+ Ok ( "`async gen fn` resumed after panicking" . into ( ) )
304316 }
305317 AssertMessage :: ResumedAfterPanic ( CoroutineKind :: AsyncGen ( _) ) => {
306- Ok ( "`gen fn` should just keep returning `AssertMessage::None` after panicking" )
318+ Ok ( "`gen fn` should just keep returning `AssertMessage::None` after panicking"
319+ . into ( ) )
307320 }
308321
309- AssertMessage :: BoundsCheck { .. } => Ok ( "index out of bounds" ) ,
322+ AssertMessage :: BoundsCheck { .. } => Ok ( "index out of bounds" . into ( ) ) ,
310323 AssertMessage :: MisalignedPointerDereference { .. } => {
311- Ok ( "misaligned pointer dereference" )
324+ Ok ( "misaligned pointer dereference" . into ( ) )
312325 }
313326 }
314327 }
0 commit comments