Skip to content

Permit const panics in stable const contexts in stdlib#90687

Merged
bors merged 1 commit into
rust-lang:masterfrom
jhpratt:const_panic
Nov 17, 2021
Merged

Permit const panics in stable const contexts in stdlib#90687
bors merged 1 commit into
rust-lang:masterfrom
jhpratt:const_panic

Conversation

@jhpratt

@jhpratt jhpratt commented Nov 8, 2021

Copy link
Copy Markdown
Member

Without this change, it is not possible to use panic! and similar (including assert!) in stable const contexts inside of stdlib. See #89542 for a real-world case that currently fails for this reason. This does not affect any user code.

For example, this snippet currently fails to compile:

#[stable(feature = "foo", since = "1.0.0")]
#[rustc_const_stable(feature = "foo", since = "1.0.0")]
const fn foo() {
    assert!(false);
    assert!(false, "foo");
}

With the addition of #[rustc_const_unstable] to core::panicking::panic, the error no longer occurs. This snippet has been added verbatim in this PR as a UI test.

To avoid needing to add #![feature(core_panic)] to libcore, the two instances of direct calls to core::panicking::panic have been switched to use the panic! macro.

I am requesting prioritization because this is holding up other stabilizations such as #89542 (which is otherwise ready to merge and succeeds with this change)

@rustbot rustbot added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-fn C-bug Category: This is a bug. I-prioritize Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical} T-lang Relevant to the language team labels Nov 8, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 8, 2021
@est31 est31 mentioned this pull request Nov 8, 2021
5 tasks
@nbdd0121

nbdd0121 commented Nov 8, 2021

Copy link
Copy Markdown
Member

I don't think this should or need to be backported.

@jhpratt jhpratt force-pushed the const_panic branch 2 times, most recently from a56c6e8 to c49d741 Compare November 8, 2021 22:05
@jhpratt

jhpratt commented Nov 8, 2021

Copy link
Copy Markdown
Member Author

As this only affects stdlib and I've confirmed that #89542 compiles after being rebased on this PR, I agree it doesn't need to be backported. I still think this would be nice to prioritize given that it's blocking other things, but feel free to remove the I-prioritize label if wanted. The actual change is all of one line — the rest is just testing and small idiomatic changes in Duration to avoid needing a feature flag. So this should be a trivial review for anyone.

@apiraino apiraino removed the I-prioritize Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical} label Nov 9, 2021
@oli-obk

oli-obk commented Nov 17, 2021

Copy link
Copy Markdown
Contributor

r? @oli-obk

this is solely an internal change and it is definitely intended that we can use panic! from within libcore in stable const contexts

@bors r+

I don't think we should prioritize/backport things just to unblock stabilizing others. There is no rush to stabilize things, but I get how annoying it is when things are blocked.

@bors

bors commented Nov 17, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 6d2f8af has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2021
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#89610 (warn on must_use use on async fn's)
 - rust-lang#90667 (Improve diagnostics when a static lifetime is expected)
 - rust-lang#90687 (Permit const panics in stable const contexts in stdlib)
 - rust-lang#90772 (Add Vec::retain_mut)
 - rust-lang#90861 (Print escaped string if char literal has multiple characters, but only one printable character)
 - rust-lang#90884 (Fix span for non-satisfied trivial trait bounds)
 - rust-lang#90900 (Remove workaround for the forward progress handling in LLVM)
 - rust-lang#90901 (Improve ManuallyDrop suggestion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@jhpratt

jhpratt commented Nov 17, 2021

Copy link
Copy Markdown
Member Author

Just to clarify w.r.t. backporting: don't. Other things don't need to wait for this to hit beta as I originally suspected.

@bors bors merged commit ec84633 into rust-lang:master Nov 17, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 17, 2021
@jhpratt jhpratt deleted the const_panic branch November 17, 2021 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants