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

static_mut_refs: Need edition migration guide documentation #123059

Open
ehuss opened this issue Mar 25, 2024 · 3 comments
Open

static_mut_refs: Need edition migration guide documentation #123059

ehuss opened this issue Mar 25, 2024 · 3 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-edition-2024 Area: The 2024 edition T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Mar 25, 2024

The change for static_mut_refs in the 2024 Edition needs to have documentation (here) for how a user can perform a manual migration.

This documentation should have a more complete explanation of why it is forbidden. Currently it just mentions use in multiple threads, but I don't think that is a complete description.

It also needs to explain to the user how to rewrite their code to make it work. My understanding is that someone can convert &STATIC to &*addr_of!(STATIC), which is equivalent, but still runs afoul of the exact same aliasing problems and undefined behavior, so I don't know if it makes sense to recommend that.

  • Why is &*addr_of!(…) allowed?
  • What situations are there where addr_of! is appropriate?
  • If addr_of! isn't the correct route, what should a user do to update their code?
    • Do they have to switch to interior mutability? How? What other options are there?

See also discussion at #114447 and
https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/static_mut_refs

@ehuss ehuss added T-lang Relevant to the language team, which will review and decide on the PR/issue. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-edition-2024 Area: The 2024 edition labels Mar 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 25, 2024
@traviscross traviscross removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 25, 2024
@traviscross
Copy link
Contributor

cc @obeis @scottmcm @RalfJung @est31

@eggyal
Copy link
Contributor

eggyal commented Apr 12, 2024

I opened rust-lang/edition-guide#299 as a step towards this.

@traviscross
Copy link
Contributor

We talked about this in the edition meeting today. The page that we merged to the edition guide in rust-lang/edition-guide#299 is a good start, but we still want to see a bit more.

We're hoping for the guide to cover an example showing why this is unsound, and then show how the simple cases could be rewritten using raw pointers, and maybe show a more complicated case showing where using a custom type instead would make sense.

Looking in the recent crater results (#125384), it seems there are a lot of calls to libc here. Perhaps we could show an example of that and how these could be addressed with raw pointers.

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 A-edition-2024 Area: The 2024 edition T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants