Skip to content

Tracking Issue for const_replace #83164

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
2 of 3 tasks
Tracked by #16
usbalbin opened this issue Mar 15, 2021 · 8 comments · Fixed by #130954
Closed
2 of 3 tasks
Tracked by #16

Tracking Issue for const_replace #83164

usbalbin opened this issue Mar 15, 2021 · 8 comments · Fixed by #130954
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@usbalbin
Copy link
Contributor

usbalbin commented Mar 15, 2021

Feature gate: #![feature(const_replace)]

This is a tracking issue for making the functions mem::replace and ptr::replace const fn.

Public API

mod mem {
    pub const fn replace<T>(dest: &mut T, src: T) -> T;
}

mod ptr {
    pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T;
}

Steps / History

Unresolved Questions

  • None yet.
@usbalbin usbalbin added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 15, 2021
@RalfJung

This comment was marked as resolved.

@Zizico2
Copy link

Zizico2 commented Jan 1, 2023

status on this? is any help needed?

@RalfJung
Copy link
Member

RalfJung commented Sep 9, 2024

@rust-lang/libs-api I think this is ready to be stabilized, given that const_mut_refs is in FCP. :)

This is about const-stabilizing two already-stable functions:

mod mem {
    pub const fn replace<T>(dest: &mut T, src: T) -> T;
}

mod ptr {
    pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T;
}

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 9, 2024
@dtolnay
Copy link
Member

dtolnay commented Sep 9, 2024

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Sep 9, 2024

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 9, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 9, 2024
@RalfJung
Copy link
Member

RalfJung commented Sep 21, 2024

@Amanieu @BurntSushi @joshtriplett @m-ou-se would be nice to get this (and some of the other &mut/*mut APIs) into the next release train so that const_mut_refs is not quite so bare-bones when it lands. :D Also, this particular feature blocks replace/take on Option so there's a bit of a dependency chain here.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 21, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Sep 21, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 1, 2024
@rfcbot
Copy link
Collaborator

rfcbot commented Oct 1, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Oct 1, 2024
tgross35 added a commit to tgross35/rust that referenced this issue Oct 12, 2024
…-fn, r=RalfJung

Stabilize const `ptr::write*` and `mem::replace`

Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we may now also stabilize the ability to write to places during const evaluation inside our library API. So, we now propose the `const fn` version of `ptr::write` and its variants. This allows us to also stabilize `mem::replace` and `ptr::replace`.
- const `mem::replace`: rust-lang#83164 (comment)
- const `ptr::write{,_bytes,_unaligned}`: rust-lang#86302 (comment)

Their implementation requires an additional internal stabilization of `const_intrinsic_forget`, which is required for `*::write*` and thus `*::replace`. Thus we const-stabilize the internal intrinsics `forget`, `write_bytes`, and `write_via_move`.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 12, 2024
Rollup merge of rust-lang#130954 - workingjubilee:stabilize-const-mut-fn, r=RalfJung

Stabilize const `ptr::write*` and `mem::replace`

Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we may now also stabilize the ability to write to places during const evaluation inside our library API. So, we now propose the `const fn` version of `ptr::write` and its variants. This allows us to also stabilize `mem::replace` and `ptr::replace`.
- const `mem::replace`: rust-lang#83164 (comment)
- const `ptr::write{,_bytes,_unaligned}`: rust-lang#86302 (comment)

Their implementation requires an additional internal stabilization of `const_intrinsic_forget`, which is required for `*::write*` and thus `*::replace`. Thus we const-stabilize the internal intrinsics `forget`, `write_bytes`, and `write_via_move`.
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 17, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 5, 2025
…r=jhpratt

Fix missing const for inherent pointer `replace` methods

`ptr::replace` (the free fn) is already const stable. However, there are inherent convenience methods on `*mut T` and `NonNull<T>`, allowing you to write eg. `unsafe { foo.replace(bar) }` where `foo` is `*mut T` or `NonNull<T>`.

It seems const was never added to the inherent method (likely oversight), so this PR adds it.
I don't believe this needs another[^1] FCP as the inherent methods are already stable and `ptr::replace` is already const stable, so this adds no new API.

Original tracking issue: rust-lang#83164
`ptr::replace` constified in rust-lang#83091
`ptr::replace` const stabilized in rust-lang#130954

[^1]: `const_replace` FCP completed: rust-lang#83164 (comment)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 5, 2025
Rollup merge of rust-lang#136877 - Sky9x:const-inherent-ptr-replace, r=jhpratt

Fix missing const for inherent pointer `replace` methods

`ptr::replace` (the free fn) is already const stable. However, there are inherent convenience methods on `*mut T` and `NonNull<T>`, allowing you to write eg. `unsafe { foo.replace(bar) }` where `foo` is `*mut T` or `NonNull<T>`.

It seems const was never added to the inherent method (likely oversight), so this PR adds it.
I don't believe this needs another[^1] FCP as the inherent methods are already stable and `ptr::replace` is already const stable, so this adds no new API.

Original tracking issue: rust-lang#83164
`ptr::replace` constified in rust-lang#83091
`ptr::replace` const stabilized in rust-lang#130954

[^1]: `const_replace` FCP completed: rust-lang#83164 (comment)
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 10, 2025
…r=jhpratt

Fix missing const for inherent pointer `replace` methods

`ptr::replace` (the free fn) is already const stable. However, there are inherent convenience methods on `*mut T` and `NonNull<T>`, allowing you to write eg. `unsafe { foo.replace(bar) }` where `foo` is `*mut T` or `NonNull<T>`.

It seems const was never added to the inherent method (likely oversight), so this PR adds it.
I don't believe this needs another[^1] FCP as the inherent methods are already stable and `ptr::replace` is already const stable, so this adds no new API.

Original tracking issue: rust-lang#83164
`ptr::replace` constified in rust-lang#83091
`ptr::replace` const stabilized in rust-lang#130954

[^1]: `const_replace` FCP completed: rust-lang#83164 (comment)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants