-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Stabilize mutable slice API #17494
Stabilize mutable slice API #17494
Conversation
2db3c9d
to
5307857
Compare
@@ -778,10 +801,11 @@ pub trait MutableSlice<'a, T> { | |||
/// // v.unsafe_set(10, "oops".to_string()); | |||
/// } | |||
/// ``` | |||
#[deprecated = "use as_mut_ptr"] |
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.
This may also want to mention the set part as well:
#[deprecated = "use `*foo.as_mut_ptr().offset(index) = val`"]
Looks good to me! r=me with some adjustments to the deprecation messages. |
5307857
to
9834d45
Compare
…ichton This commit is another in the series of vector slice API stabilization. The focus here is the *mutable* slice API. Largely, this API inherits the stability attributes [previously assigned](#16332) to the analogous methods on immutable slides. It also adds comments to a few `unstable` attributes that were previously missing them. In addition, the commit adds several `_mut` variants of APIs that were missing: - `init_mut` - `head_mut` - `tail_mut` - `splitn_mut` - `rsplitn_mut` Some of the unsafe APIs -- `unsafe_set`, `init_elem`, and `copy_memory` -- were deprecated in favor of working through `as_mut_ptr`, to simplify the API surface. Due to deprecations, this is a: [breaking-change]
This commit is another in the series of vector slice API stabilization. The focus here is the *mutable* slice API. Largely, this API inherits the stability attributes [previously assigned](rust-lang#16332) to the analogous methods on immutable slides. It also adds comments to a few `unstable` attributes that were previously missing them. In addition, the commit adds several `_mut` variants of APIs that were missing: - `init_mut` - `head_mut` - `tail_mut` - `splitn_mut` - `rsplitn_mut` Some of the unsafe APIs -- `unsafe_set`, `init_elem`, and `copy_memory` -- were deprecated in favor of working through `as_mut_ptr`, to simplify the API surface. Due to deprecations, this is a: [breaking-change]
9834d45
to
c59ef66
Compare
Why is this a regression for low-level Rust? |
This is a small change that affects two methods that are rarely used in the extant codebase. Nobody felt that it would be controversial and the implication that we were deliberately attempting to sidestep community consensus is incorrect. |
@thestinger Can you be more specific about how this is making unchecked indexing on slices harder? Discussion about this is happening now. |
@thestinger Do you have specific criticisms of the content of this pull request that you would like to discuss? |
I think the problem here is just a poor deprecation message. It should instead suggest: Replace |
/// } | ||
/// ``` | ||
/// Deprecated: use `*foo.as_mut_ptr().offset(index) = val` instead. | ||
#[deprecated = "use `*foo.as_mut_ptr().offset(index) = val`"] |
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.
Isn't *foo.unsafe_mut(index) = val
a better choice here?
Edit: ah, this was already stated elsewhere.
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.
Yes -- see comment in the github thread above. This was just a mistake in the message.
As with many other deprecations (of safe APIs), these were eliminated as conveniences that weren't worth the extra API surface area. There's also a general push toward funneling conveniences through central traits/data structures, like If you want to do extensive unsafe work with slices, the simplest avenue would be to use It's also worth noting that deprecations like these don't entail never providing such conveniences in the future, if they are ultimately deemed worthwhile. But there has been a lot of accumulation of ad hoc APIs, and the stabilization process is trying to move things toward a somewhat minimalistic, consistent, coherent, clean, and reasonably ergonomic state heading toward 1.0. (For bigger changes, like conventions, or removing the collection traits, or consolidating the numerics hierarchy, this involves RFCs.) As an aside, we should consider adding an |
I still think it's a regression and I disagree with this process but I'm not interested in arguing about it anymore. I don't care enough about the standard library to deal with that. |
…ichton This commit is another in the series of vector slice API stabilization. The focus here is the *mutable* slice API. Largely, this API inherits the stability attributes [previously assigned](#16332) to the analogous methods on immutable slides. It also adds comments to a few `unstable` attributes that were previously missing them. In addition, the commit adds several `_mut` variants of APIs that were missing: - `init_mut` - `head_mut` - `tail_mut` - `splitn_mut` - `rsplitn_mut` Some of the unsafe APIs -- `unsafe_set`, `init_elem`, and `copy_memory` -- were deprecated in favor of working through `as_mut_ptr`, to simplify the API surface. Due to deprecations, this is a: [breaking-change]
do not normalize `use foo::{self}` to `use foo` It changes behaviour and can cause collisions. E.g. for the following snippet ```rs mod foo { pub mod bar {} pub const bar: i32 = 8; } // transforming the below to `use foo::bar;` causes the error: // // the name `bar` is defined multiple times use foo::bar::{self}; const bar: u32 = 99; fn main() { let local_bar = bar; } ``` we still normalize ```rs use foo::bar; use foo::bar::{self}; ``` to `use foo::bar;` because this cannot cause collisions. See: rust-lang/rust-analyzer#17140 (comment)
This commit is another in the series of vector slice API stabilization. The focus here is the mutable slice API.
Largely, this API inherits the stability attributes previously assigned to the analogous methods on immutable slides. It also adds comments to a few
unstable
attributes that were previously missing them.In addition, the commit adds several
_mut
variants of APIs that were missing:init_mut
head_mut
tail_mut
splitn_mut
rsplitn_mut
Some of the unsafe APIs --
unsafe_set
,init_elem
, andcopy_memory
-- were deprecated in favor of working throughas_mut_ptr
, to simplify the API surface.Due to deprecations, this is a:
[breaking-change]