Skip to content
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

Constified array::from_fn and ptr::drop_in_place #109122

Closed

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Mar 14, 2023

  • Add unit test
  • Add tracking issue to feature

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2023

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 14, 2023
@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the const_array_from_fn branch 3 times, most recently from f65d736 to b4cbcb3 Compare March 17, 2023 16:14
@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead changed the title Constified array::from_fn Constified array::from_fn and ptr::drop_in_place Mar 19, 2023
@fee1-dead fee1-dead marked this pull request as ready for review March 20, 2023 14:43
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

The Miri subtree was changed

cc @rust-lang/miri

drop_in_place: unsafe {
transmute::<unsafe fn(*mut T), unsafe fn(*mut ())>(drop_in_place::<T>)
//~^ ERROR can't drop `T` in const contexts
Copy link
Member

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>
}

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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.

@cuviper
Copy link
Member

cuviper commented Mar 29, 2023

If the current plan is to remove ~const, you may want to just close this PR.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2023
@fee1-dead fee1-dead closed this Mar 30, 2023
@fee1-dead fee1-dead deleted the const_array_from_fn branch May 30, 2023 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants