Skip to content

fix!(slice): mark NESlice::from_slice_unchecked as unsafe#38

Closed
ada4a wants to merge 0 commit into
fosskers:masterfrom
ada4a:unsafe-slice-from-slice-unchecked
Closed

fix!(slice): mark NESlice::from_slice_unchecked as unsafe#38
ada4a wants to merge 0 commit into
fosskers:masterfrom
ada4a:unsafe-slice-from-slice-unchecked

Conversation

@ada4a

@ada4a ada4a commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

BREAKING CHANGE: marking a public function as unsafe is breaking as per https://doc.rust-lang.org/cargo/reference/semver.html#fn-unsafe-safe

Comment thread src/slice.rs

#[must_use]
pub(crate) const fn from_slice_unchecked(slice: &'a [T]) -> Self {
pub(crate) const unsafe fn from_slice_unchecked(slice: &'a [T]) -> Self {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Given that this is pub(crate), is the unsafe necessary?

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.

Given that this is pub(crate)

Ah, that's good, it at least makes the change non-breaking.

is the unsafe necessary?

I mean not necessary, but very much wanted imo. This is a method you might realistically want to make pub in the future (it's a useful _unchecked constructor, a common thing in libraries), so I'd say it's better to mark it unsafe now than forget to do it later^^ Besides, it's only used in one place anyway, so the churn is not too high.

@ada4a
ada4a force-pushed the unsafe-slice-from-slice-unchecked branch from 5bc8b0a to dde30b2 Compare September 6, 2025 08:18
@fosskers fosskers closed this Sep 6, 2025
@fosskers
fosskers force-pushed the unsafe-slice-from-slice-unchecked branch from dde30b2 to bbdedf3 Compare September 6, 2025 08:48
@fosskers

fosskers commented Sep 6, 2025

Copy link
Copy Markdown
Owner

The Github display is weird but this is indeed merged. Thank you!

@ada4a
ada4a deleted the unsafe-slice-from-slice-unchecked branch September 6, 2025 08:49
@ada4a

ada4a commented Sep 6, 2025

Copy link
Copy Markdown
Contributor Author

Oh, thank god, the thought of the PR getting just silently closed made my heart drop for a second 😅

@fosskers

fosskers commented Sep 6, 2025

Copy link
Copy Markdown
Owner

It's happened to me before too. I was doing rebases and somehow Github lost the connection to the original commits.

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.

2 participants