-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Consider deprecation of UB-happy static mut #53639
Copy link
Copy link
Closed as not planned
Labels
A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.This change is large or controversial enough that it should have an RFC accepted before doing it.
Metadata
Metadata
Assignees
Labels
A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-langRelevant to the language teamRelevant to the language teamdisposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.This change is large or controversial enough that it should have an RFC accepted before doing it.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Rejected/Not lang
static mutis almost impossible to use correctly, see rust-lang-nursery/lazy-static.rs#117 for an example in the widely-usedlazy-static.You must be able to show that every borrow of the
static mutis not reentrant (as opposed to regular interior mutability, which only requires reentrance-freedom when accessing data), which is almost entirely impossible in real-world scenarios.We have a chance at removing it from Rust2018 and force people to use a proper synchronization abstraction (e.g.
lazy_static!+Mutex), or in lieu of one,thread_local!/scoped_thread_local!.If they were using
static mutwith custom synchronization logic, they should do this:And then use
CustomSynchronizingAbstractionwith regularstatics, safely.This matches the "soundness boundary" of Rust APIs, whereas
static mutis more like C.cc @RalfJung @rust-lang/compiler @rust-lang/lang
2023-08 Note from triage, many years later: there's now https://doc.rust-lang.org/1.71.0/std/cell/struct.SyncUnsafeCell.html in the library, added by #95438, which can be used instead of
static mut. Butstatic mutis not even soft-deprecated currently.