Skip to content

Commit

Permalink
fix nightly clippy warnings (#6395)
Browse files Browse the repository at this point in the history
# Objective

- fix new clippy lints before they get stable and break CI

## Solution

- run `clippy --fix` to auto-fix machine-applicable lints
- silence `clippy::should_implement_trait` for `fn HandleId::default<T: Asset>`

## Changes
- always prefer `format!("{inline}")` over `format!("{}", not_inline)`
- prefer `Box::default` (or `Box::<T>::default` if necessary) over `Box::new(T::default())`
  • Loading branch information
jakobhellermann committed Oct 28, 2022
1 parent c27186c commit e71c4d2
Show file tree
Hide file tree
Showing 61 changed files with 153 additions and 157 deletions.
5 changes: 1 addition & 4 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ impl AssetServer {
.server
.asset_lifecycles
.write()
.insert(
T::TYPE_UUID,
Box::new(AssetLifecycleChannel::<T>::default()),
)
.insert(T::TYPE_UUID, Box::<AssetLifecycleChannel<T>>::default())
.is_some()
{
panic!("Error while registering new asset type: {:?} with UUID: {:?}. Another type with the same UUID is already registered. Can not register new asset type with the same UUID",
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl HandleId {

/// Creates the default id for an asset of type `T`.
#[inline]
#[allow(clippy::should_implement_trait)] // `Default` is not implemented for `HandleId`, the default value depends on the asset type
pub fn default<T: Asset>() -> Self {
HandleId::Id(T::TYPE_UUID, 0)
}
Expand Down Expand Up @@ -294,7 +295,7 @@ impl<T: Asset> Default for Handle<T> {
impl<T: Asset> Debug for Handle<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
let name = std::any::type_name::<T>().split("::").last().unwrap();
write!(f, "{:?}Handle<{}>({:?})", self.handle_type, name, self.id)
write!(f, "{:?}Handle<{name}>({:?})", self.handle_type, self.id)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/examples/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {

// Simulate 10 frames in our world
for iteration in 1..=10 {
println!("Simulating frame {}/10", iteration);
println!("Simulating frame {iteration}/10");
schedule.run(&mut world);
}
}
Expand Down Expand Up @@ -66,7 +66,7 @@ enum SimulationSystem {
fn spawn_entities(mut commands: Commands, mut entity_counter: ResMut<EntityCounter>) {
if rand::thread_rng().gen_bool(0.6) {
let entity_id = commands.spawn(Age::default()).id();
println!(" spawning {:?}", entity_id);
println!(" spawning {entity_id:?}");
entity_counter.value += 1;
}
}
Expand All @@ -82,10 +82,10 @@ fn print_changed_entities(
entity_with_mutated_component: Query<(Entity, &Age), Changed<Age>>,
) {
for entity in &entity_with_added_component {
println!(" {:?} has it's first birthday!", entity);
println!(" {entity:?} has it's first birthday!");
}
for (entity, value) in &entity_with_mutated_component {
println!(" {:?} is now {:?} frames old", entity, value);
println!(" {entity:?} is now {value:?} frames old");
}
}

Expand All @@ -100,7 +100,7 @@ fn age_all_entities(mut entities: Query<&mut Age>) {
fn remove_old_entities(mut commands: Commands, entities: Query<(Entity, &Age)>) {
for (entity, age) in &entities {
if age.frames > 2 {
println!(" despawning {:?} due to age > 2", entity);
println!(" despawning {entity:?} due to age > 2");
commands.entity(entity).despawn();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {

// Simulate 10 frames of our world
for iteration in 1..=10 {
println!("Simulating frame {}/10", iteration);
println!("Simulating frame {iteration}/10");
schedule.run(&mut world);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/examples/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
schedule.add_stage(Update, update);

for iteration in 1..=10 {
println!("Simulating frame {}/10", iteration);
println!("Simulating frame {iteration}/10");
schedule.run(&mut world);
}
}
Expand Down
18 changes: 8 additions & 10 deletions crates/bevy_ecs/macros/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
}
Ok(())
})
.unwrap_or_else(|_| panic!("Invalid `{}` attribute format", WORLD_QUERY_ATTRIBUTE_NAME));
.unwrap_or_else(|_| panic!("Invalid `{WORLD_QUERY_ATTRIBUTE_NAME}` attribute format"));
}

let path = bevy_ecs_path();
Expand All @@ -93,26 +93,26 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {

let struct_name = ast.ident.clone();
let read_only_struct_name = if fetch_struct_attributes.is_mutable {
Ident::new(&format!("{}ReadOnly", struct_name), Span::call_site())
Ident::new(&format!("{struct_name}ReadOnly"), Span::call_site())
} else {
struct_name.clone()
};

let item_struct_name = Ident::new(&format!("{}Item", struct_name), Span::call_site());
let item_struct_name = Ident::new(&format!("{struct_name}Item"), Span::call_site());
let read_only_item_struct_name = if fetch_struct_attributes.is_mutable {
Ident::new(&format!("{}ReadOnlyItem", struct_name), Span::call_site())
Ident::new(&format!("{struct_name}ReadOnlyItem"), Span::call_site())
} else {
item_struct_name.clone()
};

let fetch_struct_name = Ident::new(&format!("{}Fetch", struct_name), Span::call_site());
let fetch_struct_name = Ident::new(&format!("{struct_name}Fetch"), Span::call_site());
let read_only_fetch_struct_name = if fetch_struct_attributes.is_mutable {
Ident::new(&format!("{}ReadOnlyFetch", struct_name), Span::call_site())
Ident::new(&format!("{struct_name}ReadOnlyFetch"), Span::call_site())
} else {
fetch_struct_name.clone()
};

let state_struct_name = Ident::new(&format!("{}State", struct_name), Span::call_site());
let state_struct_name = Ident::new(&format!("{struct_name}State"), Span::call_site());

let fields = match &ast.data {
Data::Struct(DataStruct {
Expand Down Expand Up @@ -438,9 +438,7 @@ fn read_world_query_field_info(field: &Field) -> WorldQueryFieldInfo {
}
Ok(())
})
.unwrap_or_else(|_| {
panic!("Invalid `{}` attribute format", WORLD_QUERY_ATTRIBUTE_NAME)
});
.unwrap_or_else(|_| panic!("Invalid `{WORLD_QUERY_ATTRIBUTE_NAME}` attribute format"));

is_ignored
});
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ fn get_idents(fmt_string: fn(usize) -> String, count: usize) -> Vec<Ident> {
pub fn impl_param_set(_input: TokenStream) -> TokenStream {
let mut tokens = TokenStream::new();
let max_params = 8;
let params = get_idents(|i| format!("P{}", i), max_params);
let params_fetch = get_idents(|i| format!("PF{}", i), max_params);
let metas = get_idents(|i| format!("m{}", i), max_params);
let params = get_idents(|i| format!("P{i}"), max_params);
let params_fetch = get_idents(|i| format!("PF{i}"), max_params);
let metas = get_idents(|i| format!("m{i}"), max_params);
let mut param_fn_muts = Vec::new();
for (i, param) in params.iter().enumerate() {
let fn_name = Ident::new(&format!("p{}", i), Span::call_site());
let fn_name = Ident::new(&format!("p{i}"), Span::call_site());
let index = Index::from(i);
param_fn_muts.push(quote! {
pub fn #fn_name<'a>(&'a mut self) -> <#param::Fetch as SystemParamFetch<'a, 'a>>::Item {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,9 @@ impl std::error::Error for QuerySingleError {}
impl std::fmt::Display for QuerySingleError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
QuerySingleError::NoEntities(query) => write!(f, "No entities fit the query {}", query),
QuerySingleError::NoEntities(query) => write!(f, "No entities fit the query {query}"),
QuerySingleError::MultipleEntities(query) => {
write!(f, "Multiple entities fit the query {}!", query)
write!(f, "Multiple entities fit the query {query}!")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/ambiguity_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl SystemStage {
last_segment_kind = Some(segment);
}

writeln!(string, " -- {:?} and {:?}", system_a, system_b).unwrap();
writeln!(string, " -- {system_a:?} and {system_b:?}").unwrap();

if !conflicts.is_empty() {
writeln!(string, " conflicts: {conflicts:?}").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/executor_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ mod tests {
StartedSystems(1),
]
);
stage.set_executor(Box::new(SingleThreadedExecutor::default()));
stage.set_executor(Box::<SingleThreadedExecutor>::default());
stage.run(&mut world);
}
}
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Schedule {
let label = label.as_label();
self.stage_order.push(label);
let prev = self.stages.insert(label, Box::new(stage));
assert!(prev.is_none(), "Stage already exists: {:?}.", label);
assert!(prev.is_none(), "Stage already exists: {label:?}.");
self
}

Expand Down Expand Up @@ -152,11 +152,11 @@ impl Schedule {
.enumerate()
.find(|(_i, stage_label)| **stage_label == target)
.map(|(i, _)| i)
.unwrap_or_else(|| panic!("Target stage does not exist: {:?}.", target));
.unwrap_or_else(|| panic!("Target stage does not exist: {target:?}."));

self.stage_order.insert(target_index + 1, label);
let prev = self.stages.insert(label, Box::new(stage));
assert!(prev.is_none(), "Stage already exists: {:?}.", label);
assert!(prev.is_none(), "Stage already exists: {label:?}.");
self
}

Expand Down Expand Up @@ -192,11 +192,11 @@ impl Schedule {
.enumerate()
.find(|(_i, stage_label)| **stage_label == target)
.map(|(i, _)| i)
.unwrap_or_else(|| panic!("Target stage does not exist: {:?}.", target));
.unwrap_or_else(|| panic!("Target stage does not exist: {target:?}."));

self.stage_order.insert(target_index, label);
let prev = self.stages.insert(label, Box::new(stage));
assert!(prev.is_none(), "Stage already exists: {:?}.", label);
assert!(prev.is_none(), "Stage already exists: {label:?}.");
self
}

Expand Down

0 comments on commit e71c4d2

Please sign in to comment.