Skip to content

&{mut} T may (briefly) write garbage - #161452

Open
nia-e wants to merge 2 commits into
rust-lang:mainfrom
nia-e:reference-validity
Open

&{mut} T may (briefly) write garbage#161452
nia-e wants to merge 2 commits into
rust-lang:mainfrom
nia-e:reference-validity

Conversation

@nia-e

@nia-e nia-e commented Aug 21, 2026

Copy link
Copy Markdown
Member

Per opsem consensus on the topic of reference validity, expand the docs on references to account for this. Though still not explicitly settled, this also includes language allowing changing a wrapping enum discriminant (e.g. in the case of an Option<bool> handing out a &mut to the inner bool).

r? RalfJung

@nia-e nia-e added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team labels Aug 21, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 21, 2026
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@nia-e nia-e changed the title &{mut} T may point to garbage &{mut} T may (briefly) point to garbage Aug 21, 2026
@nia-e nia-e changed the title &{mut} T may (briefly) point to garbage &{mut} T may (briefly) write garbage Aug 21, 2026
@nia-e nia-e added the S-waiting-on-t-opsem Status: Awaiting decision from T-opsem label Aug 21, 2026
@RalfJung

Copy link
Copy Markdown
Member

Thanks! However if we land this as-is it is in direct contradiction to https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html which IMO would not be a good state to be in. I think we have to update the reference first.

When I suggested FCP'ing the discriminant meant I meant an issue in https://github.com/rust-lang/unsafe-code-guidelines/ where we can gather consensus on decisions without having to also figure out how to stably document them. :)

Cc @rust-lang/opsem

Comment thread library/core/src/primitive_docs.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-t-opsem Status: Awaiting decision from T-opsem T-libs Relevant to the library team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants