-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
Coercing &mut to *const should not create a shared reference #56604
Copy link
Copy link
Open
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language team
Description
Activity
Metadata
Metadata
Assignees
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language team
View all comments
It has long been a rule in Rust that you must not mutate through a shared reference, or a raw pointer obtained from a shared reference.
Unfortunately, that rule currently forbids the following code:
The reason for this is that coercing
&mut Tto*const Timplicitly first creates a shared reference and then coerces that to*const T, meaningyin the example above is technically a raw pointer obtained from a shared reference.We should fix our coercion logic to no longer create this intermediate shared reference.
See #56161 for how we uncovered this problem.
Cc @eddyb @nikomatsakis