Skip to content
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

Replace pointer castings (as) by their API equivalent #11818

Merged
merged 3 commits into from
Feb 11, 2024

Conversation

tguichaoua
Copy link
Contributor

Objective

Since rust 1.76, ptr::from_ref and ptr::from_mut are stable.

This PR replaces code that use as casting by one of ptr::from_ref, ptr::from_mut, cast_mut, cast_const, or cast methods, which are less error-prone.

Solution

  • Bump MSRV to 1.76.0
  • Enables the following clippy lints:
  • Fix the lints mentioned above

Copy link
Contributor

@doonv doonv left a 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 worth bumping up the MSRV.

@tguichaoua
Copy link
Contributor Author

I don't think this is worth bumping up the MSRV.

That's a good point. I'll close this until the MSRV is 1.76 or above.

@tguichaoua tguichaoua closed this Feb 11, 2024
@alice-i-cecile
Copy link
Member

Bevy's MSRV policy is "latest stable". This is as good a reason as any to bump it.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Pointers Relating to Bevy pointer abstractions labels Feb 11, 2024
@james7132 james7132 added the A-ECS Entities, components, systems, and events label Feb 11, 2024
@hymm hymm added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 11, 2024
@james7132 james7132 added this pull request to the merge queue Feb 11, 2024
Merged via the queue into bevyengine:main with commit c1a4e29 Feb 11, 2024
57 of 59 checks passed
@tguichaoua tguichaoua deleted the ptr_cast_lint branch February 12, 2024 09:19
github-merge-queue bot pushed a commit that referenced this pull request Apr 10, 2024
# Objective

-
[`clippy::ref_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#/ref_as_ptr)
prevents you from directly casting references to pointers, requiring you
to use `std::ptr::from_ref` instead. This prevents you from accidentally
converting an immutable reference into a mutable pointer (`&x as *mut
T`).
- Follow up to #11818, now that our [`rust-version` is
1.77](https://github.com/bevyengine/bevy/blob/11817f4ba4cca8e956c50f6d919e38f601ecc5cf/Cargo.toml#L14).

## Solution

- Enable lint and fix all warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Pointers Relating to Bevy pointer abstractions C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants