Skip to content

Commit c6749ae

Browse files
committed
Rename std::panic::PanicInfo to PanicHookInfo.
1 parent db2e055 commit c6749ae

File tree

7 files changed

+52
-46
lines changed

7 files changed

+52
-46
lines changed

core/src/error.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following are the primary interfaces of the panic system and the
1717
responsibilities they cover:
1818

1919
* [`panic!`] and [`panic_any`] (Constructing, Propagated automatically)
20-
* [`PanicInfo`] (Reporting)
20+
* [`PanicHookInfo`] (Reporting)
2121
* [`set_hook`], [`take_hook`], and [`#[panic_handler]`][panic-handler] (Reporting)
2222
* [`catch_unwind`] and [`resume_unwind`] (Discarding, Propagating)
2323

@@ -125,7 +125,7 @@ expect-as-precondition style error messages remember to focus on the word
125125
should be available and executable by the current user".
126126

127127
[`panic_any`]: ../../std/panic/fn.panic_any.html
128-
[`PanicInfo`]: crate::panic::PanicInfo
128+
[`PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html
129129
[`catch_unwind`]: ../../std/panic/fn.catch_unwind.html
130130
[`resume_unwind`]: ../../std/panic/fn.resume_unwind.html
131131
[`downcast`]: crate::error::Error

core/src/panic/location.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::fmt;
22

33
/// A struct containing information about the location of a panic.
44
///
5-
/// This structure is created by [`PanicInfo::location()`].
5+
/// This structure is created by [`PanicHookInfo::location()`] and [`PanicInfo::location()`].
66
///
77
/// [`PanicInfo::location()`]: crate::panic::PanicInfo::location
8+
/// [`PanicHookInfo::location()`]: ../../std/panic/struct.PanicHookInfo.html#method.location
89
///
910
/// # Examples
1011
///

core/src/panic/panic_info.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ use crate::panic::Location;
55
///
66
/// A `PanicInfo` structure is passed to the panic handler defined by `#[panic_handler]`.
77
///
8-
/// There two `PanicInfo` types:
9-
/// - `core::panic::PanicInfo`, which is used as an argument to a `#[panic_handler]` in `#![no_std]` programs.
10-
/// - [`std::panic::PanicInfo`], which is used as an argument to a panic hook set by [`std::panic::set_hook`].
8+
/// For the type used by the panic hook mechanism in `std`, see [`std::panic::PanicHookInfo`].
119
///
12-
/// This is the first one.
13-
///
14-
/// [`std::panic::set_hook`]: ../../std/panic/fn.set_hook.html
15-
/// [`std::panic::PanicInfo`]: ../../std/panic/struct.PanicInfo.html
10+
/// [`std::panic::PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html
1611
#[lang = "panic_info"]
1712
#[stable(feature = "panic_hooks", since = "1.10.0")]
1813
#[derive(Debug)]
@@ -78,13 +73,13 @@ impl<'a> PanicInfo<'a> {
7873
/// Returns the payload associated with the panic.
7974
///
8075
/// On `core::panic::PanicInfo`, this method never returns anything useful.
81-
/// It only exists because of compatibility with [`std::panic::PanicInfo`],
76+
/// It only exists because of compatibility with [`std::panic::PanicHookInfo`],
8277
/// which used to be the same type.
8378
///
84-
/// See [`std::panic::PanicInfo::payload`].
79+
/// See [`std::panic::PanicHookInfo::payload`].
8580
///
86-
/// [`std::panic::PanicInfo`]: ../../std/panic/struct.PanicInfo.html
87-
/// [`std::panic::PanicInfo::payload`]: ../../std/panic/struct.PanicInfo.html#method.payload
81+
/// [`std::panic::PanicHookInfo`]: ../../std/panic/struct.PanicHookInfo.html
82+
/// [`std::panic::PanicHookInfo::payload`]: ../../std/panic/struct.PanicHookInfo.html#method.payload
8883
#[deprecated(since = "1.74.0", note = "this never returns anything useful")]
8984
#[stable(feature = "panic_hooks", since = "1.10.0")]
9085
#[allow(deprecated, deprecated_in_future)]

core/src/panicking.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Panic support for core
22
//!
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.
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
5+
//! throws a `Box<dyn Any>` containing any type of value. Because of this,
6+
//! `std::panic::PanicHookInfo` is a different type, which contains a `&dyn Any` instead of a
7+
//! `fmt::Arguments`. std's panic handler will convert the `fmt::Arguments` to a `&dyn Any`
8+
//! containing either a `&'static str` or `String` containing the formatted message.
99
//!
1010
//! The core library cannot define any panic handler, but it can invoke it.
1111
//! This means that the functions inside of core are allowed to panic, but to be

std/src/panic.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ use crate::sync::atomic::{AtomicU8, Ordering};
1010
use crate::sync::{Condvar, Mutex, RwLock};
1111
use crate::thread::Result;
1212

13+
#[stable(feature = "panic_hooks", since = "1.10.0")]
14+
#[deprecated(
15+
since = "1.77.0",
16+
note = "use `PanicHookInfo` instead",
17+
suggestion = "std::panic::PanicHookInfo"
18+
)]
1319
/// A struct providing information about a panic.
1420
///
15-
/// `PanicInfo` structure is passed to a panic hook set by the [`set_hook`] function.
16-
///
17-
/// There two `PanicInfo` types:
18-
/// - [`core::panic::PanicInfo`], which is used as an argument to a `#[panic_handler]` in `#![no_std]` programs.
19-
/// - `std::panic::PanicInfo`, which is used as an argument to a panic hook set by [`set_hook`].
21+
/// `PanicInfo` has been renamed to [`PanicHookInfo`] to avoid confusion with
22+
/// [`core::panic::PanicInfo`].
23+
pub type PanicInfo<'a> = PanicHookInfo<'a>;
24+
25+
/// A struct providing information about a panic.
2026
///
21-
/// This is the second one.
27+
/// `PanicHookInfo` structure is passed to a panic hook set by the [`set_hook`] function.
2228
///
2329
/// # Examples
2430
///
@@ -32,26 +38,25 @@ use crate::thread::Result;
3238
/// panic!("critical system failure");
3339
/// ```
3440
///
35-
/// [`core::panic::PanicInfo`]: ../../core/panic/struct.PanicInfo.html
3641
/// [`set_hook`]: ../../std/panic/fn.set_hook.html
37-
#[stable(feature = "panic_hooks", since = "1.10.0")]
42+
#[stable(feature = "panic_hook_info", since = "CURRENT_RUSTC_VERSION")]
3843
#[derive(Debug)]
39-
pub struct PanicInfo<'a> {
44+
pub struct PanicHookInfo<'a> {
4045
payload: &'a (dyn Any + Send),
4146
location: &'a Location<'a>,
4247
can_unwind: bool,
4348
force_no_backtrace: bool,
4449
}
4550

46-
impl<'a> PanicInfo<'a> {
51+
impl<'a> PanicHookInfo<'a> {
4752
#[inline]
4853
pub(crate) fn new(
4954
location: &'a Location<'a>,
5055
payload: &'a (dyn Any + Send),
5156
can_unwind: bool,
5257
force_no_backtrace: bool,
5358
) -> Self {
54-
PanicInfo { payload, location, can_unwind, force_no_backtrace }
59+
PanicHookInfo { payload, location, can_unwind, force_no_backtrace }
5560
}
5661

5762
/// Returns the payload associated with the panic.
@@ -145,7 +150,7 @@ impl<'a> PanicInfo<'a> {
145150
}
146151

147152
#[stable(feature = "panic_hook_display", since = "1.26.0")]
148-
impl fmt::Display for PanicInfo<'_> {
153+
impl fmt::Display for PanicHookInfo<'_> {
149154
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
150155
formatter.write_str("panicked at ")?;
151156
self.location.fmt(formatter)?;
@@ -204,7 +209,7 @@ pub use core::panic::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
204209
/// The message can be of any (`Any + Send`) type, not just strings.
205210
///
206211
/// The message is wrapped in a `Box<'static + Any + Send>`, which can be
207-
/// accessed later using [`PanicInfo::payload`].
212+
/// accessed later using [`PanicHookInfo::payload`].
208213
///
209214
/// See the [`panic!`] macro for more information about panicking.
210215
#[stable(feature = "panic_any", since = "1.51.0")]

std/src/panicking.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
#![deny(unsafe_op_in_unsafe_fn)]
1111

12-
use crate::panic::{BacktraceStyle, PanicInfo};
12+
use crate::panic::{BacktraceStyle, PanicHookInfo};
1313
use core::panic::{Location, PanicPayload};
1414

1515
use crate::any::Any;
@@ -70,12 +70,12 @@ extern "C" fn __rust_foreign_exception() -> ! {
7070

7171
enum Hook {
7272
Default,
73-
Custom(Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>),
73+
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
7474
}
7575

7676
impl Hook {
7777
#[inline]
78-
fn into_box(self) -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
78+
fn into_box(self) -> Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send> {
7979
match self {
8080
Hook::Default => Box::new(default_hook),
8181
Hook::Custom(hook) => hook,
@@ -105,7 +105,7 @@ static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
105105
///
106106
/// [`take_hook`]: ./fn.take_hook.html
107107
///
108-
/// The hook is provided with a `PanicInfo` struct which contains information
108+
/// The hook is provided with a `PanicHookInfo` struct which contains information
109109
/// about the origin of the panic, including the payload passed to `panic!` and
110110
/// the source code location from which the panic originated.
111111
///
@@ -129,7 +129,7 @@ static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
129129
/// panic!("Normal panic");
130130
/// ```
131131
#[stable(feature = "panic_hooks", since = "1.10.0")]
132-
pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
132+
pub fn set_hook(hook: Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>) {
133133
if thread::panicking() {
134134
panic!("cannot modify the panic hook from a panicking thread");
135135
}
@@ -173,7 +173,7 @@ pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
173173
/// ```
174174
#[must_use]
175175
#[stable(feature = "panic_hooks", since = "1.10.0")]
176-
pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
176+
pub fn take_hook() -> Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send> {
177177
if thread::panicking() {
178178
panic!("cannot modify the panic hook from a panicking thread");
179179
}
@@ -219,7 +219,7 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
219219
#[unstable(feature = "panic_update_hook", issue = "92649")]
220220
pub fn update_hook<F>(hook_fn: F)
221221
where
222-
F: Fn(&(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), &PanicInfo<'_>)
222+
F: Fn(&(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static), &PanicHookInfo<'_>)
223223
+ Sync
224224
+ Send
225225
+ 'static,
@@ -234,7 +234,7 @@ where
234234
}
235235

236236
/// The default panic handler.
237-
fn default_hook(info: &PanicInfo<'_>) {
237+
fn default_hook(info: &PanicHookInfo<'_>) {
238238
// If this is a double panic, make sure that we print a backtrace
239239
// for this panic. Otherwise only print it if logging is enabled.
240240
let backtrace = if info.force_no_backtrace() {
@@ -791,10 +791,15 @@ fn rust_panic_with_hook(
791791
// formatting.)
792792
Hook::Default if panic_output().is_none() => {}
793793
Hook::Default => {
794-
default_hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
794+
default_hook(&PanicHookInfo::new(
795+
location,
796+
payload.get(),
797+
can_unwind,
798+
force_no_backtrace,
799+
));
795800
}
796801
Hook::Custom(ref hook) => {
797-
hook(&PanicInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
802+
hook(&PanicHookInfo::new(location, payload.get(), can_unwind, force_no_backtrace));
798803
}
799804
}
800805

test/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use std::{
5858
env, io,
5959
io::prelude::Write,
6060
mem::ManuallyDrop,
61-
panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo},
61+
panic::{self, catch_unwind, AssertUnwindSafe, PanicHookInfo},
6262
process::{self, Command, Termination},
6363
sync::mpsc::{channel, Sender},
6464
sync::{Arc, Mutex},
@@ -123,7 +123,7 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Opt
123123
// from interleaving with the panic message or appearing after it.
124124
let builtin_panic_hook = panic::take_hook();
125125
let hook = Box::new({
126-
move |info: &'_ PanicInfo<'_>| {
126+
move |info: &'_ PanicHookInfo<'_>| {
127127
if !info.can_unwind() {
128128
std::mem::forget(std::io::stderr().lock());
129129
let mut stdout = ManuallyDrop::new(std::io::stdout().lock());
@@ -726,7 +726,7 @@ fn spawn_test_subprocess(
726726

727727
fn run_test_in_spawned_subprocess(desc: TestDesc, runnable_test: RunnableTest) -> ! {
728728
let builtin_panic_hook = panic::take_hook();
729-
let record_result = Arc::new(move |panic_info: Option<&'_ PanicInfo<'_>>| {
729+
let record_result = Arc::new(move |panic_info: Option<&'_ PanicHookInfo<'_>>| {
730730
let test_result = match panic_info {
731731
Some(info) => calc_result(&desc, Err(info.payload()), &None, &None),
732732
None => calc_result(&desc, Ok(()), &None, &None),

0 commit comments

Comments
 (0)