-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Constified array::from_fn
and ptr::drop_in_place
#109122
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
Conversation
fee1-dead
commented
Mar 14, 2023
•
edited
Loading
edited
- Add unit test
- Add tracking issue to feature
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
f65d736
to
b4cbcb3
Compare
This comment has been minimized.
This comment has been minimized.
b4cbcb3
to
f10bdbe
Compare
array::from_fn
array::from_fn
and ptr::drop_in_place
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
The Miri subtree was changed cc @rust-lang/miri |
f10bdbe
to
8300869
Compare
drop_in_place: unsafe { | ||
transmute::<unsafe fn(*mut T), unsafe fn(*mut ())>(drop_in_place::<T>) | ||
//~^ ERROR can't drop `T` in const contexts |
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.
Isn't this a bad error? We're not actually calling the function that needs const drop, and this breaks stable code:
pub const fn get_drop<T>() -> unsafe fn(*mut T) {
core::ptr::drop_in_place::<T>
}
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.
Similarly for array::from_fn
:
pub const fn array_from_fn() -> fn(fn(usize) -> ()) -> [(); 42] {
core::array::from_fn
}
... works on stable, but fails here for lack of ~const FnMut
on the function pointer.
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.
Does this go back to the previous error after #109557?
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.
The const-eval working group has been discussing the status of const traits in the compiler as well as the standard library. We came to a consensus that all uses of ~const
in the standard library should be temporary removed to allow for a clean impl of it to land in the compiler. See this zulip thread.
If the current plan is to remove |