-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Bring back slice::ref_slice as slice::from_ref. #45306
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I didn't do anything to bring back |
Maybe it's just me, but, looking at the name alone, it's hard to tell what |
I've added the waiting-on-crater label for now so that if we decide to go ahead with this we do a crater run -- I think it's worth doing that just in case others have implemented ref_slice (which could play into the naming bikeshed, too, so probably best after fcp). |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, 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. |
These are free functions, so I don't think there's as much of a concern with collisions as you'd have with new methods. |
Since the naming is uncertain and insta-stable is proposed anyway, could they just be impl<'a, T> From<&'a T> for &'a [T] { ... }
impl<'a, T> From<&'a mut T> for &'a mut [T] { ... } |
Personally, I think A |
I'd personally prefer to initially add these as unstable (but perhaps push on stabilization soon after landing), and I agree with @whitequark that a name like |
Also strongly agree with |
These functions were deprecated and removed in 1.5, but such simple functionality shouldn't require using unsafe code, and it isn't cluttering libstd too much.
Already renamed it, just not reflected in the PR. |
ping @BurntSushi waiting for your ticky box here! |
My crate that provides these functions also provides an I'm not sure if they're worth bringing in too, figured I'd bring it up. |
I'm going to go ahead and check @BurntSushi's checkbox as this is just unstable anyway. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors: r+ |
📌 Commit 8431811 has been approved by |
src/libcore/slice/mod.rs
Outdated
@@ -2450,6 +2450,22 @@ pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] { | |||
mem::transmute(Repr { data: p, len: len }) | |||
} | |||
|
|||
/// Converts a reference to T into a slice of length 1 (without copying). | |||
#[stable(feature = "from_ref", since = "1.22.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we intend to insta-stable these?
@bors r- If the final FCP checkbox expects "this is just unstable anyway" the current code certainly isn't unstable. |
Oops sorry, thanks for catching that @kennytm! |
Can you please guide me on the stability markers here? |
|
Tracking issue filed as #45703, no unstable book entry since it seems far too trivial. |
Stability annotation updated. |
Thanks! It should be ready to go after fixing the build failure.
|
Updated. |
Library stuff doesn't need an unstable book entry as the api docs are docs;
the unstable book pages get generated automatically.
…On Wed, Nov 1, 2017 at 6:22 PM, whitequark ***@***.***> wrote:
Updated.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45306 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABsikXJgsaCpcQfEEdjztR6V-nnUeB7ks5syO8KgaJpZM4P5v2u>
.
|
@bors r=alexcrichton |
📌 Commit 1cc88be has been approved by |
Bring back slice::ref_slice as slice::from_ref. These functions were deprecated and removed in 1.5, but such simple functionality shouldn't require using unsafe code, and it isn't cluttering libstd too much. The original removal was quite contentious (see #27774), since then we've had precedent for including such nuggets of functionality (see rust-lang/rfcs#1789), and @nikomatsakis has provided a lot of use cases in rust-lang/rfcs#1789 (comment). Hence this PR. I'm not too sure what to do with stability, feel free to correct me. It seems pointless to go through stabilization for these functions though. cc @aturon
☀️ Test successful - status-appveyor, status-travis |
These functions were deprecated and removed in 1.5, but such simple
functionality shouldn't require using unsafe code, and it isn't
cluttering libstd too much.
The original removal was quite contentious (see #27774), since then
we've had precedent for including such nuggets of functionality (see rust-lang/rfcs#1789),
and @nikomatsakis has provided a lot of use cases in rust-lang/rfcs#1789 (comment).
Hence this PR.
I'm not too sure what to do with stability, feel free to correct me.
It seems pointless to go through stabilization for these functions though.
cc @aturon