-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement trait const stability #133999
base: master
Are you sure you want to change the base?
Implement trait const stability #133999
Conversation
HIR ty lowering was modified cc @fmease Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
also cc @rust-lang/project-const-traits |
I'm guessing with the current const trait impl we'd have the same issues with making impls unstable as we'd have for nonconst impls? |
Yeah... we should enforce that if a trait is marked const-stable then all its impls (in staged_api crates) are const-stable, like we do for regular stability. |
The current code doesn't deal with impls' const stability yet, that work can be incremental on top of this (i will personally probably have more cycles to spend until one week or more, so i'd prefer us landing a reviewed version of this first) |
That's fine as long as this is recorded somewhere as a blocker. |
☔ The latest upstream changes (presumably #134108) made this pull request unmergeable. Please resolve the merge conflicts. |
fa450eb
to
ee3f3df
Compare
This comment has been minimized.
This comment has been minimized.
ee3f3df
to
9c55da1
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
9c55da1
to
080ae25
Compare
This comment has been minimized.
This comment has been minimized.
080ae25
to
d60bc65
Compare
Rollup merge of rust-lang#135139 - c410-f3r:8-years-rfc, r=jhpratt [generic_assert] Constify methods used by the formatting system cc rust-lang#44838 Starts the "constification" of all the elements required to allow the execution of the formatting system in constant environments. ```rust const _: () = { panic!("{:?}", 1i32); }; ``` Further stuff is blocked by rust-lang#133999.
r=me with diagnostic and readability nits resolved |
d60bc65
to
05ca6ae
Compare
@bors r=oli-obk |
@bors r- |
This comment has been minimized.
This comment has been minimized.
let unstable_feature_allowed = span.allows_unstable(feature) | ||
|| implied_feature.is_some_and(|f| span.allows_unstable(f)); |
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.
For function calls we only honor allows_unstable
if the callee is safe-to-expose on stable. So here I guess the question would be, when is a trait safe to expose on stable? Right now I think the answer is "only when it is stable", we don't support something like #[const_stable_indirect]
on traits. That means we should not check span.allows_unstable
here.
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.
removed
span: Span, | ||
parent_def: Option<LocalDefId>, | ||
) { | ||
let Some(ConstStability { |
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.
let Some(ConstStability { | |
// This should work pretty much exactly like the function stability logic in | |
// `compiler/rustc_const_eval/src/check_consts/check.rs`. | |
// FIXME: Find some way to not duplicate that logic. | |
let Some(ConstStability { |
}); | ||
self.disabled_nightly_features(&mut diag, None, [(String::new(), feature)]); | ||
diag.emit(); | ||
} else if let Some(parent) = parent_def { |
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 don't understand this -- what is the "parent" here?
The equivalent code for this entire if-else-if in check.rs is
if !feature_enabled || !callee_safe_to_expose_on_stable {
self.check_op(ops::FnCallUnstable {
def_id: callee,
feature,
feature_enabled,
safe_to_expose_on_stable: callee_safe_to_expose_on_stable,
});
}
Here callee_safe_to_expose_on_stable
is always false
so we should always behave as-if check_op
was called.
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.
Either a const fn
that contains the ~const Tr
bound or the callee of a const method.
we should always behave as-if
check_op
was called.
Yes, this is why this code is derived from check_op_spanned
.
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.
Either a const fn that contains the ~const Tr bound or the callee of a const method.
Sorry I don't follow. If you had said "always the const fn that contains the thing we are stability-checking", i.e., the caller, that would make more sense to me. Is this a typo?
The existing const checks have nothing like this, as far as I can see. I have no idea what it means here that we are skipping the check if there is no parent. We should always know the function we are in and that defines whether we are in recursive-const-stability mode.
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.
Yes, this is why this code is derived from check_op_spanned.
Can you make the structure parallel, i.e. also have a function like that here with essentially the same inputs (without the NonConstOp
trait of course). Or ideally share that code rather than duplicate it... maybe we need a compiler/rustc_middle/src/middle/const_stability.rs
file for those functions. (stability.rs
is already huge.)
// other unstably-const features with `const_stable_indirect` | ||
stab.is_const_stable() || stab.const_stable_indirect | ||
} | ||
}; |
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.
What is this logic? This has to be a duplicate of something in check.rs
, right?
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 duplicating enforce_recursive_const_stability
.
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.
That logic is fairly critical and definitely should not be duplicated.
☔ The latest upstream changes (presumably #135286) made this pull request unmergeable. Please resolve the merge conflicts. |
05ca6ae
to
2d0c0e7
Compare
The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Yeah something went wrong with the rebase, this now deletes the dev guide.^^
|
☔ The latest upstream changes (presumably #135327) made this pull request unmergeable. Please resolve the merge conflicts. |
.. By enforcing it in three locations:
~const
orconst
const
Reopens #90080
Reopens #88955
Closes rust-lang/project-const-traits#5
Closes rust-lang/project-const-traits#16
cc @RalfJung