Rename StaticArray#to_slice
to #to_unsafe_slice
#14613
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
StaticArray#to_slice
is unsafe because it returns an unprotected pointer to data on the stack. This pointer can easily be overriden which invalidates the slice (see #14610).Renaming to
#to_unsafe_slice
highlights the unsafe nature of using the method, and distinguishes it from other#to_slice
implementations that are inherently more safe because they return heap pointers.StaticArray#to_slice
becomes deprecated.The first commit replaces
StaticArray
where it is used in the spec suite as an example for the implementation of#to_slice
. Using aString
literal with the same payload seems like a good idea. It even simplifies those specs.There are quite a lot of calls to
StaticArray#to_slice
in the standard library and spec suite. All of them get replaced. It's interesting to note that they're all explicit calls toStaticArray#to_slice
and do not involve dynamic dispatch to some other#to_slice
method. This makes rewriting easy and confirms that havingStaticArray
break from the unified#to_slice
interface does not cause any practical problems. Calls toStaticArray#to_slice
are typically unrelated to calls to other#to_slice
methods.Replaces part of #11031 and resolves part of #9606
Depends on #14615