Closed
Description
rust-lang/const-eval#19 gives many arguments for why we should not promote const fn
calls. However, we currently do promote const fn
calls in const fn
, even though that has all the same problems. This fails to compile, but really we shouldn't make this a hard error:
#![allow(unconditional_panic, const_err)]
const fn foo() { [()][42] }
pub const fn do_something(b: bool) -> i32 {
if b {
let _x = &foo();
}
13
}
This does not just apply to const fn
calls; all promotion inside const fn
should be treated like inside fn
.
Cc @rust-lang/wg-const-eval
Activity
RalfJung commentedon Aug 16, 2020
#75502 is a crater experiment to stop doing this (at least for the case of
&call()
insideconst fn
).oli-obk commentedon Aug 17, 2020
One data point I want to bring up is rust-lang/rfcs#1229 (comment)
From that reading I'm getting the vibes that @nikomatsakis would be mostly fine with hard erroring on promotion or even const propagation of failing code in const fn. But since we did not address this during the stabilization of
const fn
... this train probably left?RalfJung commentedon Aug 17, 2020
The reason promotion in
fn
is subtle is that it needs to be codegen'd, and we cannot say if the code we are generating will ever evaluate or not. There might be things likewhich would never cause div-by-zero at runtime, but will have a failing CTFE query during codegen if
T::ASSOC
is 0.And all of this applies equally to
const fn
! They are stillfn
, subject to codegen, and thus have all the same problems. I don't see how them being a "const context" is at all related. Even in a "const context" I would not expect code that properly guards against div-by-zero to cause a compile-time error.const fn
#75502Rollup merge of rust-lang#75502 - ecstatic-morse:implicit-promotion-i…
Rollup merge of rust-lang#76411 - RalfJung:promote-in-const-fn, r=ecs…
Rollup merge of rust-lang#76411 - RalfJung:promote-in-const-fn, r=ecs…
Rollup merge of rust-lang#76411 - RalfJung:promote-in-const-fn, r=ecs…
Rollup merge of rust-lang#76411 - RalfJung:promote-in-const-fn, r=ecs…
Auto merge of rust-lang#76411 - RalfJung:promote-in-const-fn, r=ecsta…