@@ -4,6 +4,7 @@ use crate::ty::{
4
4
VariantIdx ,
5
5
} ;
6
6
use crate :: { Error , Opaque , Span , Symbol } ;
7
+ use std:: borrow:: Cow ;
7
8
use std:: io;
8
9
/// The SMIR representation of a single function.
9
10
#[ derive( Clone , Debug ) ]
@@ -264,51 +265,63 @@ pub enum AssertMessage {
264
265
}
265
266
266
267
impl AssertMessage {
267
- pub fn description ( & self ) -> Result < & ' static str , Error > {
268
+ pub fn description ( & self ) -> Result < Cow < ' static , str > , Error > {
268
269
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
+ }
273
280
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 ( ) )
275
289
}
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" ) ,
279
290
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 ( ) ) ,
281
292
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 ( ) )
283
294
}
284
295
AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Coroutine ) => {
285
- Ok ( "coroutine resumed after completion" )
296
+ Ok ( "coroutine resumed after completion" . into ( ) )
286
297
}
287
298
AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Async ( _) ) => {
288
- Ok ( "`async fn` resumed after completion" )
299
+ Ok ( "`async fn` resumed after completion" . into ( ) )
289
300
}
290
301
AssertMessage :: ResumedAfterReturn ( CoroutineKind :: Gen ( _) ) => {
291
- Ok ( "`async gen fn` resumed after completion" )
302
+ Ok ( "`async gen fn` resumed after completion" . into ( ) )
292
303
}
293
304
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 ( ) )
295
307
}
296
308
AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Coroutine ) => {
297
- Ok ( "coroutine resumed after panicking" )
309
+ Ok ( "coroutine resumed after panicking" . into ( ) )
298
310
}
299
311
AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Async ( _) ) => {
300
- Ok ( "`async fn` resumed after panicking" )
312
+ Ok ( "`async fn` resumed after panicking" . into ( ) )
301
313
}
302
314
AssertMessage :: ResumedAfterPanic ( CoroutineKind :: Gen ( _) ) => {
303
- Ok ( "`async gen fn` resumed after panicking" )
315
+ Ok ( "`async gen fn` resumed after panicking" . into ( ) )
304
316
}
305
317
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 ( ) )
307
320
}
308
321
309
- AssertMessage :: BoundsCheck { .. } => Ok ( "index out of bounds" ) ,
322
+ AssertMessage :: BoundsCheck { .. } => Ok ( "index out of bounds" . into ( ) ) ,
310
323
AssertMessage :: MisalignedPointerDereference { .. } => {
311
- Ok ( "misaligned pointer dereference" )
324
+ Ok ( "misaligned pointer dereference" . into ( ) )
312
325
}
313
326
}
314
327
}
0 commit comments