Skip to content

Tracking issue for slice::from_ref and slice::from_ref_mut #45703

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
whitequark opened this issue Nov 1, 2017 · 19 comments
Closed

Tracking issue for slice::from_ref and slice::from_ref_mut #45703

whitequark opened this issue Nov 1, 2017 · 19 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@whitequark
Copy link
Member

whitequark commented Nov 1, 2017

Tracking issue for feature from_ref

// std::slice
pub fn from_ref<T>(s: &T) -> &[T];
pub fn from_ref_mut<T>(s: &mut T) -> &mut [T];
@kennytm kennytm added B-unstable Blocker: Implemented in the nightly compiler and unstable. 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 Nov 1, 2017
@SimonSapin
Copy link
Contributor

For archeology purpose: these were added to the standard library in 2014 419ac4a, then deprecated and moved to crates.io in 2015: #27774.

Now that we’ve decided to bring them back and are going through the process motions, can we start FCP to stabilize? CC @rust-lang/libs

@dtolnay
Copy link
Member

dtolnay commented Nov 15, 2017

Is there anything else in the standard library that uses "ref_mut" to refer to &mut T? In RFC 199 we went the opposite way.

Is it intended to be understood as (from_ref)_mut or from_(ref_mut)?

slice::from_mut wouldn't seem accurate to me but is there a different naming that works better with _ref and _mut suffixes?

@whitequark
Copy link
Member Author

Is it intended to be understood as (from_ref)mut or from(ref_mut)?

The latter. I think slice::from_mut is better here, too. I did not realize this in my initial PR.

@steveklabnik
Copy link
Member

I had left a brief comment in the original PR, but I didn't see anyone reply: my crate has two extra Option based versions as well, I don't know if we want to pull them in, or if my crate will still have some small use for those variants.

@SimonSapin
Copy link
Contributor

opt_slice(x) can be written as x.as_ref().map(ref_slice) which does not use unsafe (and is fairly standard Option manipulation code). So I think the need to include it is less pressing.

@whitequark
Copy link
Member Author

@steveklabnik I replied to you: #45306 (comment)

@steveklabnik
Copy link
Member

steveklabnik commented Nov 16, 2017 via email

@SimonSapin
Copy link
Contributor

Looks good to me to stabilize.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Mar 17, 2018

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

No concerns currently listed.

Once a majority of reviewers approve (and none object), 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 the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Mar 17, 2018
@dtolnay
Copy link
Member

dtolnay commented Mar 17, 2018

Given that we have Option::get_ref and Option::get_mut which is not called get_ref_mut, I think here it should be from_ref and from_mut rather than from_ref_mut.

@SimonSapin
Copy link
Contributor

Makes sense. Let’s say stabilize with that change.

@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 Apr 18, 2018
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 18, 2018

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

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 28, 2018

The final comment period is now complete.

@ghost ghost mentioned this issue May 21, 2018
kennytm added a commit to kennytm/rust that referenced this issue May 22, 2018
…nSapin

Stabilize feature from_ref

Function `from_ref_mut` is now renamed to `from_mut`, as discussed in rust-lang#45703.

Closes rust-lang#45703.

r? @SimonSapin
@ghost
Copy link

ghost commented Jul 27, 2018

Just one more last-minute question before stabilization: Why does slice::from_ref return a &[T]?

Wouldn't it be more useful to return a &[T; 1], which can be coerced into &[T]?
Are we going to add such a function later as array::from_ref?

@SimonSapin
Copy link
Contributor

That’s… a good point.

Though as you say a function that returns &[T; 1] would belong more in std::array than std::slice. If we add it there, should we also remove it from std::slice (because you can get the same with coercion) or should we keep both?

@SimonSapin
Copy link
Contributor

Yet another alternative might be From impls, instead of free functions.

@Kimundi
Copy link
Member

Kimundi commented Jul 27, 2018

I could image that implementing this with From impls might have negative inference or derfer-coercion effects, since passing a &Vec<T> for example might end in a &[Vec<T>] instead of a &[T]

@SimonSapin
Copy link
Contributor

SimonSapin commented Jul 27, 2018

Right, adding another x.into() for every x: &T would probably make inference impractical.

@alexcrichton
Copy link
Member

An excellent point @stjepang! It's a bit close to the release at this point, and I think @SimonSapin has a good idea of putting those in std::array as well

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants