Skip to content
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

Closed
16 tasks done
m-ou-se opened this issue Dec 18, 2020 · 7 comments
Closed
16 tasks done
Assignees
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC Libs-Tracked Libs issues that are tracked on the team's project board. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Dec 18, 2020

This is a tracking issue for RFC 3007 "Plan to make core and std's panic identical": rust-lang/rfcs#3007

Steps

@m-ou-se m-ou-se added A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Dec 18, 2020
@m-ou-se m-ou-se self-assigned this Dec 18, 2020
@m-ou-se m-ou-se added this to the Rust 2021 milestone Dec 18, 2020
@m-ou-se m-ou-se added the Libs-Tracked Libs issues that are tracked on the team's project board. label Jan 6, 2021
@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Jan 11, 2021

I'm a little confused about what's supported with these changes.

Do the changes here allow you to panic in #![no_std] crates with a non-literal &'static str constant at compile-time?

I made the const_format crate to allow me to do string formatting at compile-time before the standard library can do it, and need to be able to panic with a non-literal &'static str to have my own static assertion macros.

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 12, 2021

@rodrimati1992 Panicking at compile is unstable, both before and after these changes. The current unstable implementation of const_panic will not work right away with the new 2021 version of panic!(), as panic!(SOME_CONST) is no longer accepted. The 2021 version of the panic!() macro will accept the exact same arguments as the println!() macro. That is, the first argument must be a format string as string literal.

Options for panicking at compile time with a non-literal string message in Rust 2021:

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 12, 2021

@rodrimati1992 By the way, note that core::panic!(SOME_CONST) in const_panic in the current editions was fixed and works now. Also, if your crate uses edition 2018 and has a macro that expands to panic!(..), it would always be the 2018 version of panic!(), even if the crate that uses your macro is a 2021 crate.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 1, 2021
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.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 2, 2021
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`
Manishearth pushed a commit to Manishearth/rust-clippy that referenced this issue Feb 3, 2021
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.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 3, 2021
…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`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 3, 2021
…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`
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 4, 2021
…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`
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 4, 2021
…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``
m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 4, 2021
…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```
@m-ou-se
Copy link
Member Author

m-ou-se commented Feb 6, 2021

Done!

🎉

@m-ou-se m-ou-se closed this as completed Feb 6, 2021
alatiera pushed a commit to alatiera/gnome-podcasts that referenced this issue Apr 27, 2021
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.
@djugei
Copy link
Contributor

djugei commented Jul 28, 2021

bit of a late comer, seeing that this rfc has already been accepted, but:
defining shared error messages now results in a warning, i.e.:

const ERR_ALPHA: &'static str = "alpha error";
panic!(ERR_ALPHA);

this can be easily resolved in user code by writing

panic!("{}", ERR_ALPHA};

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.

@m-ou-se
Copy link
Member Author

m-ou-se commented Jul 28, 2021

@djugei #78356 would help with that. Ideally, format_args!("{}", ERR_ALPHA) results in the same trivial fmt::Arguments as format_args!("alpha error") with a .as_str() returning Some("alpha error") to avoid any formatting.

Depending on how far away we think that is, we could consider stabilizing panic_str in the meantime.

@djugei
Copy link
Contributor

djugei commented Jul 28, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC Libs-Tracked Libs issues that are tracked on the team's project board. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants