Skip to content

Commit 3ac00ed

Browse files
authored
Use Embark lints v0.2 (#128)
Switches to use our new standard template for defining shared Rust and Clippy lints for our Embark projects, EmbarkStudios/rust-ecosystem#59. Did a couple of lint fixes from this but didn't want to make the change too intrusive so added some allow exceptions for now that can be revisited
1 parent 016a12e commit 3ac00ed

10 files changed

+169
-81
lines changed

physx-sys/src/lib.rs

+60-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

physx/src/aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
142142
PxAggregate_addActor_mut(
143143
self.as_mut_ptr(),
144144
actor.as_mut_ptr(),
145-
bvh.map(Class::as_ptr).unwrap_or(null()),
145+
bvh.map_or(null(), Class::as_ptr),
146146
)
147147
}
148148
}
@@ -157,7 +157,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
157157
PxAggregate_addActor_mut(
158158
self.as_mut_ptr(),
159159
actor.as_mut_ptr(),
160-
bvh.map(Class::as_ptr).unwrap_or(null()),
160+
bvh.map_or(null(), Class::as_ptr),
161161
)
162162
}
163163
}
@@ -172,7 +172,7 @@ pub trait Aggregate: Class<physx_sys::PxAggregate> + Base {
172172
PxAggregate_addActor_mut(
173173
self.as_mut_ptr(),
174174
actor.as_mut_ptr(),
175-
bvh.map(Class::as_ptr).unwrap_or(null()),
175+
bvh.map_or(null(), Class::as_ptr),
176176
)
177177
}
178178
}

physx/src/articulation_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ pub trait ArticulationBase: Class<physx_sys::PxArticulationBase> + Base {
226226
unsafe {
227227
(PxArticulationBase_createLink_mut(
228228
self.as_mut_ptr(),
229-
parent
230-
.map(|parent| parent.as_mut_ptr())
231-
.unwrap_or(null_mut()),
229+
parent.map_or(null_mut(), |parent| parent.as_mut_ptr()),
232230
pose.as_ptr(),
233231
) as *mut Self::ArticulationLink)
234232
.as_mut()

physx/src/base.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,30 @@ pub enum ConcreteType {
6565

6666
impl From<u16> for ConcreteType {
6767
fn from(val: u16) -> Self {
68-
use ConcreteType::*;
6968
match val {
70-
0 => Undefined,
71-
1 => Heightfield,
72-
2 => ConvexMesh,
73-
3 => TriangleMeshBvh33,
74-
4 => TriangleMeshBvh34,
75-
5 => RigidDynamic,
76-
6 => RigidStatic,
77-
7 => Shape,
78-
8 => Material,
79-
9 => Constraint,
80-
10 => Aggregate,
81-
11 => Articulation,
82-
12 => ArticulationReducedCoordinate,
83-
13 => ArticulationLink,
84-
14 => ArticulationJoint,
85-
15 => ArticulationJointReducedCoordinate,
86-
16 => PruningStructure,
87-
17 => BvhStructure,
88-
18 => PhysxCoreCount,
89-
256 => FirstPhysxExtension,
90-
512 => FirstVehicleExtension,
91-
1024 => FirstUserExtension,
92-
_ => Undefined,
69+
0 => ConcreteType::Undefined,
70+
1 => ConcreteType::Heightfield,
71+
2 => ConcreteType::ConvexMesh,
72+
3 => ConcreteType::TriangleMeshBvh33,
73+
4 => ConcreteType::TriangleMeshBvh34,
74+
5 => ConcreteType::RigidDynamic,
75+
6 => ConcreteType::RigidStatic,
76+
7 => ConcreteType::Shape,
77+
8 => ConcreteType::Material,
78+
9 => ConcreteType::Constraint,
79+
10 => ConcreteType::Aggregate,
80+
11 => ConcreteType::Articulation,
81+
12 => ConcreteType::ArticulationReducedCoordinate,
82+
13 => ConcreteType::ArticulationLink,
83+
14 => ConcreteType::ArticulationJoint,
84+
15 => ConcreteType::ArticulationJointReducedCoordinate,
85+
16 => ConcreteType::PruningStructure,
86+
17 => ConcreteType::BvhStructure,
87+
18 => ConcreteType::PhysxCoreCount,
88+
256 => ConcreteType::FirstPhysxExtension,
89+
512 => ConcreteType::FirstVehicleExtension,
90+
1024 => ConcreteType::FirstUserExtension,
91+
_ => ConcreteType::Undefined,
9392
}
9493
}
9594
}

physx/src/lib.rs

+53-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
// Author: Tom Olsson <tom.olsson@embark-studios.com>
2-
// Copyright © 2019, Embark Studios, all rights reserved.
3-
// Created: 2 April 2019
4-
5-
#![warn(clippy::all)]
6-
#![deny(rust_2018_idioms)]
7-
81
//! # 🎳 physx
92
//!
103
//! ![Build Status](https://github.com/EmbarkStudios/physx-rs/workflows/CI/badge.svg)
@@ -100,6 +93,59 @@
10093
//! license, shall be dual licensed as above, without any additional terms or
10194
//! conditions.
10295
96+
// BEGIN - Embark standard lints v0.2.
97+
// do not change or add/remove here, but one can add exceptions after this section
98+
// for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
99+
#![deny(unsafe_code)]
100+
#![warn(
101+
clippy::all,
102+
clippy::await_holding_lock,
103+
clippy::dbg_macro,
104+
clippy::debug_assert_with_mut_call,
105+
clippy::doc_markdown,
106+
clippy::empty_enum,
107+
clippy::enum_glob_use,
108+
clippy::exit,
109+
clippy::explicit_into_iter_loop,
110+
clippy::filter_map_next,
111+
clippy::fn_params_excessive_bools,
112+
clippy::if_let_mutex,
113+
clippy::imprecise_flops,
114+
clippy::inefficient_to_string,
115+
clippy::let_unit_value,
116+
clippy::linkedlist,
117+
clippy::lossy_float_literal,
118+
clippy::macro_use_imports,
119+
clippy::map_flatten,
120+
clippy::map_unwrap_or,
121+
clippy::match_on_vec_items,
122+
clippy::match_wildcard_for_single_variants,
123+
clippy::mem_forget,
124+
clippy::mismatched_target_os,
125+
clippy::needless_borrow,
126+
clippy::needless_continue,
127+
clippy::option_option,
128+
clippy::pub_enum_variant_names,
129+
clippy::ref_option_ref,
130+
clippy::rest_pat_in_fully_bound_structs,
131+
clippy::string_to_string,
132+
clippy::suboptimal_flops,
133+
clippy::todo,
134+
clippy::unnested_or_patterns,
135+
clippy::unused_self,
136+
clippy::verbose_file_reads,
137+
future_incompatible,
138+
nonstandard_style,
139+
rust_2018_idioms
140+
)]
141+
// END - Embark standard lints v0.2
142+
// crate-specific exceptions:
143+
#![allow(
144+
unsafe_code, // this is a safe wrapper of unsafe code, so plenty of unsafe code in here
145+
clippy::doc_markdown, // TODO: fixup comments and docs (though annoyingly complains about "PhysX")
146+
clippy::pub_enum_variant_names, // TODO: revisit, will change API, remove from standard set?
147+
)]
148+
103149
// Utility traits
104150
pub mod traits;
105151

physx/src/owner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl<T> Owner<T> {
2525
}
2626

2727
/// Consumes the Owner without calling Drop and returns the raw pointer it was wrapping.
28+
#[allow(clippy::mem_forget)]
2829
pub fn into_ptr<S>(mut self) -> *mut S
2930
where
3031
T: Class<S>,

physx/src/physics.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,7 @@ impl<Allocator: AllocatorCallback> PhysicsFoundationBuilder<Allocator> {
717717
unsafe {
718718
phys_PxInitExtensions(
719719
physics.as_mut_ptr(),
720-
pvd.as_mut()
721-
.map(|pv| pv.as_mut_ptr())
722-
.unwrap_or_else(null_mut),
720+
pvd.as_mut().map_or_else(null_mut, |pv| pv.as_mut_ptr()),
723721
)
724722
}
725723
} else {

physx/src/scene.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
569569
completion_task: Option<&mut PxBaseTask>,
570570
scratch: Option<&mut ScratchBuffer>,
571571
) {
572-
let completion_task = completion_task.map(|t| t as *mut _).unwrap_or(null_mut());
572+
let completion_task = completion_task.map_or(null_mut(), |t| t as *mut _);
573573

574574
let (scratch_ptr, scratch_size) = if let Some(scratch) = scratch {
575575
scratch.as_ptr_and_size()
@@ -761,19 +761,19 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
761761
// Callbacks
762762

763763
/// # Safety
764-
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
764+
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
765765
unsafe fn set_contact_modify_callback(&mut self, callback: &mut PxContactModifyCallback) {
766766
PxScene_setContactModifyCallback_mut(self.as_mut_ptr(), callback);
767767
}
768768

769769
/// # Safety
770-
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
770+
/// PxContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
771771
unsafe fn get_contact_modify_callback(&self) -> &PxContactModifyCallback {
772772
&*PxScene_getContactModifyCallback(self.as_ptr())
773773
}
774774

775775
/// # Safety
776-
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
776+
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
777777
unsafe fn set_ccd_contact_modify_callback(
778778
&mut self,
779779
callback: &mut PxCCDContactModifyCallback,
@@ -782,19 +782,19 @@ pub trait Scene: Class<physx_sys::PxScene> + UserData {
782782
}
783783

784784
/// # Safety
785-
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of physx_sys.
785+
/// PxCCDContactModifyCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
786786
unsafe fn get_ccd_contact_callback(&self) -> &PxCCDContactModifyCallback {
787787
&*PxScene_getCCDContactModifyCallback(self.as_ptr())
788788
}
789789

790790
/// # Safety
791-
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of physx_sys.
791+
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
792792
unsafe fn set_broad_phase_callback(&mut self, callback: &mut PxBroadPhaseCallback) {
793793
PxScene_setBroadPhaseCallback_mut(self.as_mut_ptr(), callback);
794794
}
795795

796796
/// # Safety
797-
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of physx_sys.
797+
/// PxBroadPhaseCallback does not have a safe wrapper, using it requires use of [`physx_sys`].
798798
unsafe fn get_broad_phase_callback(&self) -> &PxBroadPhaseCallback {
799799
&*PxScene_getBroadPhaseCallback(self.as_ptr())
800800
}

physx/src/simulation_event_callback.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,16 @@ where
8484
OA: AdvanceCallback<L, D>,
8585
{
8686
unsafe {
87-
let (collision_callback, collision_user_data) = on_collide
88-
.map(OC::into_cb_user_data)
89-
.unwrap_or((None, null_mut()));
90-
let (trigger_callback, trigger_user_data) = on_trigger
91-
.map(OT::into_cb_user_data)
92-
.unwrap_or((None, null_mut()));
93-
let (constraint_break_callback, constraint_break_user_data) = on_constraint_break
94-
.map(OCB::into_cb_user_data)
95-
.unwrap_or((None, null_mut()));
96-
let (wake_sleep_callback, wake_sleep_user_data) = on_wake_sleep
97-
.map(OWS::into_cb_user_data)
98-
.unwrap_or((None, null_mut()));
99-
let (advance_callback, advance_user_data) = on_advance
100-
.map(OA::into_cb_user_data)
101-
.unwrap_or((None, null_mut()));
87+
let (collision_callback, collision_user_data) =
88+
on_collide.map_or((None, null_mut()), OC::into_cb_user_data);
89+
let (trigger_callback, trigger_user_data) =
90+
on_trigger.map_or((None, null_mut()), OT::into_cb_user_data);
91+
let (constraint_break_callback, constraint_break_user_data) =
92+
on_constraint_break.map_or((None, null_mut()), OCB::into_cb_user_data);
93+
let (wake_sleep_callback, wake_sleep_user_data) =
94+
on_wake_sleep.map_or((None, null_mut()), OWS::into_cb_user_data);
95+
let (advance_callback, advance_user_data) =
96+
on_advance.map_or((None, null_mut()), OA::into_cb_user_data);
10297

10398
Owner::from_raw(
10499
create_simulation_event_callbacks(&SimulationEventCallbackInfo {
@@ -239,8 +234,8 @@ trait ConstraintBreakCallbackRaw: ConstraintBreakCallback {
239234
}
240235
}
241236

242-
/// A trait for onWake() and onSleep() callbacks. Parametrized by the ArticulationLink,
243-
/// RigidStatic, and RigidDynamic types of the scene it is in.
237+
/// A trait for `onWake()` and `onSleep()` callbacks. Parametrized by the [`ArticulationLink`],
238+
/// [`RigidStatic`], and [`RigidDynamic`] types of the scene it is in.
244239
pub trait WakeSleepCallback<L: ArticulationLink, S: RigidStatic, D: RigidDynamic>: Sized {
245240
fn on_wake_sleep(&mut self, actors: &[&ActorMap<L, S, D>], is_waking: bool);
246241
}
@@ -282,10 +277,10 @@ where
282277
}
283278

284279
/// A trait for the Advance Callback. onAdvance() is called during simulation, so it must
285-
/// be thread safe, and `self` is not mutable. Parametrized by the ArticulationLink
286-
/// and RigidDynamic types of the scene it is in.
280+
/// be thread safe, and `self` is not mutable. Parametrized by the `ArticulationLink`
281+
/// and `RigidDynamic` types of the scene it is in.
287282
pub trait AdvanceCallback<L: ArticulationLink, D: RigidDynamic>: Sized {
288-
/// All actors with PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW set will be passed into here
283+
/// All actors with `PxRigidBodyFlag::eENABLE_POSE_INTEGRATION_PREVIEW` set will be passed into here
289284
/// once the simulate call has updated their position.
290285
fn on_advance(&self, actors: &[&RigidBodyMap<L, D>], transforms: &[PxTransform]);
291286
}

0 commit comments

Comments
 (0)