Skip to content

Tracking Issue for RFC 3007: Making core and std's panic identical in Rust 2021 #80162

@m-ou-se

Description

@m-ou-se
Member

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

Steps

Activity

added
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
T-langRelevant to the language team
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Dec 18, 2020
self-assigned this
on Dec 18, 2020
added this to the Rust 2021 milestone on Dec 18, 2020
added
Libs-TrackedLibs issues that are tracked on the team's project board.
on Jan 6, 2021
rodrimati1992

rodrimati1992 commented on Jan 11, 2021

@rodrimati1992
Contributor

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

m-ou-se commented on Jan 12, 2021

@m-ou-se
MemberAuthor

@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:

15 remaining items

added 3 commits that reference this issue on Feb 4, 2021
aa197c3
f17cd6c
87b269a
m-ou-se

m-ou-se commented on Feb 6, 2021

@m-ou-se
MemberAuthor

Done!

🎉

added a commit that references this issue on Apr 27, 2021
djugei

djugei commented on Jul 28, 2021

@djugei
Contributor

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

m-ou-se commented on Jul 28, 2021

@m-ou-se
MemberAuthor

@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

djugei commented on Jul 28, 2021

@djugei
Contributor

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

Metadata

Metadata

Assignees

Labels

A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.T-langRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @m-ou-se@rodrimati1992@djugei

      Issue actions

        Tracking Issue for RFC 3007: Making core and std's panic identical in Rust 2021 · Issue #80162 · rust-lang/rust