Description
We currently have two separate MIR passes that are responsible for const-checking. One lives in the check_consts
directory, and is responsible for the checks that run in all const contexts. The other is qualify_min_const_fn
, which performs additional checks within const fn
when #![feature(const_fn)]
is not enabled. The split was necessary to push const fn
feature over the finish line due to technical debt in the const-qualification code, but it resulted in some checks being duplicated between the two modules. Const-qualification has since been rewritten entirely, and it should be possible to unify the two to reduce the maintenance burden and improve diagnostics.
I half-heartedly attempted this in #68940, but eventually abandoned it due to the volume of error message changes and reticence from a former lang-team member. However, I think we should give this another try, since the split has caused some confusion about #![feature(const_fn)]
(see #76602) and there was a request from the libs-team to change how stability attributes affect whether the qualify_min_const_fn
runs (see #75794).
I did not fully understand when writing #68940 that qualify_min_const_fn
is responsible for ensuring that publicly exported, stable const fn
in staged_api
crates do not rely on unstable features as part of their implementation. check_consts
makes no such effort. So far, we've relied on the review process to enforce this, but I think one of the first steps will be to add this functionality to check_consts
, enabling it only within const fn
at first. After that, we can define new structured errors for each of the checks in qualify_min_const_fn
in the check_consts
framework and disable the former entirely. At first, all of these checks will be controlled by the #![feature(const_fn)]
feature gate, but I think we should assign a new gate to each (floating point arithmetic within const fn
, impl Trait
, etc.).
@oli-obk, would you be willing to review this work? Is there anything I missed?
TODO:
- Fully remove
qualify_min_const_fn
- ... (list needs completing)
cc @rust-lang/wg-const-eval