Skip to content

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

Closed

Description

@m-ou-se

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

Steps

Activity

  1. added
    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
    T-langRelevant to the language team
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Dec 18, 2020
  2. self-assigned this
    on Dec 18, 2020
  3. added this to the Rust 2021 milestone on Dec 18, 2020
  4. added
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jan 6, 2021
  5. 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.

  6. 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:

  7. m-ou-se commented on Jan 12, 2021

    @m-ou-se
    MemberAuthor

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

  8. 4 remaining items

  9. added a commit that references this issue on Feb 1, 2021
  10. added a commit that references this issue on Feb 2, 2021
  11. added a commit that references this issue on Feb 3, 2021
  12. added a commit that references this issue on Feb 3, 2021
  13. added 3 commits that reference this issue on Feb 4, 2021
  14. m-ou-se commented on Feb 6, 2021

    @m-ou-se
    MemberAuthor

    Done!

    🎉

  15. added a commit that references this issue on Apr 27, 2021
  16. 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.

  17. 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.

  18. 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 RFCI-libs-radarLibs issues that are tracked on the team's radar.T-langRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE]

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions