-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Disallow *references* to static mut [Edition Idea] #114447
Copy link
Copy link
Closed
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionA-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionA-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
StatusShow more project fields
Done
Now that we have
ptr::addr_of_mut!, the 2024 edition would be a great time to do @RalfJung's idea from #53639 (comment):Disallow
&MY_STATIC_MUTand&mut MY_STATIC_MUTentirely.ptr::addr_of_mut!(MY_STATIC_MUT)could even be safe -- unlike taking a reference which isunsafeand often insta-UB -- and helps encourage avoiding races in the accesses, which is more practical than trying to avoid the UB from concurrent existence of references.(Maybe people will end up just doing
&mut *ptr::addr_of_mut!(MY_STATIC_MUT)without thinking through all the safety requirements -- in particular, making sure that the reference stops being used before a second reference is created -- but we can't force them to drink.)