Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entry: disallow explicit/interior mutability for read-only storage classes. #1009

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

eddyb
Copy link
Contributor

@eddyb eddyb commented Mar 19, 2023

Fixes #1008 by reinstating a mutability check, but with two key differences:

  • immutable references are usable with all storage classes, not just read-only ones
    • not a difference from just before this PR, but rather pre-#567 the check was stricter (e.g. requiring &mut for StorageBuffer)
    • (SPIR-V does not observe a distinction, anyway, it looks like a &mut that was never written to)
  • interior mutability is taken into account, not just explicit &mut T
    • the &mut T-vs-&T distinction is still around, but only for syntax/phrasing in diagnostics
    • (interior mutability involves &T where T: !Freeze, with Freeze being a rustc-internal trait for "contains no UnsafeCells, at any inline nesting, ignoring behind pointer indirection", i.e. T: !Freeze implies T contains UnsafeCell, which would allow writing to those parts of &T

Diagnostics example:
(the messages were surprisingly tricky to phrase - interior mutability means "expected &T"/"found &mut T" isn't the right distinction, as when T: !Freeze, they are both theoretically mutable)
image

@eddyb eddyb force-pushed the entry-check-mut branch from 4f2f198 to 8a1e041 Compare April 4, 2023 00:29
@eddyb eddyb marked this pull request as ready for review April 4, 2023 00:29
@eddyb eddyb enabled auto-merge (rebase) April 4, 2023 00:29
@eddyb eddyb merged commit 5fffc75 into EmbarkStudios:main Apr 4, 2023
@eddyb eddyb deleted the entry-check-mut branch April 4, 2023 00:56
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.

Reference entry arguments are not checked for mutability.
2 participants