-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for RFC 3007: Making core and std's panic identical in Rust 2021 #80162
Comments
I'm a little confused about what's supported with these changes. Do the changes here allow you to panic in I made the |
@rodrimati1992 Panicking at compile is unstable, both before and after these changes. The current unstable implementation of Options for panicking at compile time with a non-literal string message in Rust 2021:
|
@rodrimati1992 By the way, note that |
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See rust-lang#80162 and rust-lang/rfcs#3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: rust-lang@c5273bd That change is blocked on figuring out what to do with rust-lang#80846 first.
Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? `@estebank`
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See rust-lang/rust#80162 and rust-lang/rfcs#3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: rust-lang/rust@c5273bd That change is blocked on figuring out what to do with rust-lang/rust#80846 first.
…1995 Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? `@estebank`
…1995 Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? `@estebank`
…1995 Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? `@estebank`
…1995 Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? ``@estebank``
…1995 Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of rust-lang#80162. r? ```@estebank```
Done! 🎉 |
Rust 2021 makes std::panic and core::panic identical. This caused a bunch of warnings to pop up. see: rust-lang/rust#81645 and: rust-lang/rust#80162 This updates the use of panic! and debug_assert to the new format.
bit of a late comer, seeing that this rfc has already been accepted, but:
this can be easily resolved in user code by writing
but no actual formatting is needed, i just want to push a string literal to stderr. this especially means that i would like to avoid pulling in the format machinery if at all possible, because it has a noticeable impact on binary size. |
@djugei #78356 would help with that. Ideally, Depending on how far away we think that is, we could consider stabilizing |
Ah, thanks i had not found panic_str (hidden under 2 layers of nightly), im ok with using nightly for now. Some const evaluation of format args could be cool though. |
This is a tracking issue for RFC 3007 "Plan to make core and std's panic identical": rust-lang/rfcs#3007
Steps
std::panic::panic_any
: Add std::panic::panic_any. #74622std::panic::panic_any
: Tracking issue Tracking Issue forpanic_any
#78500, PR Stabilize std::panic::panic_any. #81194panic_any
): Add lint forpanic!(123)
which is not accepted in Rust 2021. #81645panic!()
documentation about non-string-literals: Part of Add lint forpanic!(123)
which is not accepted in Rust 2021. #81645&str
instead of aString
instd
when usingcore::panic!
: Throw core::panic!("message") as &str instead of String. #78119todo!()
,assert_eq!()
, etc. to always usecore::panic!()
: Qualifypanic!
ascore::panic!
in non-built-incore
macros #78343assert!(expr, message)
to callcore
's panic mechanism directly: Part of Add lint for panic!("{}") #78088assert!(expr)
to callcore
's panic mechanism directly in edition 2021: Expand assert!(expr, args..) to include $crate for hygiene on 2021. #80855{std, core}::panic!(..)
always useformat_args!(..)
in edition 2021: Implement Rust 2021 panic #80851std::panic!(..)
an alias forcore::panic!(..)
in edition 2021:MakeIncluded in Implement Rust 2021 panic #80851.std::panic!()
identical tocore::panic!()
on Rust 2021 #80879This requires core::panic!() cannot be used everywhere std::panic!() can. #80846 to be fixed firstpanic_fmt
lint to mention edition 2021: Part of Add lint forpanic!(123)
which is not accepted in Rust 2021. #81645assert!(123, "{}")
expanding to the wrong edition ofpanic!()
: Fix bug with assert!() calling the wrong edition of panic!(). #81647panic_fmt
lint tonon_fmt_panic
(see Add lint for panic!("{}") #78088 (comment)): Part of Add lint forpanic!(123)
which is not accepted in Rust 2021. #81645, beta backport in [beta] Renamepanic_fmt
lint tonon_fmt_panic
#81729The text was updated successfully, but these errors were encountered: