Skip to content

Commit 5c3ae32

Browse files
authored
Enable clippy::ref_as_ptr (#12918)
# 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.
1 parent d59b1e7 commit 5c3ae32

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ semicolon_if_nothing_returned = "warn"
4141

4242
ptr_as_ptr = "warn"
4343
ptr_cast_constness = "warn"
44-
#TODO(rust 1.77): enable `ref_as_ptr`
45-
# ref_as_ptr = "warn"
44+
ref_as_ptr = "warn"
4645

4746
[workspace.lints.rust]
4847
unsafe_op_in_unsafe_fn = "warn"

crates/bevy_mikktspace/src/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
unsafe_code
4646
)]
4747

48-
use std::ptr::null_mut;
48+
use std::ptr::{self, null_mut};
4949

5050
use glam::Vec3;
5151

@@ -830,15 +830,15 @@ unsafe fn Build4RuleGroups(
830830
let mut neigh_indexR: i32 = 0;
831831
let vert_index: i32 = *piTriListIn.offset((f * 3i32 + i) as isize);
832832
let ref mut fresh2 = (*pTriInfos.offset(f as isize)).AssignedGroup[i as usize];
833-
*fresh2 = &mut *pGroups.offset(iNrActiveGroups as isize) as *mut SGroup;
833+
*fresh2 = ptr::from_mut(&mut *pGroups.offset(iNrActiveGroups as isize));
834834
(*(*pTriInfos.offset(f as isize)).AssignedGroup[i as usize])
835835
.iVertexRepresentative = vert_index;
836836
(*(*pTriInfos.offset(f as isize)).AssignedGroup[i as usize]).bOrientPreservering =
837837
(*pTriInfos.offset(f as isize)).iFlag & 8i32 != 0i32;
838838
(*(*pTriInfos.offset(f as isize)).AssignedGroup[i as usize]).iNrFaces = 0i32;
839839
let ref mut fresh3 =
840840
(*(*pTriInfos.offset(f as isize)).AssignedGroup[i as usize]).pFaceIndices;
841-
*fresh3 = &mut *piGroupTrianglesBuffer.offset(iOffset as isize) as *mut i32;
841+
*fresh3 = ptr::from_mut(&mut *piGroupTrianglesBuffer.offset(iOffset as isize));
842842
iNrActiveGroups += 1;
843843
AddTriToGroup((*pTriInfos.offset(f as isize)).AssignedGroup[i as usize], f);
844844
bOrPre = if (*pTriInfos.offset(f as isize)).iFlag & 8i32 != 0i32 {

crates/bevy_render/src/mesh/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ impl Eq for MeshVertexBufferLayoutRef {}
8080

8181
impl Hash for MeshVertexBufferLayoutRef {
8282
fn hash<H: Hasher>(&self, state: &mut H) {
83-
(&*self.0 as *const MeshVertexBufferLayout as usize).hash(state);
83+
// Hash the address of the underlying data, so two layouts that share the same
84+
// `MeshVertexBufferLayout` will have the same hash.
85+
(Arc::as_ptr(&self.0) as usize).hash(state);
8486
}
8587
}

0 commit comments

Comments
 (0)