-
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
Disable calling all const traits in stable const #132786
Disable calling all const traits in stable const #132786
Conversation
Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
How that? It's checking a quite different thing, so the diagnostics should be rather different. So IMO it makes a lot more sense for this to be a new |
I'm not certain what about the diagnostic would differ? Out of the matrix of the feature gate being enabled (yes/no) and the trait being const (yes/no), in all cases we're basically just saying that it's not possible to call a trait method in a const context. And most of what goes into rust/compiler/rustc_const_eval/src/check_consts/ops.rs Lines 139 to 280 in 59cec72
|
The entire idea of these "ops" is to have one
I can see no reason at all for why one would want to merge these into a single check. That's just confusing. |
args: fn_args, | ||
span: *fn_span, | ||
call_source, | ||
feature: tcx.is_const_trait(trait_did).then_some(sym::const_trait_impl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing, it conflates two entirely orthogonal checks:
- is this trait const-callable
- are we allowed to do const trait calls
Why is the first check even here, didn't revalidate_conditional_constness
already check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revalidate_conditional_constness
just checks that if the item is conditionally const then the trait bounds ~const
trait bounds hold. For example, if a free function item is not conditionally const, then it will have no ~const
trait bounds, so revalidate_conditional_constness
is not enforcing anything in that case.
// FIXME: apply more fine-grained per-trait const stability checks | ||
// (see <https://github.com/rust-lang/project-const-traits/issues/5>). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FIXME: apply more fine-grained per-trait const stability checks | |
// (see <https://github.com/rust-lang/project-const-traits/issues/5>). |
This is repeated below, no need to have it twice.
FWIW this will conflict with #132541 |
@@ -32,43 +35,28 @@ fn non_const_context() { | |||
#[unstable(feature = "none", issue = "none")] | |||
const fn const_context() { | |||
Unstable::func(); | |||
//[unstable]~^ ERROR cannot use `#[feature(unstable)]` | |||
//[stable]~^^ ERROR not yet stable as a const fn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something has gone very wrong here. This should complain about the missing feature gate -- const_trait_impl
can't be used here since the function does not have #[rustc_const_unstable]
. That's the entire point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're misinterpreting what I did to this file lol. I marked the whole thing as a known-bug, which requires that the test have no error annotation, because this whole test is basically useless if we have no staged apis for const traits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a test to ensure that we can't call trait functions on stable. Why shouldn't that be this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this test does a lot more than just ensure we can't call trait functions on stable. If we want a test to do that, then it can be like... 10 lines. It's got like... several revisions, an aux-build dep that is also broken due to these changes, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need an aux build to properly check the cross-crate part of this. And the revisions distinguish whether the trait callee is stable or not, which the old check was sensitive to when it could resolve the callee... I guess for now we don't need the revisions; once we have the ability to do a per-trait decision of "can this be const-called on stable", that will be relevant again.
In fact I think the |
…r=fee1-dead,compiler-errors require const_impl_trait gate for all conditional and trait const calls Alternative to rust-lang#132786. `@compiler-errors` this is basically what I meant with my proposals. I found it's easier to express this in code than English. ;) r? `@compiler-errors`
Rollup merge of rust-lang#132823 - RalfJung:conditional-const-calls, r=fee1-dead,compiler-errors require const_impl_trait gate for all conditional and trait const calls Alternative to rust-lang#132786. `@compiler-errors` this is basically what I meant with my proposals. I found it's easier to express this in code than English. ;) r? `@compiler-errors`
…ad,compiler-errors require const_impl_trait gate for all conditional and trait const calls Alternative to rust-lang/rust#132786. `@compiler-errors` this is basically what I meant with my proposals. I found it's easier to express this in code than English. ;) r? `@compiler-errors`
…r=fee1-dead,compiler-errors require const_impl_trait gate for all conditional and trait const calls Alternative to rust-lang#132786. `@compiler-errors` this is basically what I meant with my proposals. I found it's easier to express this in code than English. ;) r? `@compiler-errors`
r? @RalfJung
I hesitate to make this a separate
NonConstOp
since its error reporting would be basically totally identical to the existingFnCallNonConst
. Instead, if a trait is const, we set the status toStatus::Unstable
; otherwise it remainsStatus::Forbidden
. Am I missing something about this not being sufficient?