rust/compiler
许杰友 Jieyou Xu (Joe) d9deb38ec0
Rollup merge of #115974 - m-ou-se:panicinfo-and-panicinfo, r=Amanieu
Split core's PanicInfo and std's PanicInfo

`PanicInfo` is used in two ways:

1. As argument to the `#[panic_handler]` in `no_std` context.
2. As argument to the [panic hook](https://doc.rust-lang.org/stable/std/panic/fn.set_hook.html) in `std` context.

In situation 1, the `PanicInfo` always has a *message* (of type `fmt::Arguments`), but never a *payload* (of type `&dyn Any`).

In situation 2, the `PanicInfo` always has a *payload* (which is often a `String`), but not always a *message*.

Having these as the same type is annoying. It means we can't add `.message()` to the first one without also finding a way to properly support it on the second one. (Which is what https://github.com/rust-lang/rust/issues/66745 is blocked on.)

It also means that, because the implementation is in `core`, the implementation cannot make use of the `String` type (which doesn't exist in `core`): 0692db1a90/library/core/src/panic/panic_info.rs (L171-L172)

This also means that we cannot easily add a useful method like `PanicInfo::payload_as_str() -> Option<&str>` that works for both `&'static str` and `String` payloads.

I don't see any good reasons for these to be the same type, other than historical reasons.

---

This PR is makes 1 and 2 separate types. To try to avoid breaking existing code and reduce churn, the first one is still named `core::panic::PanicInfo`, and `std::panic::PanicInfo` is a new (deprecated) alias to `PanicHookInfo`. The crater run showed this as a viable option, since people write `core::` when defining a `#[panic_handler]` (because they're in `no_std`) and `std::` when writing a panic hook (since then they're definitely using `std`). On top of that, many definitions of a panic hook don't specify a type at all: they are written as a closure with an inferred argument type.

(Based on some thoughts I was having here: https://github.com/rust-lang/rust/pull/115561#issuecomment-1725830032)

---

For the release notes:

> We have renamed `std::panic::PanicInfo` to `std::panic::PanicHookInfo`. The old name will continue to work as an alias, but will result in a deprecation warning starting in Rust 1.82.0.
>
> `core::panic::PanicInfo` will remain unchanged, however, as this is now a *different type*.
>
> The reason is that these types have different roles: `std::panic::PanicHookInfo` is the argument to the [panic hook](https://doc.rust-lang.org/stable/std/panic/fn.set_hook.html) in std context (where panics can have an arbitrary payload), while `core::panic::PanicInfo` is the argument to the [`#[panic_handler]`](https://doc.rust-lang.org/nomicon/panic-handler.html) in no_std context (where panics always carry a formatted *message*). Separating these types allows us to add more useful methods to these types, such as `std::panic::PanicHookInfo::payload_as_str()` and `core::panic::PanicInfo::message()`.
2024-06-11 21:27:45 +01:00
..
rustc Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=... 2024-05-02 19:48:29 +02:00
rustc_abi don't inhibit random field reordering on repr(packed(1)) 2024-05-21 19:22:04 +02:00
rustc_arena rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
rustc_ast Rollup merge of #124214 - carbotaniuman:parse_unsafe_attrs, r=michaelwoerister 2024-06-07 20:14:28 +02:00
rustc_ast_ir Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_ast_lowering Delegation: fix ICE on recursive delegation 2024-06-10 21:27:25 +03:00
rustc_ast_passes Parse unsafe attributes 2024-06-06 20:26:27 -05:00
rustc_ast_pretty Rollup merge of #124214 - carbotaniuman:parse_unsafe_attrs, r=michaelwoerister 2024-06-07 20:14:28 +02:00
rustc_attr Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
rustc_baked_icu_data Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_borrowck Uplift TypeRelation and Relate 2024-06-06 07:50:19 -04:00
rustc_builtin_macros Handle safe case 2024-06-06 20:54:51 -05:00
rustc_codegen_cranelift ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_codegen_gcc ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_codegen_llvm Rollup merge of #126159 - RalfJung:scalarint-size-mismatch, r=oli-obk 2024-06-10 21:12:25 +02:00
rustc_codegen_ssa ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_const_eval interpret: ensure we check bool/char for validity when they are used in a cast 2024-06-11 12:16:09 +02:00
rustc_data_structures Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_driver
rustc_driver_impl Rename std::panic::PanicInfo to PanicHookInfo. 2024-06-11 15:47:00 +02:00
rustc_error_codes Rollup merge of #124746 - OliverKillane:E0582-explain-assoc-types-improvement, r=pnkfelix 2024-06-05 18:21:08 +02:00
rustc_error_messages Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_errors Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote 2024-05-27 08:44:12 +00:00
rustc_expand Rollup merge of #125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril 2024-06-11 09:14:34 +01:00
rustc_feature offset_of: allow (unstably) taking the offset of slice tail fields 2024-06-08 18:17:55 +02:00
rustc_fluent_macro Rename SubdiagnosticMessage as SubdiagMessage. 2024-03-05 12:14:49 +11:00
rustc_fs_util Stabilize std::path::absolute 2024-04-24 14:35:02 +00:00
rustc_graphviz Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_hir Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errors 2024-06-07 09:08:59 +00:00
rustc_hir_analysis Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errors 2024-06-07 09:08:59 +00:00
rustc_hir_pretty Revert "Create const block DefIds in typeck instead of ast lowering" 2024-06-07 08:33:58 +00:00
rustc_hir_typeck Rollup merge of #126159 - RalfJung:scalarint-size-mismatch, r=oli-obk 2024-06-10 21:12:25 +02:00
rustc_incremental Run rustfmt on files that need it. 2024-05-24 15:17:21 +10:00
rustc_index Simplify static_assert_sizes. 2024-04-18 15:36:25 +10:00
rustc_index_macros Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_infer Add explanatory note to async block type mismatch error 2024-06-10 17:14:49 +05:30
rustc_interface Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk" 2024-06-06 10:06:28 +00:00
rustc_lexer Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
rustc_lint Rollup merge of #125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril 2024-06-11 09:14:34 +01:00
rustc_lint_defs Rollup merge of #125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril 2024-06-11 09:14:34 +01:00
rustc_llvm thinlto: only build summary file if needed 2024-05-23 14:58:30 -04:00
rustc_log remove tracing tree indent lines 2024-05-30 15:26:48 +02:00
rustc_macros Make the panic info more useful 2024-06-06 09:47:10 +00:00
rustc_metadata Only compute specializes query if specialization is enabled in the crate of the specialized impl 2024-06-07 15:58:50 -04:00
rustc_middle Rollup merge of #126265 - RalfJung:interpret-cast-validity, r=oli-obk 2024-06-11 14:16:47 +01:00
rustc_mir_build Rollup merge of #126159 - RalfJung:scalarint-size-mismatch, r=oli-obk 2024-06-10 21:12:25 +02:00
rustc_mir_dataflow Remove #[macro_use] extern crate tracing from rustc_mir_dataflow. 2024-05-23 18:02:40 +10:00
rustc_mir_transform Auto merge of #125910 - scottmcm:single-use-consts, r=saethlin 2024-06-11 02:03:12 +00:00
rustc_monomorphize Auto merge of #125928 - michaelwoerister:fix-cgu-hashstable, r=oli-obk 2024-06-07 04:02:59 +00:00
rustc_next_trait_solver Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_parse Rollup merge of #126052 - nnethercote:rustc_parse-more-cleanups, r=spastorino 2024-06-07 20:14:30 +02:00
rustc_parse_format Apply x clippy --fix and x fmt 2024-05-30 09:51:27 +08:00
rustc_passes reachable computation: clarify comments around consts 2024-06-11 09:08:28 +02:00
rustc_pattern_analysis ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_privacy Make body_owned_by return the body directly. 2024-05-29 10:04:08 +00:00
rustc_query_impl Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00
rustc_query_system Make the panic info more useful 2024-06-06 09:47:10 +00:00
rustc_resolve Rollup merge of #126234 - Bryanskiy:delegation-no-entry-ice, r=petrochenkov 2024-06-11 09:14:35 +01:00
rustc_sanitizers Misc fixes (pattern type lowering, cfi, pretty printing) 2024-06-05 22:25:42 +01:00
rustc_serialize Apply x clippy --fix and x fmt 2024-05-30 09:51:27 +08:00
rustc_session Improve naming and path operations in crate loader 2024-06-06 21:53:29 +02:00
rustc_smir Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk" 2024-06-06 10:06:28 +00:00
rustc_span rustc_span: Optimize syntax context updates in spans 2024-06-10 02:20:16 +03:00
rustc_symbol_mangling Add Ty to ConstKind::Value 2024-06-05 22:25:41 +01:00
rustc_target offset_of: allow (unstably) taking the offset of slice tail fields 2024-06-08 18:17:55 +02:00
rustc_trait_selection Rollup merge of #126258 - oli-obk:recursive_rpit, r=lcnr 2024-06-11 14:16:47 +01:00
rustc_traits Align Term methods with GenericArg methods 2024-06-03 20:36:27 -04:00
rustc_transmute ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_ty_utils ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
rustc_type_ir Uplift TypeRelation and Relate 2024-06-06 07:50:19 -04:00
rustc_type_ir_macros Uplift TraitPredicate 2024-05-11 18:20:00 -04:00
stable_mir Remove some unused crate dependencies. 2024-06-10 19:55:49 +10:00