Skip to content

Commit e79bc78

Browse files
authored
Fix *most* clippy lints (#15906)
# Objective Another clippy-lint fix: the goal is so that `ci lints` actually displays the problems that a contributor caused, and not a bunch of existing stuff in the repo. (when run on nightly) ## Solution This fixes all but the `clippy::needless_lifetimes` lint, which will result in substantially more fixes and be in other PR(s). I also explicitly allow `non_local_definitions` since it is [not working correctly, but will be fixed](rust-lang/rust#131643). A few things were manually fixed: for example, some places had an explicitly defined `div_ceil` function that was used, which is no longer needed since this function is stable on unsigned integers. Also, empty lines in doc comments were handled individually. ## Testing I ran `cargo clippy --workspace --all-targets --all-features --fix --allow-staged` with the `clippy::needless_lifetimes` lint marked as `allow` in `Cargo.toml` to avoid fixing that too. It now passes with all but the listed lint.
1 parent bd912c2 commit e79bc78

File tree

16 files changed

+23
-45
lines changed

16 files changed

+23
-45
lines changed

crates/bevy_asset/src/io/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl AssetSources {
587587
AssetSourceId::Name(name) => self
588588
.sources
589589
.get(&name)
590-
.ok_or_else(|| MissingAssetSourceError(AssetSourceId::Name(name))),
590+
.ok_or(MissingAssetSourceError(AssetSourceId::Name(name))),
591591
}
592592
}
593593

crates/bevy_ecs/src/batching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl BatchingStrategy {
101101
);
102102
let batches = thread_count * self.batches_per_thread;
103103
// Round up to the nearest batch size.
104-
let batch_size = (max_items() + batches - 1) / batches;
104+
let batch_size = max_items().div_ceil(batches);
105105
batch_size.clamp(self.batch_size_limits.start, self.batch_size_limits.end)
106106
}
107107
}

crates/bevy_ecs/src/bundle.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ impl BundleInfo {
461461
}
462462

