Skip to content

Commit ddea3f9

Browse files
committed
document more things as needing to stay in sync
1 parent 4c53783 commit ddea3f9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,11 @@ impl<O> AssertKind<O> {
12751275
matches!(self, OverflowNeg(..) | Overflow(Add | Sub | Mul | Shl | Shr, ..))
12761276
}
12771277

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.
12811283
pub fn description(&self) -> &'static str {
12821284
use AssertKind::*;
12831285
match self {
@@ -1303,6 +1305,11 @@ impl<O> AssertKind<O> {
13031305
}
13041306

13051307
/// 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.
13061313
pub fn fmt_assert_args<W: Write>(&self, f: &mut W) -> fmt::Result
13071314
where
13081315
O: Debug,
@@ -1358,6 +1365,12 @@ impl<O> AssertKind<O> {
13581365
}
13591366
}
13601367

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.
13611374
pub fn diagnostic_message(&self) -> DiagnosticMessage {
13621375
use crate::fluent_generated::*;
13631376
use AssertKind::*;

library/core/src/panicking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! {
188188
#[lang = "panic_cannot_unwind"] // needed by codegen for panic in nounwind function
189189
#[rustc_nounwind]
190190
fn panic_cannot_unwind() -> ! {
191+
// Keep the text in sync with `UnwindTerminateReason::as_str` in `rustc_middle`.
191192
panic_nounwind("panic in a function that cannot unwind")
192193
}
193194

@@ -203,6 +204,7 @@ fn panic_cannot_unwind() -> ! {
203204
#[lang = "panic_in_cleanup"] // needed by codegen for panic in nounwind function
204205
#[rustc_nounwind]
205206
fn panic_in_cleanup() -> ! {
207+
// Keep the text in sync with `UnwindTerminateReason::as_str` in `rustc_middle`.
206208
panic_nounwind("panic in a destructor during cleanup")
207209
}
208210

0 commit comments

Comments
 (0)