Skip to content

refactor: deprecate as_slice and as_mut_slice in favor of AsRef/AsMut (#711) - #763

Merged
alejandro-vaz merged 2 commits into
servo:v2from
Ankit-cs:fix/deprecate-as-slice
Oct 16, 2026
Merged

alejandro-vaz merged 2 commits into
servo:v2from
Ankit-cs:fix/deprecate-as-slice

Conversation

@Ankit-cs

Copy link
Copy Markdown
Contributor

Description

Addresses the deprecation of as_slice and as_mut_slice as discussed in the request for comments under the v2 deprecations tracking issue (#711).

In idiomatic Rust, standard trait implementations (AsRef<[T]> and AsMut<[T]>) are preferred over bespoke accessor methods. Following maintainer feedback (@alejandro-vaz):

  • Marked SmallVec::as_slice and SmallVec::as_mut_slice with #[deprecated(since = "2.0.0-beta.3", note = "use <SmallVec<Item, INLINE, Heap> as AsRef<[Item]>>::as_ref instead")].
  • Marked IntoIter::as_slice and IntoIter::as_mut_slice with #[deprecated(since = "2.0.0-beta.3", ...)] and implemented AsRef<[Item]> and AsMut<[Item]> for IntoIter.
  • Marked Drain::as_slice with #[deprecated(since = "2.0.0-beta.3", ...)] and implemented AsRef<[Item]> for Drain.
  • Updated all internal crate calls (src/references.rs, src/comparisons.rs, src/specialization.rs, src/iterators/extractif.rs) to use .as_ref() / .as_mut().
  • Added test coverage for AsRef on IntoIter and Drain, and added #[allow(deprecated)] to the legacy slice tests.
  • Code has been verified with cargo +nightly fmt -- --check.

Related to #711

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Hi @alejandro-vaz,

I have implemented the deprecations according to your feedback:

  1. Marked as_slice and as_mut_slice as deprecated across all relevant types (SmallVec, IntoIter, and Drain) with #[deprecated(since = "2.0.0-beta.3", note = ...)], pointing callers directly to <Type as AsRef<[Item]>>::as_ref and as_mut.
  2. Implemented AsRef and AsMut for IntoIter, and AsRef for Drain, providing the idiomatic trait replacements.
  3. Updated internal crate usages (src/references.rs, src/comparisons.rs, src/specialization.rs, src/iterators/extractif.rs) to use .as_ref() / .as_mut() so no internal deprecation warnings are emitted.
  4. Added test coverage for the new AsRef / AsMut implementations on IntoIter and Drain, and updated legacy tests with #[allow(deprecated)].
  5. Code is formatted and verified with cargo +nightly fmt -- --check.

Looking forward to your review!

@alejandro-vaz
alejandro-vaz self-requested a review October 16, 2026 09:06
@alejandro-vaz alejandro-vaz linked an issue Oct 16, 2026 that may be closed by this pull request
Comment thread src/iterators/intoiter.rs Outdated
Comment on lines 83 to 91
@@ -60,6 +90,10 @@ impl<Item, const INLINE: usize, Heap: Allocator> IntoIter<Item, INLINE, Heap> {
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change how this works to simply call as_ref

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sir

Comment thread src/iterators/intoiter.rs Outdated
note = "use `<IntoIter<Item, INLINE, Heap> as AsMut<[Item]>>::as_mut` instead"
)]
#[inline]
pub const fn as_mut_slice(&mut self) -> &mut [Item] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sir

Comment thread src/lib.rs Outdated
Comment on lines 978 to 982
pub const fn as_slice(&self) -> &[Item] {
let (length, on_heap) = self.length.parts();
// SAFETY: all the elements in `..length` are initialized
unsafe { core::slice::from_raw_parts(self.raw.as_ptr(on_heap), length) }
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, let this be a simple as_ref

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sir

Comment thread src/lib.rs Outdated
note = "use `<SmallVec<Item, INLINE, Heap> as AsMut<[Item]>>::as_mut` instead"
)]
#[inline]
pub const fn as_mut_slice(&mut self) -> &mut [Item] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

i will solve this faster in few minutes

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

what happened??

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

Yeah just give me 10 minutes I will work on the feedback

@Ankit-cs

Copy link
Copy Markdown
Contributor Author

I have updated the implementation according to your feedback @alejandro-vaz sir

@alejandro-vaz alejandro-vaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Ankit-cs

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Oct 16, 2026
Merged via the queue into servo:v2 with commit 9a30d99 Oct 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deprecate as_slice and as_mut_slice?

2 participants