Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allow calling *const methods on *mut values #82436
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
Allow calling *const methods on *mut values #82436
Changes from all commits
98fbc09
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, it's not so much that the pointer would be dereferenced, but more that adding an autoref would create a safe reference, which we don't want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried this:
the relevant, unoptimized MIR:
I thought the
*
dereferences, no? Similar code for the pointer version would also do&*
and dereference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not wrong, the
*
does dereference -- it's just that, when you combine it with a&
, the net effect is kind of an "identity transform", at least at runtime. That is,&*x
is sort of equivalent tox
(the "address of the data thatx
points to" is kind of just "x") -- but only sort of, because now we've made a shared reference, and that has implications (e.g., ifx: &mut T
, it implies that*x
is frozen while this shared reference is live).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the case even when result of
&
is a pointer, rather than reference? I'm guessing the final assembly for&*
(for pointer-to-pointer conversions) may disappear, but I thought in MIR it's still dereferencing, and has the implications of*
operation (whatever those implications are).Instead what we do here is more like
x as *const T
(wherex : *mut T
), which doesn't have unsafe dereferencing in MIR, and as a result would not have the same implications.