-
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
Tracking Issue for const_ptr_read #80377
Comments
Should this be mentioned in #57563? |
Are
I guess it can be checked now |
Let's say they are on the wish list. ;) With #80290, making them |
Do we need to wait for #80418 (for allowing borrowing) to hit beta before Also |
Well... you could use
This is supposed to be changed in #79989. |
Just popping in to say that I just found out that this and One thing I'd ask though is if there are plans to make |
Yeah, those could all easily be made |
Perhaps something like this #83091 |
That looks great if it all works! Didn't even think about Here's an example snippet taking advantage of what's been implemented so far that I'll be including in the demo program for my crate with the next release, by the way: // It's also possible to write compile-time initialization functions that suit your specific needs
// with "complex" logic taking advantage of various methods you might typically expect to only
// be available at runtime.
const fn build<T: Copy, const N: usize>(x: [T; N]) -> StaticVec<T, N> {
// StaticVec implements `Drop`, and so can't *directly* be returned from a `const fn` yet (at
// least specifically if / when first instantiated as a fully-initialized "naked" function-local
// variable) even when `T` is `Copy`, making the (sound) use of MaybeUninit below necessary to
// facilitate regular access to the StaticVec we'll be creating.
let mut mu = MaybeUninit::new(StaticVec::new());
// Not actually unsafe here: `sv` is just a mutable reference to a normal empty StaticVec.
let sv = unsafe { mu.assume_init_mut() };
// `StaticVec::push` is a `const fn`. Note that loops in `const fn` are limited to `while`
// currently: if that changes, obviously use an iterator-based `for` loop instead.
let mut i = 0;
while i < N {
sv.push(x[i]);
i += 1;
}
// `StaticVec::pop` is also a `const fn`, so we can do this as well...
while sv.pop().is_some() {}
// And put everything back in like this...
sv.insert_from_slice(0, &x);
// Still not actually unsafe here: we soundly initialized everything that needed it as soon as we
// called `StaticVec::new()`.
unsafe { mu.assume_init() }
// The methods demonstrated above are by no means the only ones for StaticVec that could be used
// (and might be useful) in a context like this, so do go ahead and peruse the docs for this crate
// to find out more.
} Possibly worth noting that the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
T-lang approval on #89551 is the blocker that I see. After that, this is purely a libs issue |
I was presupposing that that is ok'd. Sounds good though. |
The item that Oli linked was approved and merged. Does this mean we're ready to move forward, or have other blockers come up in the past few months? |
Nope, a PR assigned to T-libs-api should be uncontroversial now |
@rfcbot merge |
Team member @m-ou-se 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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. |
…r=m-ou-se Stabilize const_ptr_read Stabilizes const_ptr_read, with tracking issue rust-lang#80377
…r=m-ou-se Stabilize const_ptr_read Stabilizes const_ptr_read, with tracking issue rust-lang#80377
Is there anything left here? #97320 should have closed this issue, no? |
Feature gate:
#![feature(const_ptr_read)]
This is a tracking issue for making the functions
ptr::read
andptr::read_unaligned
, and the same methods on*const T
and*mut T
,const fn
. This unlocks things like moving values out of arrays in const context.Public API
Steps / History
Related
Unresolved Questions
Inorder to make
intrinsics::copy
andintrinsics::copy_nonoverlapping
compile asconst fn
, some checks were removed.See comment for some more info
(#79684 did the
Comment out the debug assertions for now.
-thing).So the question is, how do we bring them back?
The text was updated successfully, but these errors were encountered: