-
Notifications
You must be signed in to change notification settings - Fork 13.4k
panic: Use local functions in panic!
whenever possible
#128068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
goldsteinn
wants to merge
12
commits into
rust-lang:master
from
goldsteinn:goldsteinn/panic-func-wrappers
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca16524
panic: Use local functions in `panic!` whenever possible
goldsteinn cc107fc
Comments + Fixup to std::panic_2015
goldsteinn 11caff4
Remove internal feature from std::panic
goldsteinn f2f77f2
make {} special case non-const in std::panic_2015
goldsteinn a59b918
fix core::unreachable_2021!
goldsteinn af6260f
Allow const_format_args in core::unreachable_2021!
goldsteinn 6a4f226
Fixup tests
goldsteinn 6cbc3eb
Drop TODO
goldsteinn 7219ce0
Fixup clippy test
goldsteinn 555a033
Move explicit panic/unreachable into panicking.rs
goldsteinn 12e23c4
Fix clippy tests
goldsteinn b8d3c62
Fixup tests
goldsteinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,19 +212,49 @@ impl fmt::Display for PanicHookInfo<'_> { | |
|
||
#[doc(hidden)] | ||
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")] | ||
#[allow_internal_unstable(libstd_sys_internals, const_format_args, panic_internals, rt)] | ||
#[allow_internal_unstable( | ||
libstd_sys_internals, | ||
const_format_args, | ||
panic_internals, | ||
rt, | ||
const_dispatch, | ||
const_eval_select, | ||
rustc_attrs | ||
)] | ||
#[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_2015_macro")] | ||
#[rustc_macro_transparency = "semitransparent"] | ||
pub macro panic_2015 { | ||
// For all cases where it is possible, wrap the actual call to the | ||
// internal panic implementation function with a local no-inline | ||
// cold function. This moves the codegen for setting up the | ||
// arguments to the panic implementation function to the | ||
// presumably cold panic path. | ||
// It would be nice to handle literals here specially with a | ||
// wrapper function, but unfortunately it results in unclear error | ||
// messages when using panic(<non-str>). | ||
() => ({ | ||
$crate::rt::begin_panic("explicit panic") | ||
#[cold] | ||
#[track_caller] | ||
#[inline(never)] | ||
const fn panic_cold_explicit() -> ! { | ||
$crate::rt::begin_panic("explicit panic"); | ||
} | ||
Comment on lines
+236
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You get the point... |
||
panic_cold_explicit(); | ||
}), | ||
($msg:expr $(,)?) => ({ | ||
$crate::rt::begin_panic($msg); | ||
}), | ||
// Special-case the single-argument case for const_panic. | ||
("{}", $arg:expr $(,)?) => ({ | ||
$crate::rt::panic_display(&$arg); | ||
#[cold] | ||
#[track_caller] | ||
#[inline(never)] | ||
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval | ||
#[rustc_do_not_const_check] // hooked by const-eval | ||
const fn panic_cold_display<T: $crate::fmt::Display>(arg: &T) -> ! { | ||
$crate::rt::panic_display(arg) | ||
} | ||
panic_cold_display(&$arg); | ||
}), | ||
($fmt:expr, $($arg:tt)+) => ({ | ||
// Semicolon to prevent temporaries inside the formatting machinery from | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.