@@ -149,44 +149,45 @@ impl<O> AssertKind<O> {
149149 matches ! ( self , OverflowNeg ( ..) | Overflow ( Add | Sub | Mul | Shl | Shr , ..) )
150150 }
151151
152- /// Get the message that is printed at runtime when this assertion fails .
152+ /// Get the lang item that is invoked to print a static message when this assert fires .
153153 ///
154154 /// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` by
155155 /// invoking the appropriate lang item (panic_bounds_check/panic_misaligned_pointer_dereference)
156- /// instead of printing a static message.
157- pub fn description ( & self ) -> & ' static str {
156+ /// instead of printing a static message. Those have dynamic arguments that aren't present for
157+ /// the rest of the messages here.
158+ pub fn description ( & self ) -> LangItem {
158159 use AssertKind :: * ;
159160 match self {
160- Overflow ( BinOp :: Add , _, _) => "attempt to add with overflow" ,
161- Overflow ( BinOp :: Sub , _, _) => "attempt to subtract with overflow" ,
162- Overflow ( BinOp :: Mul , _, _) => "attempt to multiply with overflow" ,
163- Overflow ( BinOp :: Div , _, _) => "attempt to divide with overflow" ,
164- Overflow ( BinOp :: Rem , _, _) => "attempt to calculate the remainder with overflow" ,
165- OverflowNeg ( _) => "attempt to negate with overflow" ,
166- Overflow ( BinOp :: Shr , _, _) => "attempt to shift right with overflow" ,
167- Overflow ( BinOp :: Shl , _, _) => "attempt to shift left with overflow" ,
161+ Overflow ( BinOp :: Add , _, _) => LangItem :: PanicAddOverflow ,
162+ Overflow ( BinOp :: Sub , _, _) => LangItem :: PanicSubOverflow ,
163+ Overflow ( BinOp :: Mul , _, _) => LangItem :: PanicMulOverflow ,
164+ Overflow ( BinOp :: Div , _, _) => LangItem :: PanicDivOverflow ,
165+ Overflow ( BinOp :: Rem , _, _) => LangItem :: PanicRemOverflow ,
166+ OverflowNeg ( _) => LangItem :: PanicNegOverflow ,
167+ Overflow ( BinOp :: Shr , _, _) => LangItem :: PanicShrOverflow ,
168+ Overflow ( BinOp :: Shl , _, _) => LangItem :: PanicShlOverflow ,
168169 Overflow ( op, _, _) => bug ! ( "{:?} cannot overflow" , op) ,
169- DivisionByZero ( _) => "attempt to divide by zero" ,
170- RemainderByZero ( _) => "attempt to calculate the remainder with a divisor of zero" ,
171- ResumedAfterReturn ( CoroutineKind :: Coroutine ( _) ) => "coroutine resumed after completion" ,
170+ DivisionByZero ( _) => LangItem :: PanicDivZero ,
171+ RemainderByZero ( _) => LangItem :: PanicRemZero ,
172+ ResumedAfterReturn ( CoroutineKind :: Coroutine ( _) ) => LangItem :: PanicCoroutineResumed ,
172173 ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
173- "`async fn` resumed after completion"
174+ LangItem :: PanicAsyncFnResumed
174175 }
175176 ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
176- "`async gen fn` resumed after completion"
177+ LangItem :: PanicAsyncGenFnResumed
177178 }
178179 ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
179- "`gen fn` should just keep returning `None` after completion"
180+ LangItem :: PanicGenFnNone
180181 }
181- ResumedAfterPanic ( CoroutineKind :: Coroutine ( _) ) => "coroutine resumed after panicking" ,
182+ ResumedAfterPanic ( CoroutineKind :: Coroutine ( _) ) => LangItem :: PanicCoroutineResumedPanic ,
182183 ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
183- "`async fn` resumed after panicking"
184+ LangItem :: PanicAsyncFnResumedPanic
184185 }
185186 ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
186- "`async gen fn` resumed after panicking"
187+ LangItem :: PanicAsyncGenFnResumedPanic
187188 }
188189 ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
189- "`gen fn` should just keep returning `None` after panicking"
190+ LangItem :: PanicGenFnNonePanic
190191 }
191192
192193 BoundsCheck { .. } | MisalignedPointerDereference { .. } => {
@@ -246,13 +247,37 @@ impl<O> AssertKind<O> {
246247 Overflow ( BinOp :: Shl , _, r) => {
247248 write ! ( f, "\" attempt to shift left by `{{}}`, which would overflow\" , {r:?}" )
248249 }
250+ Overflow ( op, _, _) => bug ! ( "{:?} cannot overflow" , op) ,
249251 MisalignedPointerDereference { required, found } => {
250252 write ! (
251253 f,
252254 "\" misaligned pointer dereference: address must be a multiple of {{}} but is {{}}\" , {required:?}, {found:?}"
253255 )
254256 }
255- _ => write ! ( f, "\" {}\" " , self . description( ) ) ,
257+ ResumedAfterReturn ( CoroutineKind :: Coroutine ( _) ) => {
258+ write ! ( f, "\" coroutine resumed after completion\" " )
259+ }
260+ ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
261+ write ! ( f, "\" `async fn` resumed after completion\" " )
262+ }
263+ ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
264+ write ! ( f, "\" `async gen fn` resumed after completion\" " )
265+ }
266+ ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
267+ write ! ( f, "\" `gen fn` should just keep returning `None` after completion\" " )
268+ }
269+ ResumedAfterPanic ( CoroutineKind :: Coroutine ( _) ) => {
270+ write ! ( f, "\" coroutine resumed after panicking\" " )
271+ }
272+ ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
273+ write ! ( f, "\" `async fn` resumed after panicking\" " )
274+ }
275+ ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
276+ write ! ( f, "\" `async gen fn` resumed after panicking\" " )
277+ }
278+ ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
279+ write ! ( f, "\" `gen fn` should just keep returning `None` after panicking\" " )
280+ }
256281 }
257282 }
258283
0 commit comments