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](https://github.com/rust-lang/rust/issues/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.
This commit is contained in:
Clar Fon 2024-10-14 16:52:35 -04:00 committed by GitHub
parent bd912c25f7
commit e79bc7811d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 23 additions and 45 deletions

View File

@ -587,7 +587,7 @@ impl AssetSources {
AssetSourceId::Name(name) => self AssetSourceId::Name(name) => self
.sources .sources
.get(&name) .get(&name)
.ok_or_else(|| MissingAssetSourceError(AssetSourceId::Name(name))), .ok_or(MissingAssetSourceError(AssetSourceId::Name(name))),
} }
} }

View File

@ -101,7 +101,7 @@ impl BatchingStrategy {
); );
let batches = thread_count * self.batches_per_thread; let batches = thread_count * self.batches_per_thread;
// Round up to the nearest batch size. // Round up to the nearest batch size.
let batch_size = (max_items() + batches - 1) / batches; let batch_size = max_items().div_ceil(batches);
batch_size.clamp(self.batch_size_limits.start, self.batch_size_limits.end) batch_size.clamp(self.batch_size_limits.start, self.batch_size_limits.end)
} }
} }

View File

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

View File

@ -463,7 +463,6 @@ impl<'w, 's> Commands<'w, 's> {
/// ///
/// #[derive(Component)] /// #[derive(Component)]
/// struct Label(&'static str); /// struct Label(&'static str);
/// fn example_system(mut commands: Commands) { /// fn example_system(mut commands: Commands) {
/// // Create a new, empty entity /// // Create a new, empty entity
/// let entity = commands.spawn_empty().id(); /// let entity = commands.spawn_empty().id();
@ -565,7 +564,6 @@ impl<'w, 's> Commands<'w, 's> {
/// counter.0 += 25; /// counter.0 += 25;
/// }); /// });
/// } /// }
/// # bevy_ecs::system::assert_is_system(add_three_to_counter_system); /// # bevy_ecs::system::assert_is_system(add_three_to_counter_system);
/// # bevy_ecs::system::assert_is_system(add_twenty_five_to_counter_system); /// # bevy_ecs::system::assert_is_system(add_twenty_five_to_counter_system);
/// ``` /// ```

View File

@ -1,9 +1,9 @@
//! Internal components used by bevy with a fixed component id.
//! Constants are used to skip [`TypeId`] lookups in hot paths.
use super::*; use super::*;
use crate::{self as bevy_ecs}; use crate::{self as bevy_ecs};
#[cfg(feature = "bevy_reflect")] #[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
/// Internal components used by bevy with a fixed component id.
/// Constants are used to skip [`TypeId`] lookups in hot paths.
/// [`ComponentId`] for [`OnAdd`] /// [`ComponentId`] for [`OnAdd`]
pub const ON_ADD: ComponentId = ComponentId::new(0); pub const ON_ADD: ComponentId = ComponentId::new(0);

View File

@ -1175,7 +1175,7 @@ impl World {
pub fn get_many_entities_mut<const N: usize>( pub fn get_many_entities_mut<const N: usize>(
&mut self, &mut self,
entities: [Entity; N], entities: [Entity; N],
) -> Result<[EntityMut<'_>; N], QueryEntityError> { ) -> Result<[EntityMut<'_>; N], QueryEntityError<'_>> {
self.get_entity_mut(entities).map_err(|e| match e { self.get_entity_mut(entities).map_err(|e| match e {
EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity), EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity),
EntityFetchError::AliasedMutability(entity) => { EntityFetchError::AliasedMutability(entity) => {
@ -1212,7 +1212,7 @@ impl World {
pub fn get_many_entities_dynamic_mut<'w>( pub fn get_many_entities_dynamic_mut<'w>(
&'w mut self, &'w mut self,
entities: &[Entity], entities: &[Entity],
) -> Result<Vec<EntityMut<'w>>, QueryEntityError> { ) -> Result<Vec<EntityMut<'w>>, QueryEntityError<'w>> {
self.get_entity_mut(entities).map_err(|e| match e { self.get_entity_mut(entities).map_err(|e| match e {
EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity), EntityFetchError::NoSuchEntity(entity) => QueryEntityError::NoSuchEntity(entity),
EntityFetchError::AliasedMutability(entity) => { EntityFetchError::AliasedMutability(entity) => {
@ -1255,7 +1255,7 @@ impl World {
pub fn get_many_entities_from_set_mut<'w>( pub fn get_many_entities_from_set_mut<'w>(
&'w mut self, &'w mut self,
entities: &EntityHashSet, entities: &EntityHashSet,
) -> Result<Vec<EntityMut<'w>>, QueryEntityError> { ) -> Result<Vec<EntityMut<'w>>, QueryEntityError<'w>> {
self.get_entity_mut(entities) self.get_entity_mut(entities)
.map(|fetched| fetched.into_values().collect()) .map(|fetched| fetched.into_values().collect())
.map_err(|e| match e { .map_err(|e| match e {
@ -1331,13 +1331,13 @@ impl World {
/// ///
/// // `spawn` can accept a single component: /// // `spawn` can accept a single component:
/// world.spawn(Position { x: 0.0, y: 0.0 }); /// world.spawn(Position { x: 0.0, y: 0.0 });
///
/// // It can also accept a tuple of components: /// // It can also accept a tuple of components:
/// world.spawn(( /// world.spawn((
/// Position { x: 0.0, y: 0.0 }, /// Position { x: 0.0, y: 0.0 },
/// Velocity { x: 1.0, y: 1.0 }, /// Velocity { x: 1.0, y: 1.0 },
/// )); /// ));
///
/// // Or it can accept a pre-defined Bundle of components: /// // Or it can accept a pre-defined Bundle of components:
/// world.spawn(PhysicsBundle { /// world.spawn(PhysicsBundle {
/// position: Position { x: 2.0, y: 2.0 }, /// position: Position { x: 2.0, y: 2.0 },

View File

@ -166,8 +166,8 @@ pub fn ktx2_buffer_to_image(
(height >> level as u32).max(1), (height >> level as u32).max(1),
); );
let (num_blocks_x, num_blocks_y) = ( let (num_blocks_x, num_blocks_y) = (
((level_width + block_width_pixels - 1) / block_width_pixels) .max(1), level_width.div_ceil(block_width_pixels) .max(1),
((level_height + block_height_pixels - 1) / block_height_pixels) .max(1), level_height.div_ceil(block_height_pixels) .max(1),
); );
let level_bytes = (num_blocks_x * num_blocks_y * block_bytes) as usize; let level_bytes = (num_blocks_x * num_blocks_y * block_bytes) as usize;
@ -247,8 +247,8 @@ pub fn ktx2_buffer_to_image(
(depth as usize >> level).max(1), (depth as usize >> level).max(1),
); );
let (num_blocks_x, num_blocks_y) = ( let (num_blocks_x, num_blocks_y) = (
((level_width + block_width_pixels - 1) / block_width_pixels).max(1), level_width.div_ceil(block_width_pixels).max(1),
((level_height + block_height_pixels - 1) / block_height_pixels).max(1), level_height.div_ceil(block_height_pixels).max(1),
); );
let level_bytes = num_blocks_x * num_blocks_y * level_depth * block_bytes; let level_bytes = num_blocks_x * num_blocks_y * level_depth * block_bytes;

View File

@ -223,10 +223,6 @@ impl MorphAttributes {
} }
} }
/// Integer division rounded up.
const fn div_ceil(lhf: u32, rhs: u32) -> u32 {
(lhf + rhs - 1) / rhs
}
struct Rect(u32, u32); struct Rect(u32, u32);
/// Find the smallest rectangle of maximum edge size `max_edge` that contains /// Find the smallest rectangle of maximum edge size `max_edge` that contains
@ -249,7 +245,7 @@ struct Rect(u32, u32);
fn lowest_2d(min_includes: u32, max_edge: u32) -> Option<(Rect, u32)> { fn lowest_2d(min_includes: u32, max_edge: u32) -> Option<(Rect, u32)> {
(1..=max_edge) (1..=max_edge)
.filter_map(|a| { .filter_map(|a| {
let b = div_ceil(min_includes, a); let b = min_includes.div_ceil(a);
let diff = (a * b).checked_sub(min_includes)?; let diff = (a * b).checked_sub(min_includes)?;
Some((Rect(a, b), diff)) Some((Rect(a, b), diff))
}) })

View File

@ -268,8 +268,8 @@ impl ViewNode for SsaoNode {
&[view_uniform_offset.offset], &[view_uniform_offset.offset],
); );
preprocess_depth_pass.dispatch_workgroups( preprocess_depth_pass.dispatch_workgroups(
div_ceil(camera_size.x, 16), camera_size.x.div_ceil(16),
div_ceil(camera_size.y, 16), camera_size.y.div_ceil(16),
1, 1,
); );
} }
@ -289,11 +289,7 @@ impl ViewNode for SsaoNode {
&bind_groups.common_bind_group, &bind_groups.common_bind_group,
&[view_uniform_offset.offset], &[view_uniform_offset.offset],
); );
ssao_pass.dispatch_workgroups( ssao_pass.dispatch_workgroups(camera_size.x.div_ceil(8), camera_size.y.div_ceil(8), 1);
div_ceil(camera_size.x, 8),
div_ceil(camera_size.y, 8),
1,
);
} }
{ {
@ -312,8 +308,8 @@ impl ViewNode for SsaoNode {
&[view_uniform_offset.offset], &[view_uniform_offset.offset],
); );
spatial_denoise_pass.dispatch_workgroups( spatial_denoise_pass.dispatch_workgroups(
div_ceil(camera_size.x, 8), camera_size.x.div_ceil(8),
div_ceil(camera_size.y, 8), camera_size.y.div_ceil(8),
1, 1,
); );
} }
@ -805,8 +801,3 @@ fn hilbert_index(mut x: u16, mut y: u16) -> u16 {
index index
} }
/// Divide `numerator` by `denominator`, rounded up to the nearest multiple of `denominator`.
fn div_ceil(numerator: u32, denominator: u32) -> u32 {
(numerator + denominator - 1) / denominator
}

View File

@ -277,7 +277,7 @@ impl<'a> ReflectDerive<'a> {
return Ok(Self::Opaque(meta)); return Ok(Self::Opaque(meta));
} }
return match &input.data { match &input.data {
Data::Struct(data) => { Data::Struct(data) => {
let fields = Self::collect_struct_fields(&data.fields)?; let fields = Self::collect_struct_fields(&data.fields)?;
let reflect_struct = ReflectStruct { let reflect_struct = ReflectStruct {
@ -302,7 +302,7 @@ impl<'a> ReflectDerive<'a> {
input.span(), input.span(),
"reflection not supported for unions", "reflection not supported for unions",
)), )),
}; }
} }
/// Set the remote type for this derived type. /// Set the remote type for this derived type.

View File

@ -44,7 +44,6 @@ use core::{
/// ///
/// [struct-like]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html /// [struct-like]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html
/// [reflection]: crate /// [reflection]: crate
/// [unit structs]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#unit-like-structs-without-any-fields /// [unit structs]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#unit-like-structs-without-any-fields
pub trait Struct: PartialReflect { pub trait Struct: PartialReflect {
/// Returns a reference to the value of the field named `name` as a `&dyn /// Returns a reference to the value of the field named `name` as a `&dyn

View File

@ -121,7 +121,7 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
#[inline] #[inline]
fn align_to_next(value: u64, alignment: u64) -> u64 { fn align_to_next(value: u64, alignment: u64) -> u64 {
debug_assert!(alignment & (alignment - 1) == 0); debug_assert!(alignment.is_power_of_two());
((value - 1) | (alignment - 1)) + 1 ((value - 1) | (alignment - 1)) + 1
} }

View File

@ -92,7 +92,6 @@ use super::{Sampler, TextureView};
/// ], /// ],
/// ); /// );
/// ``` /// ```
pub struct BindGroupEntries<'b, const N: usize = 1> { pub struct BindGroupEntries<'b, const N: usize = 1> {
entries: [BindGroupEntry<'b>; N], entries: [BindGroupEntry<'b>; N],
} }

View File

@ -10,7 +10,6 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
/// ///
/// This enum allows specifying values for various [`Style`](crate::Style) properties in different units, /// This enum allows specifying values for various [`Style`](crate::Style) properties in different units,
/// such as logical pixels, percentages, or automatically determined values. /// such as logical pixels, percentages, or automatically determined values.
#[derive(Copy, Clone, Debug, Reflect)] #[derive(Copy, Clone, Debug, Reflect)]
#[reflect(Default, PartialEq, Debug)] #[reflect(Default, PartialEq, Debug)]
#[cfg_attr( #[cfg_attr(
@ -204,7 +203,7 @@ impl Val {
/// A type which is commonly used to define margins, paddings and borders. /// A type which is commonly used to define margins, paddings and borders.
/// ///
/// # Examples /// # Examples
///
/// ## Margin /// ## Margin
/// ///
/// A margin is used to create space around UI elements, outside of any defined borders. /// A margin is used to create space around UI elements, outside of any defined borders.
@ -244,7 +243,6 @@ impl Val {
/// bottom: Val::Px(40.0), /// bottom: Val::Px(40.0),
/// }; /// };
/// ``` /// ```
#[derive(Copy, Clone, PartialEq, Debug, Reflect)] #[derive(Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect(Default, PartialEq, Debug)] #[reflect(Default, PartialEq, Debug)]
#[cfg_attr( #[cfg_attr(

View File

@ -2046,7 +2046,6 @@ pub struct CalculatedClip {
/// appear in the UI hierarchy. In such a case, the last node to be added to its parent /// appear in the UI hierarchy. In such a case, the last node to be added to its parent
/// will appear in front of its siblings. /// will appear in front of its siblings.
/// ///
/// Nodes without this component will be treated as if they had a value of [`ZIndex(0)`]. /// Nodes without this component will be treated as if they had a value of [`ZIndex(0)`].
#[derive(Component, Copy, Clone, Debug, Default, PartialEq, Eq, Reflect)] #[derive(Component, Copy, Clone, Debug, Default, PartialEq, Eq, Reflect)]
#[reflect(Component, Default, Debug, PartialEq)] #[reflect(Component, Default, Debug, PartialEq)]

View File

@ -85,7 +85,6 @@ fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window
/// This feature only works on some platforms. Please check the /// This feature only works on some platforms. Please check the
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level) /// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
/// for more details. /// for more details.
fn switch_level(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) { fn switch_level(input: Res<ButtonInput<KeyCode>>, mut window: Single<&mut Window>) {
if input.just_pressed(KeyCode::KeyT) { if input.just_pressed(KeyCode::KeyT) {
window.window_level = match window.window_level { window.window_level = match window.window_level {