-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove qualify_min_const_fn
and #![feature(const_fn)]
#76618
Comments
I am confused, haven't we relied on |
For checks that exist in both |
Ah, so basically when |
So it looks like stable library functions can't use const FOO: Option<&mut i32> = None; is allowed on stable, but const fn bar() {
let x: Option<&mut i32> = None;
} is not, playground link. The corresponding check in
This seems mostly true, an example of where it's not is the type-level check, which checks for some banned types, and then lets all other types pass through, which means if a new const-incompatible type/operation was added, this check would need to be updated. |
Note that we have a few cases where things are allowed in constants but not |
yes definively! |
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
…d-api, r=oli-obk Use const-checking to forbid use of unstable features in const-stable functions First step towards rust-lang#76618. Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass. Also contains some unrelated refactoring, which is split into separate commits. r? @oli-obk
I tried to remove To fully resolve the first half of this issue, one of a few things needs to happen:
|
That would be my preferred solution for now, TBH -- but I am not a Clippy maintainer so obviously I am picking what would be easiest for rustc itself. I added resolving this as a checkbox to the OP. I am not sure if there are still parts of |
Cc @rust-lang/clippy for the clippy problem |
This comment has been minimized.
This comment has been minimized.
Clippy is the only client of The new const analysis that rustc is using does not have a "speculative mode" -- if it detects a const-error, it raises a hard error. That is how such analysis usually work in rustc AFAIK, min_const_fn was the odd one out. Clippy exploited this special status to be able to detect if a function could be const without raising hard errors when it is not. A new mechanism to achieve this will have to be introduced, ideally with minimal maintenance overhead on the rustc side. |
… r=RalfJung,oli-obk Add `#![feature(const_fn_floating_point_arithmetic)]` cc rust-lang#76618 This is a template for splitting up `const_fn` into granular feature gates. I think this will make it easier, both for us and for users, to track stabilization of each individual feature. We don't *have* to do this, however. We could also keep stabilizing things out from under `const_fn`. cc @rust-lang/wg-const-eval r? @oli-obk
… r=RalfJung,oli-obk Add `#![feature(const_fn_floating_point_arithmetic)]` cc rust-lang#76618 This is a template for splitting up `const_fn` into granular feature gates. I think this will make it easier, both for us and for users, to track stabilization of each individual feature. We don't *have* to do this, however. We could also keep stabilizing things out from under `const_fn`. cc @rust-lang/wg-const-eval r? @oli-obk
Clippy frequently has custom algorithms to detect whether to lint on something. It's totally fine not to reuse the compiler logic and keep the compiler logic simple and just have a bunch of false negatives in the lint. False negatives in a non-bug-detecting lint are absolutely no problem. So yes, I think we should just move the function to clippy and call it a day. We can then look into improving things on the clippy side without requiring any maintaining on the compiler side |
@oli-obk sounds like a good plan to me. |
I'll do that now |
@oli-obk @ecstatic-morse what is left to be done here? The checklist in the original issue only has one unchecked item, which says "list needs completing"... ;) |
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 isqualify_min_const_fn
, which performs additional checks withinconst fn
when#![feature(const_fn)]
is not enabled. The split was necessary to pushconst 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 thequalify_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, stableconst fn
instaged_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 tocheck_consts
, enabling it only withinconst fn
at first. After that, we can define new structured errors for each of the checks inqualify_min_const_fn
in thecheck_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 withinconst fn
,impl Trait
, etc.).@oli-obk, would you be willing to review this work? Is there anything I missed?
TODO:
qualify_min_const_fn
cc @rust-lang/wg-const-eval
The text was updated successfully, but these errors were encountered: