-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rename ~const Drop
to ~const Destruct
#94901
Conversation
wait, even if I just add this as a lang item now it wouldn't work because the logic for handling them would still need to be backported... I guess we could go with a compatible approach by ignoring @rustbot author |
You could implement |
yeah that works, which means we could land this now and I will implement the logic later |
If the purpose of this trait to mark the types that can be trivially dropped for the purposes of CTFE, shouldn't it be "auto" trait or some other special "const auto" trait, or may be simultaneously marker trait (never manually implementable, but not sure about it)? |
Yeah if we can implement it for all |
Minor bikeshedding: In a lot of cases, trait names use the imperative form of a verb ( |
Is there ever going to be a case where types don't implement |
Don't think so. The rationale behind the use of the word destructible is as another word for drop, where any type can be dropped/destructed in runtime, but not in compile time. |
My main concern is that it seems like this is just a renamed version of |
|
Destructible
trait for replacing ~const Drop
bounds in the future~const Drop
to ~const Destruct
This comment has been minimized.
This comment has been minimized.
if obligation.param_env.constness() == Constness::NotConst { | ||
return Ok(ImplSourceConstDropData { nested: vec![] }); | ||
) -> Result<ImplSourceConstDestructData<PredicateObligation<'tcx>>, SelectionError<'tcx>> { | ||
// `~const Destruct` in a non-const environment is always trivially true, since our type is `Drop` |
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.
Well... for now it's true because all types implement Destruct. Unless we get those weird kind of types that may never get destructed, outside of constness all types implement Destruct
@@ -1054,9 +1062,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |||
let cause = obligation.derived_cause(BuiltinDerivedObligation); | |||
|
|||
// If we have a custom `impl const Drop`, then | |||
// first check it like a regular impl candidate | |||
// first check it like a regular impl candidate. | |||
// This is copied from confirm_impl_candidate but remaps the predicate to `~const Drop` beforehand. |
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 does this code make work that wouldn't otherwise?
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.
So.. basically the nested obligation causes must be correctly ~const Destruct
, but we want the obligation that is matched to actually be ~const Drop
such that match_impl
wouldn't fail.
@bors r+ |
📌 Commit fe5b813 has been approved by |
☀️ Test successful - checks-actions |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9280445): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
This change was driven by [rust-lang/rust#94901][1]. It's actually more than just renaming - it fixes the irregular meaning of `~const Drop` (“the type can be destructed in a const context”, instead of the regular meaning of “`<T as Drop>::drop is `const fn`”), which the compiler was unable to reconcile in `Drop` bounds and thus necessitated the work- around explained in `[ref:drop_const_bounds]`. This is no longer an issue because `~const Destruct` has a regular meaning. [1]: rust-lang/rust#94901
This change was driven by [rust-lang/rust#94901][1]. It's actually more than just renaming - it fixes the irregular meaning of `~const Drop` (“the type can be destructed in a const context”, instead of the regular meaning of “`<T as Drop>::drop is `const fn`”), which the compiler was unable to reconcile in `Drop` bounds and thus necessitated for us to implement the work-around explained in `[ref:drop_const_bounds]`. This is no longer an issue because `~const Destruct` has a regular meaning. [1]: rust-lang/rust#94901
Migration notes: We have renamed
~const Drop
to~const std::marker::Destruct
. When you bump the pinned nightly version, please make sure that all usages of~const Drop
are changed to~const Destruct
!r? @oli-obk
Completely switching to
~const Destructible
would be rather complicated, so it seems best to add it for now and wait for it to be backported to beta in the next release.The rationale is to prevent complications such as #92149 and #94803 by introducing an entirely new trait. And
~const Destructible
reads a bit better than~const Drop
. Name Bikesheddable.