about summary refs log tree commit diff
path: root/library/std/src/panicking.rs
AgeCommit message (Collapse)AuthorLines
2025-01-14std: lazily allocate the main thread handlejoboet-18/+21
Thereby, we also allow accessing thread::current before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from name will only be "main" after the runtime initialization code has run, but I think that is acceptable. This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).
2025-01-01Try to write the panic message with a single `write_all` callJohn Kåre Alsaker-1/+17
2024-12-23Use `#[derive(Default)]` instead of manually implementing itEsteban Küber-7/+2
2024-12-05Added struct `fmt::FormattingOptions`Elias Holzmann-1/+1
This allows to build custom `std::Formatter`s at runtime. Also added some related enums and two related methods on `std::Formatter`.
2024-11-28Share inline(never) generics across cratesMark Rousskov-0/+16
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
2024-09-26Rollup merge of #130846 - ChrisDenton:revert-break, r=NoratriebJubilee-17/+1
Revert Break into the debugger on panic (129019) This was talked about a bit at a recent libs meeting. While I think experimenting with this is worthwhile, I am nervous about this new behaviour reaching stable. We've already reverted on one tier 1 platform (Linux, https://github.com/rust-lang/rust/pull/130810) which means we have differing semantics on different tier 1 platforms. Also the fact it triggers even when `catch_unwind` is used to catch the panic means it can be very noisy in some projects. At the very least I think it could use some more discussion before being instantly stable. I think this could maybe be re-landed with an environment variable to control/override the behaviour. But that part would likely need a libs-api decision. cc ````@workingjubilee```` ````@kromych````
2024-09-25Use `&raw` in the standard libraryJosh Stone-1/+1
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-25Revert Break into the debugger on panic (129019)Chris Denton-17/+1
2024-09-08Auto merge of #129019 - kromych:master, r=workingjubileebors-1/+17
Break into the debugger (if attached) on panics (Windows, Linux, macOS, FreeBSD) The developer experience for panics is to provide the backtrace and exit the program. When running under debugger, that might be improved by breaking into the debugger once the code panics thus enabling the developer to examine the program state at the exact time when the code panicked. Let the developer catch the panic in the debugger if it is attached. If the debugger is not attached, nothing changes. Providing this feature inside the standard library facilitates better debugging experience. Validated under Windows, Linux, macOS 14.6, and FreeBSD 13.3..14.1.
2024-09-05Break into the debugger (if attached) on panics (Windows, macOS, Linux, FreeBSD)kromych-1/+17
The developer experience for panics is to provide the backtrace and exit the program. When running under debugger, that might be improved by breaking into the debugger once the code panics thus enabling the developer to examine the program state at the exact time when the code panicked. Let the developer catch the panic in the debugger if it is attached. If the debugger is not attached, nothing changes. Providing this feature inside the standard library facilitates better debugging experience. Validated under Windows, Linux, macOS 14.6, and FreeBSD 13.3..14.1.
2024-09-02Auto merge of #129063 - the8472:cold-opt-size, r=Amanieubors-2/+6
Apply size optimizations to panic machinery and some cold functions * std dependencies gimli and addr2line are now built with opt-level=s * various panic-related methods and `#[cold]` methods are now marked `#[optimize(size)]` Panics should be cold enough that it doesn't make sense to optimize them for speed. The only tradeoff here is if someone does a lot of backtrace captures (without panics) and printing then the opt-level change might impact their perf. Seems to be the first use of the optimize attribute. Tracking issue #54882
2024-08-24panicking: improve hint for Miri's RUST_BACKTRACE behaviorRalf Jung-1/+1
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-2/+6
2024-07-29Reformat `use` declarations.Nicholas Nethercote-12/+9
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-12fix interleaved panic outputjyn-2/+6
previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook would be interleaved with the backtrace. now, we hold the lock for the full duration of the hook, and the output is ordered.
2024-06-17Add PanicMessage type for PanicInfo::message().Mara Bos-5/+8
2024-06-16std: move `sys_common::backtrace` to `sys`joboet-3/+3
2024-06-11Formatting.Mara Bos-1/+3
2024-06-11Fix display of panic message in recursive panic.Mara Bos-9/+6
2024-06-11Rename std::panic::PanicInfo to PanicHookInfo.Mara Bos-10/+15
2024-06-11Reorder body of begin_panic for consistency.Mara Bos-17/+11
In the other functions, we put the struct and impl blocks first, such that the return expression can be at the end of the body as usual.
2024-06-11Impl Display for PanicPayload to simplify things.Mara Bos-9/+28
2024-06-11Use unnamed lifetimes for [..]Payload impl blocks.Mara Bos-7/+3
2024-06-11Move downcasting panic payload to str to a function.Mara Bos-7/+11
2024-06-11Remove std::panic::PanicInfo::internal_constructor+set_payload.Mara Bos-9/+4
We can just set the payload immediately in the constructor, and the constructor does not need to be public.
2024-06-11Split core's PanicInfo and std's PanicInfo.Mara Bos-21/+16
2024-04-18when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var ↵Ralf Jung-0/+7
isolation
2024-04-11Rollup merge of #122882 - Zoxc:panic-output-panic, r=AmanieuMatthias Krüger-4/+4
Avoid a panic in `set_output_capture` in the default panic handler This avoid a panic in the default panic handler by not using `set_output_capture` as `OUTPUT_CAPTURE.with` may panic once `OUTPUT_CAPTURE` is dropped. A new non-panicking `try_set_output_capture` variant of `set_output_capture` is added for use in the default panic handler.
2024-03-31std: move `thread::current` TLS variable out of `thread_info`joboet-2/+1
2024-03-24panic-in-panic-hook: formatting a message that's just a string is risk-freeRalf Jung-5/+9
2024-03-23Rollup merge of #122930 - RalfJung:panic-in-panic-fmt, r=AmanieuMatthias Krüger-1/+7
add panic location to 'panicked while processing panic' Fixes https://github.com/rust-lang/rust/issues/97181 r? `@Amanieu`
2024-03-23add panic location to 'panicked while processing panic'Ralf Jung-1/+7
2024-03-22Avoid a panic in `set_output_capture` in the default panic handlerJohn Kåre Alsaker-4/+4
2024-03-19SeqCst->Relaxed for FIRST_PANIC.Mara Bos-1/+1
Relaxed is enough to make sure this `swap` results in `true` only once.
2024-02-26rename 'try' intrinsic to 'catch_unwind'Ralf Jung-4/+4
2024-02-24library: use `addr_of!`Pavel Grigorenko-1/+1
2024-02-23Get rid of some `#[allow(static_mut_refs)]`Pavel Grigorenko-3/+0
2024-02-18Improve wording of static_mut_refObei Sideg-2/+3
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-08Step all bootstrap cfgs forwardMark Rousskov-1/+1
This also takes care of other bootstrap-related changes.
2024-01-07Update test for `E0796` and `static_mut_ref` lintObei Sideg-0/+2
2023-12-15Cfg remove lang items in doctestCameron Steffen-2/+2
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-1/+59
2023-09-21Rollup merge of #116008 - m-ou-se:boxmeup, r=oli-obkMatthias Krüger-21/+21
Rename BoxMeUp to PanicPayload. "BoxMeUp" is not very clear. Let's rename that to a description of what it actually represents: a panic payload. This PR also renames the structs that implement this trait to have more descriptive names. Part of https://github.com/rust-lang/rust/issues/116005 r? `@oli-obk`
2023-09-20Rename BoxMeUp to PanicPayload.Mara Bos-21/+21
2023-09-07Don't modify libstd to dump rustc ICEsMichael Goulet-29/+7
2023-08-27avoid triple-backtrace due to panic-during-cleanupRalf Jung-6/+30
2023-07-29Change default panic handler message format.Mara Bos-1/+1
2023-07-27When flushing delayed span bugs, write to the ICE dump file even if it ↵Esteban Küber-1/+1
doesn't exist Fix #113881.
2023-07-19On nightly, dump ICE backtraces to diskEsteban Küber-7/+31
Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected.
2023-05-27Rework handling of recursive panicsAmanieu d'Antras-53/+67