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

Mark {array, slice}::{from_ref, from_mut} as const fn #90162

Merged
merged 3 commits into from
Oct 24, 2021

Conversation

WaffleLapkin
Copy link
Member

This PR marks the following APIs as const:

// core::array
pub const fn from_ref<T>(s: &T) -> &[T; 1];
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1];

// core::slice
pub const fn from_ref<T>(s: &T) -> &[T];
pub const fn from_mut<T>(s: &mut T) -> &mut [T];

Note that from_ref methods require const_raw_ptr_deref feature (which seems totally fine, since it's being stabilized, see #89551), from_mut methods require const_mut_refs (which seems fine too since this PR marks from_mut functions as const unstable).

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Oct 22, 2021

These changes all lgtm.

Please add a tracking issue and tests. Once raw ptr deref is stabilized we can immediately ask the libs team for stabilization of the immutable parts

@WaffleLapkin
Copy link
Member Author

@oli-obk done. Not sure if the tests make sense, but I've tried 😅

Also, maybe we want to separate features for &/&mut version? It seems like we'll stabilize the &mut versions a lot later.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 24, 2021

We can just stabilise the immutable functions and leave the gate for the mutable ones.

The tests are great

@bors r+

@bors
Copy link
Contributor

bors commented Oct 24, 2021

📌 Commit 5f390cf has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 24, 2021
…_ref_mut, r=oli-obk

Mark `{array, slice}::{from_ref, from_mut}` as const fn

This PR marks the following APIs as `const`:
```rust
// core::array
pub const fn from_ref<T>(s: &T) -> &[T; 1];
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1];

// core::slice
pub const fn from_ref<T>(s: &T) -> &[T];
pub const fn from_mut<T>(s: &mut T) -> &mut [T];
```

Note that `from_ref` methods require `const_raw_ptr_deref` feature (which seems totally fine, since it's being stabilized, see rust-lang#89551), `from_mut` methods require `const_mut_refs` (which seems fine too since this PR marks `from_mut` functions as const unstable).

r? `@oli-obk`
This was referenced Oct 24, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 24, 2021
…_ref_mut, r=oli-obk

Mark `{array, slice}::{from_ref, from_mut}` as const fn

This PR marks the following APIs as `const`:
```rust
// core::array
pub const fn from_ref<T>(s: &T) -> &[T; 1];
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1];

// core::slice
pub const fn from_ref<T>(s: &T) -> &[T];
pub const fn from_mut<T>(s: &mut T) -> &mut [T];
```

Note that `from_ref` methods require `const_raw_ptr_deref` feature (which seems totally fine, since it's being stabilized, see rust-lang#89551), `from_mut` methods require `const_mut_refs` (which seems fine too since this PR marks `from_mut` functions as const unstable).

r? ``@oli-obk``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 24, 2021
…_ref_mut, r=oli-obk

Mark `{array, slice}::{from_ref, from_mut}` as const fn

This PR marks the following APIs as `const`:
```rust
// core::array
pub const fn from_ref<T>(s: &T) -> &[T; 1];
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1];

// core::slice
pub const fn from_ref<T>(s: &T) -> &[T];
pub const fn from_mut<T>(s: &mut T) -> &mut [T];
```

Note that `from_ref` methods require `const_raw_ptr_deref` feature (which seems totally fine, since it's being stabilized, see rust-lang#89551), `from_mut` methods require `const_mut_refs` (which seems fine too since this PR marks `from_mut` functions as const unstable).

r? ```@oli-obk```
This was referenced Oct 24, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 24, 2021
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#89558 (Add rustc lint, warning when iterating over hashmaps)
 - rust-lang#90100 (Skip documentation for tier 2 targets on dist-x86_64-apple-darwin)
 - rust-lang#90155 (Fix alignment of method headings for scannability)
 - rust-lang#90162 (Mark `{array, slice}::{from_ref, from_mut}` as const fn)
 - rust-lang#90221 (Fix ICE when forgetting to `Box` a parameter to a `Self::func` call)
 - rust-lang#90234 (Temporarily turn overflow checks off for rustc-rayon-core)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c16ee19 into rust-lang:master Oct 24, 2021
@rustbot rustbot added this to the 1.58.0 milestone Oct 24, 2021
@WaffleLapkin WaffleLapkin deleted the const_array_slice_from_ref_mut branch May 23, 2022 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants