Skip to content

Deprecate into_vec and into_boxed_slice in favor of Into - #685

Merged
alejandro-vaz merged 12 commits into
servo:v2from
Ashutosh-Panda2004:fix/683-deprecate-into-methods
Sep 30, 2026
Merged

alejandro-vaz merged 12 commits into
servo:v2from
Ashutosh-Panda2004:fix/683-deprecate-into-methods

Conversation

@Ashutosh-Panda2004

Copy link
Copy Markdown
Contributor

Moves the conversion logic into the existing From<SmallVec<T, N>> impls for Vec<T> and Box<[T]>, and turns into_vec / into_boxed_slice into deprecated compatibility wrappers delegating to Into.

Closes #683.

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
Replaced the implementation of `into_vec` and `into_boxed_slice` to use `Into::into` instead of custom logic.

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
…methods-1

Refactor deprecated methods to use Into::into
…methods-2

Update assertions in into_vec test for SmallVec
@Ashutosh-Panda2004

Copy link
Copy Markdown
Contributor Author

@alejandro-vaz, this is ready for review whenever you have a moment.

@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.

okay for it to work properly I realized we have to change the implementations to use SmallVec<T, N, A> I think

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

honestly, everywhere in the codebase we should be using <T, N, A> or at least <T, N, Global> to have API guarantees explicit

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>

@Ashutosh-Panda2004 Ashutosh-Panda2004 left a comment

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.

Addressed the From implementations are now generic over A: Allocator.

@Ashutosh-Panda2004

Ashutosh-Panda2004 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

honestly, everywhere in the codebase we should be using <T, N, A> or at least <T, N, Global> to have API guarantees explicit

Agreed , I'll do the codebase-wide pass in #686 so this PR stays focused.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

you have to run cargo fmt --all in nightly so that CI is happy, that's the failing check

@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.

rustfmt needed

Remove extra newline before the deprecated function.

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>

@Ashutosh-Panda2004 Ashutosh-Panda2004 left a comment

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.

Formatting fixed, removed the double blank line in src/lib.rs and shortened the long SAFETY comment in src/conversions.rs to fit the 100-char limit. Should be rustfmt-clean now, waiting on CI.

Clarify safety comments regarding vector ownership transfer.

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>

@Ashutosh-Panda2004 Ashutosh-Panda2004 left a comment

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.

Fix rustfmt formatting issues

@Ashutosh-Panda2004

Ashutosh-Panda2004 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@alejandro-vaz Formatting is fixed now, the two deprecated attributes are on single lines and the conversions.rs bits are cleaned up. CI is green on the latest push, could you take another look when you get a chance?

Comment thread src/lib.rs Outdated
since = "2.0.0-alpha.13",
note = "use `TryInto::<[T; N]>::try_into` instead"
)]

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.

but this can be removed

Comment thread src/lib.rs Outdated

#[inline]
#[deprecated(since = "2.0.0", note = "use `Into::<Vec<T>>::into` instead")]

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.

why did you add it?? rustfmt doesn't require it

Remove deprecated methods and update notes for alternatives.

Signed-off-by: Ashutosh Panda <133190480+Ashutosh-Panda2004@users.noreply.github.com>
@Ashutosh-Panda2004

Copy link
Copy Markdown
Contributor Author

@alejandro-vaz Removed the blank lines between the deprecated attributes and the three functions. Should be good now.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

thanks brother

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Sep 30, 2026
Merged via the queue into servo:v2 with commit e388f60 Sep 30, 2026
8 checks passed
Comment thread src/conversions.rs
// - the allocation is not larger than `isize::MAX`
unsafe {
let (ptr, cap) = this.raw.heap;
Vec::from_raw_parts(ptr.as_ptr(), length, cap)

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.

Isn't it unsound to create a Vec<T, Global> from memory allocated by A?

From the from_raw_parts docs:

If T is not a zero-sized type and the capacity is nonzero, ptr must have been allocated using the global allocator, such as via the alloc::alloc function.

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.

yes it is

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 all the into_* methods

3 participants