-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
panic!() with formatting arguments sometimes accepted in const #139621
Copy link
Copy link
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-panicArea: Panicking machineryArea: Panicking machineryC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-const-evalWorking group: Const evaluationWorking group: Const evaluation
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-panicArea: Panicking machineryArea: Panicking machineryC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-const-evalWorking group: Const evaluationWorking group: Const evaluation
Type
Fields
Give feedbackNo fields configured for issues without a type.
This issue is a combination of three things:
fn panic_fmtis marked with#[rustc_do_not_const_check]and fully relies onformat_args!()with any arguments to not be accepted in const.Inlining/flattening of format_args!() accidentally exposed as stable through const #139136 -
I accidentally marked this function asEdit: This is actually caused by [generic_assert] Constify methods used by the formatting system #135139const, meaning that flattened format_args are accepted in const. This went unnoticed until two weeks ago.We have a special case for
panic!("{}", $expr)that we added at some point to makepanic!("{}", my_string)work in const, as a workaround forpanic!(my_string)which no longer works as of Rust 2021.The result is pretty terrible:
Only the four marked lines error. The others compile fine. 🙃
(The
Aconstants use the"{}"special case forpanic!()and end up invokingpanic_displayfor which we have a special const eval check that the argument is a&str. TheBconstants end up invokingpanic_fmt(which does not have any const eval checks) andformat_args!().)