-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Add more array references to raw pointer casts. #31418
Conversation
Previously, you could only cast from `&[T; n]` to `*const T`.
I also changed "`&{T; n]` or `&mut [T; n]``" to "`&.[T; n]`".
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -345,7 +346,7 @@ impl<'tcx> CastCheck<'tcx> { | |||
{ | |||
// array-ptr-cast. | |||
|
|||
if m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutImmutable { | |||
if !(m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutMutable) { |
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 don't think this is correct - this would only allow casts from &[T; n]
to *mut T
, whereas you want casts from immutable to const and mut to mut.
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.
It should do the opposite of that due to the !
at the front and only accept casts that are not
&[T; n]
to *mut T
. The other 3 casts work with a version of rustc that contains this change.
This will need some tests too. |
@nrc Should I add a file to |
@Jexell yes, or you could find tests that already test similar casts and add tests to those files. BTW, the CI tests are failing because you used a tab rather than spaces |
Closing due to inactivity, but feel free to resubmit with the tests fixed! |
Adds
&mut [T; n]
to*mut T
and&mut [T; n]
to*const T
casts. Closes #24151.