463463
/// Returns an iterator over the [ID](ComponentId) of each component explicitly defined in this bundle (ex: this excludes Required Components).
464-
465464
/// To iterate all components contributed by this bundle (including Required Components), see [`BundleInfo::iter_contributed_components`]
466465
#[inline]
467466
pub fn iter_explicit_components(&self) -> impl Iterator<Item = ComponentId> + '_ {

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl<'w, 's> Commands<'w, 's> {
463463
///
464464
/// #[derive(Component)]
465465
/// struct Label(&'static str);
466-
467466
/// fn example_system(mut commands: Commands) {
468467
/// // Create a new, empty entity
469468
/// let entity = commands.spawn_empty().id();
@@ -565,7 +564,6 @@ impl<'w, 's> Commands<'w, 's> {
565564
/// counter.0 += 25;
566565
/// });
567566
/// }
568-
569567
/// # bevy_ecs::system::assert_is_system(add_three_to_counter_system);
570568
/// # bevy_ecs::system::assert_is_system(add_twenty_five_to_counter_system);
571569
/// ```

crates/bevy_ecs/src/world/component_constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
//! Internal components used by bevy with a fixed component id.
2+
//! Constants are used to skip [`TypeId`] lookups in hot paths.
13
use super::*;
24
use crate::{self as bevy_ecs};
35
#[cfg(feature = "bevy_reflect")]
46
use bevy_reflect::Reflect;
5-
/// Internal components used by bevy with a fixed component id.
6-
/// Constants are used to skip [`TypeId`] lookups in hot paths.
77

88
/// [`ComponentId`] for [`OnAdd`]
99
pub const ON_ADD: ComponentId = ComponentId::new(0);

crates/bevy_ecs/src/world/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ impl World {
11751175
pub fn get_many_entities_mut<const N: usize>(
11761176
&mut self,
11771177
entities: [Entity; N],
1178-
) -> Result<[EntityMut<'_>; N], QueryEntityError> {
1178+
) -> Result<[EntityMut<'_>; N], QueryEntityError<'_>> {
11791179
self.get_entity_mut(entities).map_err(|e| match e {
11801180
EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity),
11811181
EntityFetchError::AliasedMutability(entity) => {
@@ -1212,7 +1212,7 @@ impl World {
12121212
pub fn get_many_entities_dynamic_mut<'w>(
12131213
&'w mut self,
12141214
entities: &[Entity],
1215-
) -> Result<Vec<EntityMut<'w>>, QueryEntityError> {
1215+
) -> Result<Vec<EntityMut<'w>>, QueryEntityError<'w>> {
12161216
self.get_entity_mut(entities).map_err(|e| match e {
12171217
EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity),
12181218
EntityFetchError::AliasedMutability(entity) => {
@@ -1255,7 +1255,7 @@ impl World {
12551255
pub fn get_many_entities_from_set_mut<'w>(
12561256
&'w mut self,
12571257
entities: &EntityHashSet,
1258-
) -> Result<Vec<EntityMut<'w>>, QueryEntityError> {
1258+
) -> Result<Vec<EntityMut<'w>>, QueryEntityError<'w>> {
12591259
self.get_entity_mut(entities)
12601260
.map(|fetched| fetched.into_values().collect())
12611261
.map_err(|e| match e {
@@ -1331,13 +1331,13 @@ impl World {
13311331
///
13321332
/// // `spawn` can accept a single component:
13331333
/// world.spawn(Position { x: 0.0, y: 0.0 });
1334-
1334+
///
13351335
/// // It can also accept a tuple of components:
13361336
/// world.spawn((
13371337
/// Position { x: 0.0, y: 0.0 },
13381338
/// Velocity { x: 1.0, y: 1.0 },
13391339
/// ));
1340-
1340+
///
13411341
/// // Or it can accept a pre-defined Bundle of components:
13421342
/// world.spawn(PhysicsBundle {
13431343
/// position: Position { x: 2.0, y: 2.0 },

crates/bevy_image/src/ktx2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ pub fn ktx2_buffer_to_image(
166166
(height >> level as u32).max(1),
167167
);
168168
let (num_blocks_x, num_blocks_y) = (
169-
((level_width + block_width_pixels - 1) / block_width_pixels) .max(1),
170-
((level_height + block_height_pixels - 1) / block_height_pixels) .max(1),
169+
level_width.div_ceil(block_width_pixels) .max(1),
170+
level_height.div_ceil(block_height_pixels) .max(1),
171171
);
172172
let level_bytes = (num_blocks_x * num_blocks_y * block_bytes) as usize;
173173

@@ -247,8 +247,8 @@ pub fn ktx2_buffer_to_image(
247247
(depth as usize >> level).max(1),
248248
);
249249
let (num_blocks_x, num_blocks_y) = (
250-
((level_width + block_width_pixels - 1) / block_width_pixels).max(1),
251-
((level_height + block_height_pixels - 1) / block_height_pixels).max(1),
250+
level_width.div_ceil(block_width_pixels).max(1),
251+
level_height.div_ceil(block_height_pixels).max(1),
252252
);
253253
let level_bytes = num_blocks_x * num_blocks_y * level_depth * block_bytes;
254254

crates/bevy_mesh/src/morph.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ impl MorphAttributes {
223223
}
224224
}
225225

226-
/// Integer division rounded up.
227-
const fn div_ceil(lhf: u32, rhs: u32) -> u32 {
228-
(lhf + rhs - 1) / rhs
229-
}
230226
struct Rect(u32, u32);
231227

232228
/// Find the smallest rectangle of maximum edge size `max_edge` that contains
@@ -249,7 +245,7 @@ struct Rect(u32, u32);
249245
fn lowest_2d(min_includes: u32, max_edge: u32) -> Option<(Rect, u32)> {
250246
(1..=max_edge)
251247
.filter_map(|a| {
252-
let b = div_ceil(min_includes, a);
248+
let b = min_includes.div_ceil(a);
253249
let diff = (a * b).checked_sub(min_includes)?;
254250
Some((Rect(a, b), diff))
255251
})

crates/bevy_pbr/src/ssao/mod.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ impl ViewNode for SsaoNode {
268268
&[view_uniform_offset.offset],
269269
);
270270
preprocess_depth_pass.dispatch_workgroups(
271-
div_ceil(camera_size.x, 16),
272-
div_ceil(camera_size.y, 16),
271+
camera_size.x.div_ceil(16),
272+
camera_size.y.div_ceil(16),
273273
1,
274274
);
275275
}
@@ -289,11 +289,7 @@ impl ViewNode for SsaoNode {
289289
&bind_groups.common_bind_group,
290290
&[view_uniform_offset.offset],
291291
);
292-
ssao_pass.dispatch_workgroups(
293-
div_ceil(camera_size.x, 8),
294-
div_ceil(camera_size.y, 8),
295-
1,
296-
);
292+
ssao_pass.dispatch_workgroups(camera_size.x.div_ceil(8), camera_size.y.div_ceil(8), 1);
297293
}
298294

299295
{
@@ -312,8 +308,8 @@ impl ViewNode for SsaoNode {
312308
&[view_uniform_offset.offset],
313309
);
314310
spatial_denoise_pass.dispatch_workgroups(
315-
div_ceil(camera_size.x, 8),
316-
div_ceil(camera_size.y, 8),
311+
camera_size.x.div_ceil(8),
312+
camera_size.y.div_ceil(8),
317313
1,
318314
);
319315
}
@@ -805,8 +801,3 @@ fn hilbert_index(mut x: u16, mut y: u16) -> u16 {
805801

806802
index
807803
}
808-
809-
/// Divide `numerator` by `denominator`, rounded up to the nearest multiple of `denominator`.
810-
fn div_ceil(numerator: u32, denominator: u32) -> u32 {
811-
(numerator + denominator - 1) / denominator
812-
}

crates/bevy_reflect/derive/src/derive_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'a> ReflectDerive<'a> {
277277
return Ok(Self::Opaque(meta));
278278
}
279279

280-
return match &input.data {
280+
match &input.data {
281281
Data::Struct(data) => {
282282
let fields = Self::collect_struct_fields(&data.fields)?;
283283
let reflect_struct = ReflectStruct {
@@ -302,7 +302,7 @@ impl<'a> ReflectDerive<'a> {
302302
input.span(),
303303
"reflection not supported for unions",
304304
)),
305-
};
305+
}
306306
}
307307

308308
/// Set the remote type for this derived type.

crates/bevy_reflect/src/struct_trait.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use core::{
4444
///
4545
/// [struct-like]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html
4646
/// [reflection]: crate
47-
4847
/// [unit structs]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#unit-like-structs-without-any-fields
4948
pub trait Struct: PartialReflect {
5049
/// Returns a reference to the value of the field named `name` as a `&dyn

crates/bevy_render/src/render_resource/batched_uniform_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
121121

122122
#[inline]
123123
fn align_to_next(value: u64, alignment: u64) -> u64 {
124-
debug_assert!(alignment & (alignment - 1) == 0);
124+
debug_assert!(alignment.is_power_of_two());
125125
((value - 1) | (alignment - 1)) + 1
126126
}
127127

crates/bevy_render/src/render_resource/bind_group_entries.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ use super::{Sampler, TextureView};
9292
/// ],
9393
/// );
9494
/// ```
95-
9695
pub struct BindGroupEntries<'b, const N: usize = 1> {
9796
entries: [BindGroupEntry<'b>; N],
9897
}

crates/bevy_ui/src/geometry.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
1010
///
1111
/// This enum allows specifying values for various [`Style`](crate::Style) properties in different units,
1212
/// such as logical pixels, percentages, or automatically determined values.
13-
1413
#[derive(Copy, Clone, Debug, Reflect)]
1514
#[reflect(Default, PartialEq, Debug)]
1615
#[cfg_attr(
@@ -204,7 +203,7 @@ impl Val {
204203
/// A type which is commonly used to define margins, paddings and borders.
205204
///
206205
/// # Examples
207-
206+
///
208207
/// ## Margin
209208
///
210209
/// A margin is used to create space around UI elements, outside of any defined borders.
@@ -244,7 +243,6 @@ impl Val {
244243
/// bottom: Val::Px(40.0),
245244
/// };
246245
/// ```
247-
248246
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
249247
#[reflect(Default, PartialEq, Debug)]
250248
#[cfg_attr(

crates/bevy_ui/src/ui_node.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,6 @@ pub struct CalculatedClip {
20462046
/// appear in the UI hierarchy. In such a case, the last node to be added to its parent
20472047
/// will appear in front of its siblings.
20482048
///
2049-
20502049
/// Nodes without this component will be treated as if they had a value of [`ZIndex(0)`].
20512050
#[derive(Component, Copy, Clone, Debug, Default, PartialEq, Eq, Reflect)]
20522051
#[reflect(Component, Default, Debug, PartialEq)]

examples/window/window_settings.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window
8585
/// This feature only works on some platforms. Please check the
8686
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
8787
/// for more details.
88-
8988
fn switch_level(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
9089
if input.just_pressed(KeyCode::KeyT) {
9190
window.window_level = match window.window_level {

0 commit comments

Comments
 (0)