Skip to content

Avoid unsafe where safety depends on non-local values#1791

Open
dhardy wants to merge 1 commit into
masterfrom
push-yxwwqxvvrvnm
Open

Avoid unsafe where safety depends on non-local values#1791
dhardy wants to merge 1 commit into
masterfrom
push-yxwwqxvvrvnm

Conversation

@dhardy

@dhardy dhardy commented Jun 18, 2026

Copy link
Copy Markdown
Member
  • Added a CHANGELOG.md entry

Summary

Avoid usage of unsafe in contexts where non-local memory corruption (e.g. in RAM) could invalidate a safety contract.

Motivation

This could be seen as an alternative fix to #1790, though I'd prefer to merge both PRs.

This PR could have noticeable impacts (performance, code size, panic point). If this is a significant concern we could consider alternatives (not doing this, using a feature flag, adding an explicitly-unsafe variant such as slice::ChooseUnsafe).

@dhardy dhardy requested review from newpavlov and tarcieri June 18, 2026 08:18
@newpavlov

Copy link
Copy Markdown
Member

With any "non-local memory corruption" all bets are off, so I am not sure it's worth to guard against it.

Minimizing amount of unsafe code could be a sufficient motivation for this change, but personally I am fine with the current code as well.

@tarcieri tarcieri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the memory corruption angle, but avoiding unsafe seems good to me

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.

3 participants