@@ -149,44 +149,45 @@ impl<O> AssertKind<O> {
149
149
matches ! ( self , OverflowNeg ( ..) | Overflow ( Add | Sub | Mul | Shl | Shr , ..) )
150
150
}
151
151
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 .
153
153
///
154
154
/// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` by
155
155
/// 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 {
158
159
use AssertKind :: * ;
159
160
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 ,
168
169
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 ,
172
173
ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
173
- "`async fn` resumed after completion"
174
+ LangItem :: PanicAsyncFnResumed
174
175
}
175
176
ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
176
- "`async gen fn` resumed after completion"
177
+ LangItem :: PanicAsyncGenFnResumed
177
178
}
178
179
ResumedAfterReturn ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
179
- "`gen fn` should just keep returning `None` after completion"
180
+ LangItem :: PanicGenFnNone
180
181
}
181
- ResumedAfterPanic ( CoroutineKind :: Coroutine ( _) ) => "coroutine resumed after panicking" ,
182
+ ResumedAfterPanic ( CoroutineKind :: Coroutine ( _) ) => LangItem :: PanicCoroutineResumedPanic ,
182
183
ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) ) => {
183
- "`async fn` resumed after panicking"
184
+ LangItem :: PanicAsyncFnResumedPanic
184
185
}
185
186
ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) ) => {
186
- "`async gen fn` resumed after panicking"
187
+ LangItem :: PanicAsyncGenFnResumedPanic
187
188
}
188
189
ResumedAfterPanic ( CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) ) => {
189
- "`gen fn` should just keep returning `None` after panicking"
190
+ LangItem :: PanicGenFnNonePanic
190
191
}
191
192
192
193
BoundsCheck { .. } | MisalignedPointerDereference { .. } => {
@@ -246,13 +247,37 @@ impl<O> AssertKind<O> {
246
247
Overflow ( BinOp :: Shl , _, r) => {
247
248
write ! ( f, "\" attempt to shift left by `{{}}`, which would overflow\" , {r:?}" )
248
249
}
250
+ Overflow ( op, _, _) => bug ! ( "{:?} cannot overflow" , op) ,
249
251
MisalignedPointerDereference { required, found } => {
250
252
write ! (
251
253
f,
252
254
"\" misaligned pointer dereference: address must be a multiple of {{}} but is {{}}\" , {required:?}, {found:?}"
253
255
)
254
256
}
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
+ }
256
281
}
257
282
}
258
283
0 commit comments