Skip to content
forked from rust-lang/rust
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cca865d

Browse files
committedJun 11, 2024
Update doc comment about core::panicking.
1 parent 221a90c commit cca865d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎core/src/panicking.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
//! Panic support for core
22
//!
3-
//! The core library cannot define panicking, but it does *declare* panicking. This
4-
//! means that the functions inside of core are allowed to panic, but to be
3+
//! In core, panicking is always done with a message, resulting in a core::panic::PanicInfo
4+
//! containing a fmt::Arguments. In std, however, panicking can be done with panic_any, which throws
5+
//! a Box<dyn Any> containing any type of value. Because of this, std::panic::PanicInfo is a
6+
//! different type, which contains a &dyn Any instead of a fmt::Arguments.
7+
//! std's panic handler will convert the fmt::Arguments to a &dyn Any containing either a
8+
//! &'static str or String containing the formatted message.
9+
//!
10+
//! The core library cannot define any panic handler, but it can invoke it.
11+
//! This means that the functions inside of core are allowed to panic, but to be
512
//! useful an upstream crate must define panicking for core to use. The current
613
//! interface for panicking is:
714
//!
@@ -10,11 +17,6 @@
1017
//! # { loop {} }
1118
//! ```
1219
//!
13-
//! This definition allows for panicking with any general message, but it does not
14-
//! allow for failing with a `Box<Any>` value. (`PanicInfo` just contains a `&(dyn Any + Send)`,
15-
//! for which we fill in a dummy value in `PanicInfo::internal_constructor`.)
16-
//! The reason for this is that core is not allowed to allocate.
17-
//!
1820
//! This module contains a few other panicking functions, but these are just the
1921
//! necessary lang items for the compiler. All panics are funneled through this
2022
//! one function. The actual symbol is declared through the `#[panic_handler]` attribute.

0 commit comments

Comments
 (0)
Failed to load comments.