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

add array::from_ref #77074

Merged
merged 3 commits into from
Sep 25, 2020
Merged

add array::from_ref #77074

merged 3 commits into from
Sep 25, 2020

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Sep 22, 2020

mirrors the methods in std::slice with the same name.

I guess this method previously didn't exist as there was close to no reason to create an array of size 1.
This will change due to const generics in the near future.

@rust-highfive
Copy link
Collaborator

r? @cramertj

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 22, 2020
@lcnr lcnr changed the title add array from_ref add array::from_ref Sep 22, 2020
@SimonSapin
Copy link
Contributor

This is new unstable safe API that would be very easy to re-implement, but require unsafe. It is rather niche, but follows the precedent of similar functions in std::slice. At least one person asked about exactly this: https://www.reddit.com/r/rust/comments/ixqzkf/are_there_any_gotchas_to_converting_t_into_t_1/

@rust-lang/libs Does anyone feel this should not be merged and eventually stabilized?

@sfackler
Copy link
Member

I'm not really opposed, but why will const generics change the usefulness of this method?

@lcnr
Copy link
Contributor Author

lcnr commented Sep 23, 2020

const generics makes working with arrays easier, which will result in more methods to both create and use arrays.

@emilazy
Copy link

emilazy commented Sep 23, 2020

Just wanted to point out that slice::from_{ref,mut} can both be reimplemented more simply in terms of array::from_{ref,mut} due to &[T; 1] automatically decaying to &[T], so this API can be added with no net increase of unsafe usage and arguably decreases the subtlety of the safety justifications.

@SimonSapin
Copy link
Contributor

Good point @emilazy.

@lcnr, could you make the change in this PR? r=me with that.

@lcnr
Copy link
Contributor Author

lcnr commented Sep 23, 2020

@bors r=SimonSapin rollup

@bors
Copy link
Contributor

bors commented Sep 23, 2020

📌 Commit 5b30161 has been approved by SimonSapin

@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 Sep 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 25, 2020
…as-schievink

Rollup of 15 pull requests

Successful merges:

 - rust-lang#75438 (Use adaptive SVG favicon for rustdoc like other rust sites)
 - rust-lang#76304 (Make delegation methods of `std::net::IpAddr` unstably const)
 - rust-lang#76724 (Allow a unique name to be assigned to dataflow graphviz output)
 - rust-lang#76978 (Documented From impls in std/sync/mpsc/mod.rs)
 - rust-lang#77044 (Liballoc bench vec use mem take not replace)
 - rust-lang#77050 (Typo fix: "satsify" -> "satisfy")
 - rust-lang#77074 (add array::from_ref)
 - rust-lang#77078 (Don't use an if guard to check equality with a constant)
 - rust-lang#77079 (Use `Self` in docs when possible)
 - rust-lang#77081 (Merge two almost identical match arms)
 - rust-lang#77121 (Updated html_root_url for compiler crates)
 - rust-lang#77136 (Suggest `const_mut_refs`, not `const_fn` for mutable references in `const fn`)
 - rust-lang#77160 (Suggest `const_fn_transmute`, not `const_fn`)
 - rust-lang#77164 (Remove workaround for deref issue that no longer exists.)
 - rust-lang#77165 (Followup to rust-lang#76673)

Failed merges:

r? `@ghost`
@bors bors merged commit 09b0bd6 into rust-lang:master Sep 25, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 25, 2020
@lcnr lcnr deleted the array-from-ref branch September 25, 2020 06:27
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.

8 participants