Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6749ae

Browse files
committed
Rename std::panic::PanicInfo to PanicHookInfo.
1 parentdb2e055 commitc6749ae

File tree

7 files changed

+52
-46
lines changed

7 files changed

+52
-46
lines changed

‎core/src/error.md‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 6 additions & 11 deletions
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‎

Lines changed: 6 additions & 6 deletions
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+
//!throwsa `Box<dyn Any>` containing any type of value. Because of this,
6+
//!`std::panic::PanicHookInfo` is adifferent 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‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ use crate::sync::atomic::{AtomicU8, Ordering};
1010
usecrate::sync::{Condvar,Mutex,RwLock};
1111
usecrate::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 toa 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 toa panic hook set by [`set_hook`].
21+
/// `PanicInfo`has been renamed to[`PanicHookInfo`]to avoid confusion with
22+
/// [`core::panic::PanicInfo`].
23+
pubtypePanicInfo<'a> =PanicHookInfo<'a>;
24+
25+
///A struct providing information abouta panic.
2026
///
21-
///Thisis thesecond one.
27+
///`PanicHookInfo` structureispassed to a panic hook set bythe[`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-
pubstructPanicInfo<'a>{
44+
pubstructPanicHookInfo<'a>{
4045
payload:&'a(dynAny +Send),
4146
location:&'aLocation<'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)fnnew(
4954
location:&'aLocation<'a>,
5055
payload:&'a(dynAny +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::DisplayforPanicInfo<'_>{
153+
impl fmt::DisplayforPanicHookInfo<'_>{
149154
fnfmt(&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‎

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

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

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

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

7676
implHook{
7777
#[inline]
78-
fninto_box(self) ->Box<dynFn(&PanicInfo<'_>) +'static +Sync +Send>{
78+
fninto_box(self) ->Box<dynFn(&PanicHookInfo<'_>) +'static +Sync +Send>{
7979
matchself{
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-
pubfnset_hook(hook:Box<dynFn(&PanicInfo<'_>) +'static +Sync +Send>){
132+
pubfnset_hook(hook:Box<dynFn(&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-
pubfntake_hook() ->Box<dynFn(&PanicInfo<'_>) +'static +Sync +Send>{
176+
pubfntake_hook() ->Box<dynFn(&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
pubfnupdate_hook<F>(hook_fn:F)
221221
where
222-
F:Fn(&(dynFn(&PanicInfo<'_>) +Send +Sync +'static),&PanicInfo<'_>)
222+
F:Fn(&(dynFn(&PanicHookInfo<'_>) +Send +Sync +'static),&PanicHookInfo<'_>)
223223
+Sync
224224
+Send
225225
+'static,
@@ -234,7 +234,7 @@ where
234234
}
235235

236236
/// The default panic handler.
237-
fndefault_hook(info:&PanicInfo<'_>){
237+
fndefault_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::Defaultifpanic_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‎

Lines changed: 3 additions & 3 deletions
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
letmut stdout =ManuallyDrop::new(std::io::stdout().lock());
@@ -726,7 +726,7 @@ fn spawn_test_subprocess(
726726

727727
fnrun_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)

[8]ページ先頭

©2009-2025 Movatter.jp