@@ -1275,9 +1275,11 @@ impl<O> AssertKind<O> {
1275
1275
matches ! ( self , OverflowNeg ( ..) | Overflow ( Add | Sub | Mul | Shl | Shr , ..) )
1276
1276
}
1277
1277
1278
- /// Getting a description does not require `O` to be printable, and does not
1279
- /// require allocation.
1280
- /// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` separately.
1278
+ /// Get the message that is printed at runtime when this assertion fails.
1279
+ ///
1280
+ /// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` by
1281
+ /// invoking the appropriate lang item (panic_bounds_check/panic_misaligned_pointer_dereference)
1282
+ /// instead of printing a static message.
1281
1283
pub fn description ( & self ) -> & ' static str {
1282
1284
use AssertKind :: * ;
1283
1285
match self {
@@ -1303,6 +1305,11 @@ impl<O> AssertKind<O> {
1303
1305
}
1304
1306
1305
1307
/// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing.
1308
+ ///
1309
+ /// Needs to be kept in sync with the run-time behavior (which is defined by
1310
+ /// `AssertKind::description` and the lang items mentioned in its docs).
1311
+ /// Note that we deliberately show more details here than we do at runtime, such as the actual
1312
+ /// numbers that overflowed -- it is much easier to do so here than at runtime.
1306
1313
pub fn fmt_assert_args < W : Write > ( & self , f : & mut W ) -> fmt:: Result
1307
1314
where
1308
1315
O : Debug ,
@@ -1358,6 +1365,12 @@ impl<O> AssertKind<O> {
1358
1365
}
1359
1366
}
1360
1367
1368
+ /// Format the diagnostic message for use in a lint (e.g. when the assertion fails during const-eval).
1369
+ ///
1370
+ /// Needs to be kept in sync with the run-time behavior (which is defined by
1371
+ /// `AssertKind::description` and the lang items mentioned in its docs).
1372
+ /// Note that we deliberately show more details here than we do at runtime, such as the actual
1373
+ /// numbers that overflowed -- it is much easier to do so here than at runtime.
1361
1374
pub fn diagnostic_message ( & self ) -> DiagnosticMessage {
1362
1375
use crate :: fluent_generated:: * ;
1363
1376
use AssertKind :: * ;
0 commit comments